Separating /boot into non-BTRFS parition for GRUB

Hello!

I have been using Leap 15.1 with KDE for a while now and still have one issue I would like to fix. I dual boot with Windows, but I have found (twice, unfortunately) that I have to set GRUB to select Windows by default or else when Windows reboots for updates automatically if it goes into Leap then Windows is quite unhappy (sometimes dead).

I want to use the GRUB last saved option(GRUB_DEFAULT=saved and GRUB_SAVEDEFAULT=true), but it doesn’t work since my root filesystem is BTRFS (see the note here and the explanation here). So, it seems like I should separate my /boot into a separate partition.

So first, are there any drawbacks to this?

  • Will this break any of the OpenSUSE-managed Grub parts (like configuring in YAST), or will it work fine so long as I mount it as /boot in fstab?
  • Over time could this method accidentally fail after running a system/kernel/GRUB update?
  • Is this not a recommended workaround due to some reason I do not know?

So then if it is the right way, how do I go about doing it? Here is my drive in Partitioner, GParted, and fstab:
https://i.imgur.com/9pAjJok.png
https://i.imgur.com/8mCOTV3.png

/dev/system/swap                           swap                    swap   defaults                      0  0
/dev/system/root                           /                       btrfs  defaults                      0  0
/dev/system/root                           /.snapshots             btrfs  subvol=/@/.snapshots          0  0
/dev/system/root                           /var                    btrfs  subvol=/@/var                 0  0
/dev/system/root                           /var/cache              btrfs  subvol=/@/var/cache           0  0
/dev/system/root                           /usr/local              btrfs  subvol=/@/usr/local           0  0
/dev/system/root                           /tmp                    btrfs  subvol=/@/tmp                 0  0
/dev/system/root                           /srv                    btrfs  subvol=/@/srv                 0  0
/dev/system/root                           /root                   btrfs  subvol=/@/root                0  0
/dev/system/root                           /opt                    btrfs  subvol=/@/opt                 0  0
/dev/system/home                           /home                   xfs    defaults                      0  0
/dev/system/root                           /boot/grub2/x86_64-efi  btrfs  subvol=/@/boot/grub2/x86_64-efi  0  0
/dev/system/root                           /boot/grub2/i386-pc     btrfs  subvol=/@/boot/grub2/i386-pc  0  0
UUID=<REDACTED>                            /boot/efi               vfat   defaults                      0  0
UUID=<REDACTED>                            /mnt/windows            ntfs   defaults                      0  0

Should I:

  • Create the new partition in my LVM group or outside of it? I suspect it can go inside of it since that is where /boot is currently.
  • I think it should be ext2?
  • If it is outside, should it have the boot flag? Does it need any other flags?
  • Should it be 500 MB, or larger?
  • Speed-wise it shouldn’t matter where it is on the disk since this is an SSD, but does placement matter for any other reason? I boot with EFI, so I figure it doesn’t matter if this is the first partition on the disk.
  • Should I copy everything in /boot to the new partition and then add it to fstab?
  • Do I need to give it any special flags in fstab?
  • How do I let GRUB or the EFI bootloader know of this change? Or does it happen automatically if I run grub2-mkconfig or run the YAST configurator?

Sorry for the massive amount of questions! I think I have wrapped my head around this, but I want to make sure I do it right (and not end up with a failed system lol).
Thanks!

Hi
Can you post the output from;


efibootmgr -v

I would suspect based on your hardware and UEFI BIOS implementation that Windows would default to using the HDD implementation rather than the efi partition which your currently have on sda4 (I think even winX looks at sda1 first…). The above should provide more info :wink: You should also be able to get to a boot menu on the hardware to select the efi loader to boot?

What you need to enure in grub is that it checks for a foreign OS (os-prober) so it sets the order and adds it all back into grub.

Oh gosh this is long. So I should note there is a second drive in my computer that I do not boot off of at all and never shows up in boot menus, but it may be in this list:

