View previous topic :: View next topic |
Author |
Message |
sixtysixtysix Tux's lil' helper
Joined: 28 Jun 2021 Posts: 86
|
Posted: Thu Jan 27, 2022 6:54 pm Post subject: genkernel, new kernel, efi entries... can I use a symlink? |
|
|
I hope I manage to explain the following clearly. What I'm trying to do is implement something I see by default in my Arch installation and which I have found massively useful.
I use GPT partitioning for all disks - NO need at all to go anywhere near Windows/MBR or, in fact, grub.
I am set up to boot via efi stub. I presently use efibootmgr to write/replace the entries in NVRAM. Since there's no option to edit an entry (that I'm aware of) it requires me to delete and re-write that entry every time the kernel version changes, or I've done something else to my boot parameters (e.g. load a module). Since I use PARTUUID entries with hibernate that's quite a lot of typing.
It's clunky to keep deleting/re-writing those entries, and even the tiniest syntax error will cause a panic or boot failure.
The way that Arch handles kernel upgrades is that it has a hook which automatically regenerates an Initramfs while the entry in the bootloader points at a file which ... is symlinked? (is that right?) to the new kernel. Thus whichever specific version number is built, the bootloader entry itself never needs editing.
Is it possible to do what I'd like i.e. create an entry in efi that points to a label such as "Gentoo" and which will never need replacing despite the actual version number of the kernel? I realise that Arch is systemd, and I'm using openrc.
Subsidiary question: would it make any difference if I overcame my dislike of MBR and actually installed grub on the disk? Since grub has a simple way to update itself, anything that saves the faff of keep messing about inside efibootmgr is a good idea. |
|
Back to top |
|
|
grknight Retired Dev
Joined: 20 Feb 2015 Posts: 2005
|
Posted: Thu Jan 27, 2022 7:15 pm Post subject: |
|
|
Quote: | Subsidiary question: would it make any difference if I overcame my dislike of MBR and actually installed grub on the disk? Since grub has a simple way to update itself, anything that saves the faff of keep messing about inside efibootmgr is a good idea. |
Since you do not appear to be adverse to grub, why not just use it with UEFI?
It really is quite simple as grub-install will create its EFI executable and register it via efibootmgr.
Then you have the flexibility of editing /etc/default/grub for the common command-line which grub-mkconfig will read and produce a list of kernels it finds automatically. |
|
Back to top |
|
|
pietinger Moderator
Joined: 17 Oct 2006 Posts: 5377 Location: Bavaria
|
Posted: Thu Jan 27, 2022 7:19 pm Post subject: |
|
|
I have all my systems installed with grub2 as described in our AMD64 handbook. After the main installation I made the kernel bootable from UEFI (=efistub-kernel) and copied it WITHOUT version information into \EFI\...[mysys]...\bzImage.efi
so I have two boot-entries in my UEFI-BIOS. One pointing to grub2 and the other pointing to my efistub-kernel.
After (successfull) booting my new kernel from UEFI I do simply:
Code: | # mount /boot
# cd /usr/src/linux
# make install
# grub-mkconfig -o /boot/grub/grub.cfg
# umount /boot |
(Because grub2 boots an efistub-kernel also like every "normal" kernel)
When getting a new kernel (new version/new config), I copy it (over) to \EFI\...[mysys]...\bzImage.efi
If the new kernel doesnt boot, I select in my UEFI-BIOS grub2 ("gentoo) and boot the last kernel ... |
|
Back to top |
|
|
pietinger Moderator
Joined: 17 Oct 2006 Posts: 5377 Location: Bavaria
|
Posted: Thu Jan 27, 2022 7:29 pm Post subject: |
|
|
sixtysixtysix wrote: | [...] to my boot parameters (e.g. load a module). Since I use PARTUUID entries with hibernate that's quite a lot of typing.[...] |
P.S.: Maybe you are interested to put all your command line parameters directly into your kernel (I do this):
Code: | Processor type and features --->
[*] Built-in kernel command line
(root=PARTUUID=99beb5b2-b529-40fb-b0bc-3250a5237491 ro loglevel=8 lsm.debug ima_appraise=enforce) Built-in kernel command string
[*] Built-in command line overrides boot loader arguments |
(The last line is important to be independent from grub2 ... ) |
|
Back to top |
|
|
Leonardo.b Guru
Joined: 10 Oct 2020 Posts: 308
|
Posted: Thu Jan 27, 2022 7:30 pm Post subject: |
|
|
Write a script to handle your kernel upgrades.
It is more convenient. |
|
Back to top |
|
|
sixtysixtysix Tux's lil' helper
Joined: 28 Jun 2021 Posts: 86
|
Posted: Thu Jan 27, 2022 7:35 pm Post subject: |
|
|
woah! Thanks... you made me look - I had no idea grub2 in Gentoo could be installed directly onto GPT! That'll teach me to keep referring to the Arch wiki at times!
So, a couple of other questions then, because for sure I'm going down this road. Anything that stops me ever having to manually edit those efi entries is fine by me
the process described by pietinger:
I sort of follow but not entirely clear. why do you duplicate? Or is that simply the default outcome of the method you use?
I followed the Gentoo wiki and have a /boot/efi/boot/bootx64.efi which is a copy of "vmlinuz-<version>.img". Is there any reason to use bzImage instead? Very happy for you to point me at some docs or a wiki page.
You allude to what I'm trying to achieve i.e. booting a particular file by name, and it's the name that I want fixed. So copying something into the new file achieves this, but then if I go with grub, then surely by updating grub I'm letting it do the exact same thing really?
Guess I'll find out more once I install and configure grub, but tbh I'm very happy it will just run without me adding any disk partitions.
One other question: the wiki page says to add "pc" USE flag for installation on bios. I don't need this, yet the USE flags suggested by emerge include "pc". I can disable it, but what's the outcome? Should I install the whole shebang for use with EFI? |
|
Back to top |
|
|
pietinger Moderator
Joined: 17 Oct 2006 Posts: 5377 Location: Bavaria
|
Posted: Thu Jan 27, 2022 8:43 pm Post subject: |
|
|
First of all you have to know about UEFI-BIOS:
UEFI searches in all partitions marked as ESP (efi system partition) for bootable binaries. There is ONE name - "bootx64.efi" - which is a default and will be found ALWAYS (when it is in \EFI\boot) - even without a boot-entry. This is the reason why on a USB-stick (where there is no boot-entry) the name must be "bootx64.efi". If you want to boot another entry you HAVE to make an entry (with "efibootmgr") in UEFI-table.
Second: I am using grub2 not as primary backup (it is only my second backup) because I have another bootable (efi-stub-) kernel. This is because I am using IMA. Look to my table:
Code: | # efibootmgr -v
BootCurrent: 0001
Timeout: 1 seconds
BootOrder: 0001,0002,0000
Boot0000* gentoo HD(2,GPT,e6cccc9a-40e0-4b59-b6d2-082596500077,0x1800,0x1fe800)/File(\EFI\gentoo\grubx64.efi)
Boot0001* DIRECT HD(2,GPT,e6cccc9a-40e0-4b59-b6d2-082596500077,0x1800,0x1fe800)/File(\EFI\Boot\bzImage.efi)
Boot0002* UNLOCKED HD(2,GPT,e6cccc9a-40e0-4b59-b6d2-082596500077,0x1800,0x1fe800)/File(\EFI\unlocked\bzImage.efi) |
Third: The NAMES are only names. You can choose what you want. It is only important to set the correct name when doing your "efibootmgr -c ..."
(The first entry was installed automatically when installing grub2; its a default entry from grub)
sixtysixtysix wrote: | I sort of follow but not entirely clear. why do you duplicate? Or is that simply the default outcome of the method you use? |
To be honest: I dont install every kernel for using by grub. My working kernel is always the newest LTS (5.15.17). The other unlocked is 5.15.16 and I havent update the kernel in grub (is only 5.10.xx).
sixtysixtysix wrote: | I followed the Gentoo wiki and have a /boot/efi/boot/bootx64.efi which is a copy of "vmlinuz-<version>.img". Is there any reason to use bzImage instead? Very happy for you to point me at some docs or a wiki page. |
You can use only ONE bootx64.efi in your ESP. It is more cleaner if you choose an extra directory for every kernel. vmlinuz and bzImage are traditional names. If you want you are able to put four kernels in one directory and name them "kernel1.efi", "kernel2,efi" ... but I dont recommend this.
sixtysixtysix wrote: | One other question: the wiki page says to add "pc" USE flag for installation on bios. I don't need this, yet the USE flags suggested by emerge include "pc". I can disable it, but what's the outcome? Should I install the whole shebang for use with EFI? |
"pc" is not a Use-flag. It is ONE of some settings in the variable: "GRUB_PLATFORMS=" and you SHOULD NOT use it for an UEFI-system. Put this BEFORE installing grub2 into your make.conf:
Code: | GRUB_PLATFORMS="efi-64" |
Last word to UEFI:
"efibootmgr" "talks" with UEFI via "efivarfs" !
To have "efivarfs" you need
1. a kernel with this settings enabled. See more here: https://wiki.gentoo.org/wiki/Efibootmgr Of course our minimal installation CD has it;
2. correct settings in your BIOS: CSM boot must be DISABLED (some mainboards call it "legacy boot"; then this must be DISABLED)
3. GPT instead of MBR
You can check if you it:
Code: | ! check if /sys/firmware/efi exists -> yes -> ok, it was really an uefi boot
# ls /sys/firmware
- or -
# mount
->
[...]
efivarfs on /sys/firmware/efi/efivars type efivarfs (rw,nosuid,nodev,noexec,relatime)
[...] |
So, why we have a strange explanation in our handbook ? Because it could be some users boot (with another CD) into a system where no efivarfs is available. This would cause grub2 installation to break when trying to "talk" with UEFI (internal via "efibootmgr). For these rare cases there is rescue plan: We dont copy grub2 as grubx64.efi into \EFI\gentoo. Instead we copy it as "bootx64.efi" into \EFI\boot
See also:
https://wiki.gentoo.org/wiki/EFI_stub
https://wiki.gentoo.org/wiki/EFI_System_Partition |
|
Back to top |
|
|
sixtysixtysix Tux's lil' helper
Joined: 28 Jun 2021 Posts: 86
|
Posted: Thu Jan 27, 2022 11:19 pm Post subject: |
|
|
thanks again, pietinger for taking the time to explain carefully.
All sorted now, after a confusing couple of hours with Grub2. I'll explain because a) grateful to you for taking the time, thus not ignoring b) in case it's at all helpful elsewhere.
What it took me quite a while to figure out, after many unsuccessful attempts at booting (!!) was
that the Gentoo wiki on grub installation and config differs from the AMD64 wiki in a vital respect: they use slightly different paths for the EFI! To explain - I have simple /dev/sda1, /dev/sda2, dev/sda3 all properly formatted. /dev/sda1 is a VFAT partition, mounted (in fstab) at /boot
having previously followed the wiki for efibootmgr, I have
/boot/efi/boot/
in which is
bootx64.efi
Trouble was, that by following the paths listed in the grub wiki, after I ran Code: | #grub-install --efi-directory=/boot/efi |
followed by the expected Code: | #grub-mkconfig -o /boot/grub/grub.cfg |
I then had dirs
/boot/efi/EFI/grub/gentoo/
and so the path that it wrote into the NVRAM looked correct (to grub) but of course was one level of directory out!
This took me far too long to realise. However, in conclusion
I've now unmerged grub completely. Why? Because although it's easier to run the grub update than it is to get into efibootmgr and twiddle, all it's actually done for me is to place a further layer on top of the boot process for which I had no need. I have different kernels (and different distros) on separate physical disks, so there's no need to keep them separated here, as they're not aware of each other. Not only this, but for some unfathomable reason, after it having written these incorrect boot entries several times, I found that when going back to the manual edit via efibootmgr, those entries had become non-persistent. Every time I rebooted they were gone, and I was left without a booting system. Weird. It took me to use the rescue disk and then chroot back in and then sort it all out from there. NO idea at all why that happened but clearly there's still some difference between the way grub and efibootmgr talk to the NVRAM. The results look similar but function differently. I completely accept this is most likely simply my hardware and not a feature of gentoo.
You have helped me greatly though, because yes I missed the blindingly obvious solution I came here for... which is to call my initram and vmlinuz any old name, write THOSE values into NVRAM, and then every time I update, I just rename the compiled initramfs and vmlinuz to the existing names. Doh! Can't believe I didn't think of this before.
Anyway, thanks again for everyone's help |
|
Back to top |
|
|
pietinger Moderator
Joined: 17 Oct 2006 Posts: 5377 Location: Bavaria
|
Posted: Fri Jan 28, 2022 12:10 am Post subject: |
|
|
sixtysixtysix wrote: | thanks again, pietinger for taking the time to explain carefully. |
My pleasure - you are welcome.
sixtysixtysix wrote: | [...] that the Gentoo wiki on grub installation and config differs from the AMD64 wiki in a vital respect: they use slightly different paths for the EFI! |
This is unfortunately true. Reason is history and defaults in other distros. There exists three options to go for. Our developers decided one of them in our AMD64 handbook (I like this option). I have explained it here: https://forums.gentoo.org/viewtopic-p-8648587.html#8648587
sixtysixtysix wrote: | Trouble was, that by following the paths listed in the grub wiki, after I ran Code: | #grub-install --efi-directory=/boot/efi |
followed by the expected Code: | #grub-mkconfig -o /boot/grub/grub.cfg |
I then had dirs
/boot/efi/EFI/grub/gentoo/
and so the path that it wrote into the NVRAM looked correct (to grub) but of course was one level of directory out! |
Yes. For your configuration a simple
Code: | #grub-install --efi-directory=/boot/ |
would have done it correct (it is the default also).
sixtysixtysix wrote: | Not only this, but for some unfathomable reason, after it having written these incorrect boot entries several times, I found that when going back to the manual edit via efibootmgr, those entries had become non-persistent. Every time I rebooted they were gone,[...] |
I think this is a usually behaviour of many (all?) UEFI-BIOS. They delete an entry where no binary exists. My Gigabyte mainboard is doing the same. |
|
Back to top |
|
|
Goverp Advocate
Joined: 07 Mar 2007 Posts: 2202
|
Posted: Fri Jan 28, 2022 9:21 am Post subject: |
|
|
As what's now an aside, the reason you can't use a symlink is that the EFI partition is FAT32, and that doesn't support symlinks.
If you were to revert to using the kernel EFI stub loader, you'd probably want to install your new kernels as "vmlinuz" rather than "vmlinuz-5.16.97" or whatever, which requires changes to whatever procedure you use to install kernels. But then you get the problem of recovery when it breaks. At a minimum, you'd want to copy vmlinuz as vmlinuz.old, and perhaps have an EFI entry to boot that. Ideally, you'd install the new kernel as vmlinuz.new first, test it, and once successful, copy vmlinuz->vmlinuz.old and copy vmlinuz.new as vmlinuz. (Use copy rather than rename so as not to leave missing files to stop the EFI boot process deleting the boot command entries.) _________________ Greybeard |
|
Back to top |
|
|
sixtysixtysix Tux's lil' helper
Joined: 28 Jun 2021 Posts: 86
|
Posted: Fri Jan 28, 2022 1:03 pm Post subject: |
|
|
Thanks, Goverp. Makes perfect sense now - I'd been wondering.
Recovery when it breaks? Yes, I can see that. To date all I've been doing (since I have two disks with working OSes) is that if my latest Gentoo kernel fails, I simply boot up in the other OS and either rewrite the NVRAM entry (this is the most common cause of failure) or failing that, boot with the live install USB.
I can see that, with Gentoo long since the daily driver, it's probably wise to have something a bit quicker/more convenient for correcting failures.
I suppose this simply leads me back to an aspect of the original post... I installed grub. Sure, it works. But unless I have an older kernel installed AND any real need to then boot to that one instead, it just felt like unnecessary overhead. The one important thing it did do was make a better job of writing the entry into the efi partition.
I see that it's possible to create a boot text menu (if I'm understanding Syslinux wiki correctly) so perhaps my answer would be to create a config file for Syslinux, register that as the loader, and then select older/previous kernel from there.
It's completely true that in all my previous uses of Linux (Manjaro, Fedora, Ubuntu) I allowed the full distro to set me up, which tended to always use Grub and a selection menu. But since I switched to running only Linux, and furthermore that I only ever need(ed) one single, solid OS, I don't really see the point in fancy boot loaders. If I think of all the time I wasted over the years by obsessing over the eye candy.... installing Plymouth in Arch even - JUST so that I could stare at something pretty for a few seconds. Even mroe so now that I try hard as I can to make the machine boot as fast as possible... WHY would I want to stop and stare at a boot screen? Each to their own etc.
I now see that by auto logging direct into xfce4 session via X, my longest delay is waiting for the blank screen to acquire wallpaper and icons. Now... if only I knew how to speed that up!!? |
|
Back to top |
|
|
Hu Administrator
Joined: 06 Mar 2007 Posts: 23093
|
Posted: Fri Jan 28, 2022 4:13 pm Post subject: |
|
|
As an incidental recovery tip, some UEFI firmware offers a modestly capable shell, along the lines of the old MS-DOS COMMAND.COM shell. In such firmware, you can drop to that shell, then run a UEFI application of your choice (including a Linux kernel with EFI stub) directly from the shell. This may be more convenient for a one-off repair when you built a bad kernel or bad default EFI entry, since it can let you boot the good kernel directly from the firmware. I wouldn't recommend this as a standard bootloader, but it can get you back into your normal system to let you do the repairs using Linux tools, and might be more convenient than needing an alternate working OS. |
|
Back to top |
|
|
sixtysixtysix Tux's lil' helper
Joined: 28 Jun 2021 Posts: 86
|
Posted: Sun Feb 06, 2022 10:51 pm Post subject: |
|
|
Thanks, Hu
Very good idea! In fact I'm still learning... and now that I have a stable installation, and which I understand reasonably well, I can get to doing some nice extras like scripts and helpers. In fact the .iso I use for Arch installation has a nice little UEFI shell that makes editing the boot entries supremely easy. Even better, it can be installed in an efi partition somewhere on the boot mount... So I'm going to look into doing that for exactly the reasons you mention i.e. make it easy to get in and edit an entry without the hassle of rebooting and remounting disks just to get at an entry.
I'm also about to look at writing/copying parts of the install scripts and place them on the live sticks as well, to save all the typing |
|
Back to top |
|
|
dcrook Tux's lil' helper
Joined: 22 Jul 2004 Posts: 83
|
Posted: Mon Feb 07, 2022 2:04 am Post subject: |
|
|
You might want to look at using rEFIned for managing your boot process since it can just can for kernels installed in /boot and automatically boot the newest one.
https://wiki.gentoo.org/wiki/Refind |
|
Back to top |
|
|
sixtysixtysix Tux's lil' helper
Joined: 28 Jun 2021 Posts: 86
|
Posted: Mon Feb 07, 2022 8:14 am Post subject: |
|
|
thanks for the tip dcrook, but I want as little as possible in between pushing the power button and having a working desktop.
I ended up using Grub for Gentoo because the alternative was just not worth the pain. Even now I'd like things to take less time hahaha. Oh dear, I should probably get out more! |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|