BootCurrent: 0008
Timeout: 0 seconds
BootOrder: 0008,0009,0020,0028,0027,0024,002A,0023,0021,0022,0029,0025,0006
Boot0000  Startup Interrupt Menu        FvFile(f46ee6f4-4785-43a3-923d-7f786c3c8479)
Boot0001  Rescue and Recovery   FvFile(665d3f60-ad3e-4cad-8e26-db46eee9f1b5)
Boot0002  MEBx Hot Key  FvFile(ac6fd56a-3d41-4efd-a1b9-870293811a28)
Boot0003* IDER BOOT CDROM       PciRoot(0x0)/Pci(0x16,0x2)/Ata(0,1,0)
Boot0004* IDER BOOT Floppy      PciRoot(0x0)/Pci(0x16,0x2)/Ata(0,0,0)
Boot0005* ATA HDD       VenMsg(bc7838d2-0f82-4d60-8316-c068ee79d25b,91af625956449f41a7b91f4f892ab0f6)
Boot0006* PCI LAN       VenMsg(bc7838d2-0f82-4d60-8316-c068ee79d25b,78a84aaf2b2afc4ea79cf5cc8f3d3803)
Boot0007* opensuse-secureboot   HD(5,GPT,f210526d-9ff9-4315-8774-bb83c79aff0e,0x4c58b000,0xfa000)/File(\EFI\opensuse\shim.efi)
Boot0008* opensuse-secureboot   HD(5,GPT,f210526d-9ff9-4315-8774-bb83c79aff0e,0x4c58b000,0xfa000)/File(\EFI\opensuse\shim.efi)
Boot0009* Windows Boot Manager  HD(2,GPT,c12ee7ee-c0bf-4820-adaa-35185ed93060,0x1f4800,0x82000)/File(\EFI\Microsoft\Boot\bootmgfw.efi)WINDOWS.........x...B.C.D.O.B.J.E.C.T.=.{.9.d.e.a.8.6.2.c.-.5.c.d.d.-.4.e.7.0.-.a.c.c.1.-.f.3.2.b.3.4.4.d.4.7.9.5.}....................
Boot0016  Setup FvFile(721c8b66-426c-4e86-8e99-3457c46ab0b9)
Boot0017  Boot Menu     FvFile(126a762d-5758-4fca-8531-201a7f57f850)
Boot0018  Diagnostic Splash Screen      FvFile(a7d8d9a6-6ab0-4aeb-ad9d-163e59a7a380)
Boot0019  Lenovo Diagnostics    FvFile(3f7e615b-0d45-4f80-88dc-26b234958560)
Boot0020  PCI LAN       VenMsg(bc7838d2-0f82-4d60-8316-c068ee79d25b,78a84aaf2b2afc4ea79cf5cc8f3d3803)
Boot0021* Other HDD     VenMsg(bc7838d2-0f82-4d60-8316-c068ee79d25b,91af625956449f41a7b91f4f892ab0f606)
Boot0022* Other CD      VenMsg(bc7838d2-0f82-4d60-8316-c068ee79d25b,aea2090adfde214e8b3a5e471856a35406)
Boot0023* ATAPI CD      VenMsg(bc7838d2-0f82-4d60-8316-c068ee79d25b,aea2090adfde214e8b3a5e471856a354)
Boot0024* USB CD        VenMsg(bc7838d2-0f82-4d60-8316-c068ee79d25b,86701296aa5a7848b66cd49dd3ba6a55)
Boot0025* USB FDD       VenMsg(bc7838d2-0f82-4d60-8316-c068ee79d25b,6ff015a28830b543a8b8641009461e49)
Boot0027* ATA HDD0      VenMsg(bc7838d2-0f82-4d60-8316-c068ee79d25b,91af625956449f41a7b91f4f892ab0f600)
Boot0028* ATA HDD1:     VenMsg(bc7838d2-0f82-4d60-8316-c068ee79d25b,91af625956449f41a7b91f4f892ab0f605)
Boot0029* ATA HDD2:     VenMsg(bc7838d2-0f82-4d60-8316-c068ee79d25b,91af625956449f41a7b91f4f892ab0f601)
Boot002A* USB HDD       VenMsg(bc7838d2-0f82-4d60-8316-c068ee79d25b,33e821aaaf33bc4789bd419f88c50803)

OK, so here is how my computer currently boots:

  1. BIOS loads grub via EFI (appears in BIOS as opensuse-secureboot)
  2. GRUB lets me choose Leap or Windows. I have set Windows as the default to avoid Windows killing itself

No matter where or how I reboot, my BIOS loads GRUB via EFI/opensuse-secureboot. Windows always goes through grub (this is how I want it, or at least I think I do and am happy with it other than that it doesn’t remember the last option).

I suppose I can hold F12 at boot to get to the BIOS’s EFI selector, but it won’t remember the last option, which is sort of the problem. I would have to go into the BIOS settings and re-order the EFI options every time, which is not very fluid so I would like to avoid that if I can.

I think it is there already (by default I think?), but I will check! So far every time I boot (even after re-applying/configuring GRUB) it has been consistent. Setting Windows as the current default has worked fine, I just want it to remember the last option now instead of always defaulting to Windows.

Sorry if I misunderstood what you are recommending and thank you for your response!

Yes, that happens here.

My solution: I set Windows to be first in boot order. In my case, that’s the command

efibootmgr -o 0001,0000

I’ll note that my desktop is a Dell computer. I also have a Lenovo, and the only way to set the boot order there, is to do it in the BIOS settings menu for the computer.

When booting from Windows to openSUSE on my Dell, I use “SHIFT restart” in Windows. Then Windows gives me several choices, one of which is “Use a device”. I select that, and “opensuse-secureboot” is an available boot option.

When booting from openSUSE to openSUSE on my Dell, I use:

efibootmgr -n 0000

so that the next boot will use Boot0000 (in my case, that’s opensuse-secureboot). If I forget to run that “efibootmgr” command before restart, I have a second chance. I can hit F12 while booting to get a BIOS boot menu.

I don’t have Windows on my Lenovo, so I have not tried all of those. I do know that hitting F12 during booting does give a BIOS boot menu. My guess would be that using “efinootmgr -n” to select the next boot would also work. But I don’t know that for sure.

Hmm, let me try that. Yes, that works on my Lenovo ThinkServer. I don’t know if it will work on your system, but it is worth a try.

Your ideas about “/boot” won’t actually help you. If I configure grub2 in openSUSE to boot Windows by default, then Windows still does not like that. It wants Windows to be selected by the BIOS for booting. And if I use F12 while rebooting, and select Windows (after updating and rebooting), then Windows doesn’t even like that. They only thing that seems to work is to have the BIOS select Windows as the default boot choice.

I should add that my experience is with Windows 8.1. I’m guessing that it is the same with Windows 10, but I have no experience with that.

Ohhhhh I think I understand what y’all are saying now! Wow I knew the OS could do this but never realized I could take advantage of it. OK, so here is my idea (idk if this works):

  1. Set Windows as the default EFI option in BIOS. If I am in Windows, then it will restart into Windows.
  2. In OpenSUSE, add a systemd oneshot to set the next boot to be OpenSUSE. This way if OpenSUSE restarts, then it will go back into OpenSUSE.
  3. To switch between the OSes, I can use either F12 at boot or hold SHIFT when restarting Windows.

Question: How will the BIOS handle shutdowns? If I set the EFI next-boot and then shutdown the computer instead of restarting, what will it do?

I have a Lenovo T440p. I will do some experimenting!

Interesting. This has not been my experience (Windows 10 Pro). Windows has been fine for me being booted via GRUB. I didn’t touch its entry config so it is doing it however os-prober decided to.

I’m pretty sure that on my system, it will honor the “next-boot” setting, even if there was a cold shutdown in between. But you will need to test that on your system.

Interesting. This has not been my experience (Windows 10 Pro). Windows has been fine for me being booted via GRUB. I didn’t touch its entry config so it is doing it however os-prober decided to.

Perhaps I was a bit confusing there.

Yes, Windows is normally fine booting with the grub menu. The one exception is when rebooting to complete a Windows update. Sometime I do a Windows update, and reboot to complete the update. And then Windows uninstalls that update, and says that something went wrong. But if I set Windows to be the BIOS default for booting, that never happens.

I’m not sure, but I think this is when a Windows update is modifying the boot software in Windows. So it tries to test whether everything works, and if it finds a problem in uninstalls that update. And apparently it thinks something didn’t work if Windows isn’t the BIOS default.

OK, I did some testing and I think I have a solution (assuming there are no drawbacks):

  1. Set my BIOS to boot to Windows by default. To switch to OpenSUSE, I hold shift when restarting Windows and select it
  2. OpenSUSE runs efibootmgr -n 0008 at boot via systemd oneshot so that any further reboots stay in OpenSUSE by default. To switch to Windows, I run efibootmgr -N to cancel the BootNext flag.
  3. Some testing shows that my computer preserves the NextBoot flag when using F12 at boot, so I should avoid using that (restarting Windows without selecting OpenSUSE could go into OpenSUSE if the NextBoot flag is set). I am thinking about adding some sudo rules to allow my local user to run efibootmgr -n 0008 and efibootmgr -N or corresponding systemd oneshots so that I can have some shortcuts on my desktop to select what boots next.

I tried setting the boot order from OpenSUSE but that didn’t work (same result as you on your Lenovo). The F12 thing not resetting the NextBoot could be confusing if you didn’t know what was happening: You could set your NextBoot to OS1 from OS2, then enter BIOS setup at the next boot and set OS2 as the default and then save your changes and it will still go to OS1 (I tested this and that is my computer’s behavior)!

Wow this is much cleaner/safer to implement than trying to separate my /boot. I did not realize I could do this!

It seems to work! This is great.

Huh. Yeah I have never had that issue. Though I suppose with this new solution I will possibly avoid ever having it.

It seems that you have a good plan that will work for you.

OK, I just wanted to document what I did for anyone who finds this thread in the future. **This solution is very very over-the-top. **I was seeing how well and smoothly I could integrate it into the system.

For my computer, the problem is solved by always setting the EFI Next Boot to OpenSUSE whenever OpenSUSE boots.

I started by creating a script in /usr/sbin/efi-bootnext-opensuse:

#!/usr/bin/env bash

ENTRY_HEX="0008"
ENTY_NAME="opensuse-secureboot"

# First check that the entry exists and is enabled
# Note: the star means that the boot entry is enabled
opensuse_boot_entry=`sudo /usr/sbin/efibootmgr --verbose | /bin/grep "Boot$ENTRY_HEX\* $ENTRY_NAME" --count`

# Then check if it is the current NextBoot
opensuse_bootnext_entry=`/usr/sbin/efibootmgr --verbose | /bin/grep "BootNext: $ENTRY_HEX" --count`

if  "$1" != "set" ] &&  "$1" != "cancel" ]; then
  echo "Please specify 'set' or 'cancel' as a first argument." >&2
  exit 1
fi

if  "$opensuse_boot_entry" != "1" ]; then
  echo "Did not complete task! Check EFI entries are correct!" >&2
  exit 1
fi

if  "$1" == "set" ]; then
  echo "Setting OpenSUSE as the NextBoot (even if already set)"
  /usr/sbin/efibootmgr --bootnext 0008 --quiet
elif  "$opensuse_bootnext_entry" == "1" ]; then
  echo "Cancelling OpenSUSE as the NextBoot"
  /usr/sbin/efibootmgr --delete-bootnext --quiet
else
  echo "Did not remove OpenSUSE as NextBoot! OpenSUSE is not currently set as NextBoot! (either nothing is or something else is)" >&2
  exit 1
fi

The interface is simple:

# efi-bootnext-opensuse set
Setting OpenSUSE as the NextBoot (even if already set)
# efi-bootnext-opensuse cancel
Cancelling OpenSUSE as the NextBoot

Note that this script makes heavy use of the efibootmgr program and it may break if its command-line interface changes. This script checks that the EFI entry exists and is enabled as you expect it to be and that the Next Boot flag that you cancel was OpenSUSE. Basically, it reduces the chance of unintended user error.

I then worked this into a systemd service to automate it /usr/lib/systemd/system/efi-nextboot-opensuse.service:

[Unit]
Description=EFI NextBoot OpenSUSE
DefaultDependencies=no

[Service]
User=root
Group=root
Type=oneshot
ExecStart=/usr/sbin/efi-bootnext-opensuse set
RemainAfterExit=true
ExecStop=/usr/sbin/efi-bootnext-opensuse cancel
StandardOutput=journal
Restart=no

[Install]
WantedBy=multi-user.target

This works a bit differently than a normal service. The RemainAfterExit=true setting causes it to consider itself as on/started/active if ExecStart completes without error. It is off/inactive/exited when ExecStop completes without error. This means that it can be controlled by starting and stopping a systemd service. The DefaultDependencies=no setting causes it not to stop it when the system shuts down (that would defeat the purpose lol).

The only thing to be careful about is that it uses WantedBy=multi-user.target. This means that it will start the service once all of the other vital parts of the system are running. So if you boot into emergency mode or interrupt the boot process before you get to a login prompt, then this service will not run and you will need to run the command yourself or use F12 at next boot. I did not use an earlier runlevel setting because I did not want to accidentally risk stopping my computer from booting in the future if something changes or the script or service fails.

The next step is to add a sudo rule so that I can run it from UI elements without any password prompts. I am OK with this since you can just as easily hold F12 at boot or select a boot device without a password from the Windows side.

I used visudo to edit /etc/sudoers.d/20-efi-nextboot-opensuse:

%wheel   ALL=(root) NOPASSWD: /usr/bin/systemctl start efi-nextboot-opensuse.service
%wheel   ALL=(root) NOPASSWD: /usr/bin/systemctl stop efi-nextboot-opensuse.service
%wheel   ALL=(root) NOPASSWD: /usr/bin/systemctl restart efi-nextboot-opensuse.service

This allows any user in the wheel group (administrators) to run these exact commands with sudo without a password prompt.

Next I created two local application files so that it can be controlled from my application menu or desktop icons. /usr/share/applications/efi-nextboot-opensuse-set.desktop:

[Desktop Entry]
Categories=System;
Comment=Set the computer to boot into OpenSUSE at next boot
Encoding=UTF-8    
Exec=/usr/bin/sudo /usr/bin/systemctl start efi-nextboot-opensuse.service
Icon=yast-bootloader
MimeType=  
Name=EFI Next Boot Set OpenSUSE
Path=
StartupNotify=true
Terminal=true
TerminalOptions=
Type=Application
X-DBUS-ServiceName=
X-DBUS-StartupType=

/usr/share/applications/efi-nextboot-opensuse-cancel.desktop:

[Desktop Entry]
Categories=System;
Comment=Cancel the computer booting into OpenSUSE at next boot
Encoding=UTF-8
Exec=/usr/bin/sudo /usr/bin/systemctl stop efi-nextboot-opensuse.service
Icon=yast-bootloader
MimeType=
Name=EFI Next Boot Cancel OpenSUSE
Path=
StartupNotify=true
Terminal=true
TerminalOptions=
Type=Application
X-DBUS-ServiceName=
X-DBUS-StartupType=

These will open a terminal prompt for users not in the wheel group to enter their password (as per sudo rule above) and simply work for users that do not require the prompt for the commands. You could also probably use gksudo or kdesu and set Terminal=false.

Lastly, I added a button to my bottom panel in KDE. I used the Configurable Button widget and configured it like so:

On-Script: /usr/bin/sudo /usr/bin/systemctl start efi-nextboot-opensuse.service
Off-Script: /usr/bin/sudo /usr/bin/systemctl stop efi-nextboot-opensuse.service
Status Script: /usr/bin/systemctl is-active --quiet efi-nextboot-opensuse.service

If you do not allow your user to run the command without a password prompt, then you will need to use gksudo or kdesu here.
https://i.imgur.com/yvhnure.png

And that’s it. I am very happy with this and it will probably follow me to all of my dual-boots now (or until there is a better solution)!

Thanks for all the help!