View previous topic :: View next topic |
Author |
Message |
mael n00b
Joined: 28 Feb 2018 Posts: 37 Location: Germany
|
Posted: Mon Jan 14, 2019 9:59 am Post subject: grub latest kernel autoselection possible? [SOLVED] |
|
|
hi folks,
i think i have a relativly simple question, but with a solution not so easy (at least for myself) to discover...
my grub version is 2.02-r1 (currently marked as stable), my current kernel is gentoo-sources-4.19.15 (currently marked as testing),
when i upgrade a kernel via the usual method (make oldconfig, make -j32, make modules_install, make install) i must manually update my /boot/grub/grub.cfg every time and change the version number of the selected kernel at least one digit upwards, and thats annoying somehow considering that i already have to manually uninstall and delete old kernel sources in /usr/src/, delete their installed counterparts in /boot/ and delete old module dirs in /lib/modules/ AFTER a successful and stable uptime with the new kernel.
my example needed grub.cfg update every time i upgrade a kernel manually:
Code: |
echo 'Loading Kernel ...'
linux /boot/vmlinuz-4.19.14-gentoo root=/dev/sdb2 rootfstype=ext4 rw fbcon=scrollback:2048k video=1920x1080-32@60 snd-hda-intel.enable=0,0,1
|
to this new version...
Code: |
echo 'Loading Kernel ...'
linux /boot/vmlinuz-4.19.15-gentoo root=/dev/sdb2 rootfstype=ext4 rw fbcon=scrollback:2048k video=1920x1080-32@60 snd-hda-intel.enable=0,0,1
|
is there a stable way to tell grub via its grub.cfg file to use automaticly the latest (highest version number) kernel version installed in my /boot/ directory? something like ...
Code: |
echo 'Loading Kernel ...'
linux /boot/vmlinuz-{*}-gentoo root=/dev/sdb2 rootfstype=ext4 rw fbcon=scrollback:2048k video=1920x1080-32@60 snd-hda-intel.enable=0,0,1
|
... would be nice. i already tried several placeholders but they didnt work at all and i had to manually tell grub via its emergency console interface the right kernel to boot everytime when experimenting in that direction...
is there some simple but effictive magic possible?
i would also be thankfull for any other tips to improve my (silly but working) way for kernel upgrades...
gentoo linux, the favorite choice even for professionals _________________ Gigabyte X99-SLI
Intel Core i7-5960X 16 Threads @ 3 Ghz
64 GB DDR4 RAM @ 2,13 Ghz
AMD Radeon 290X 8 GB RAM
Creative Soundblaster Z
Areca ARC-1883ix-16
16 Samsung 860 EVO 250 GB SSDs @ 3,5 TB RAID 6
Hauppauge HVR-5525
Firmwares are up-to-date
Last edited by mael on Tue Jan 15, 2019 8:30 am; edited 1 time in total |
|
Back to top |
|
|
steve_v Guru
Joined: 20 Jun 2004 Posts: 416 Location: New Zealand
|
Posted: Mon Jan 14, 2019 12:23 pm Post subject: Re: grub latest kernel autoselection via grub.cfg possible? |
|
|
mael wrote: | when i upgrade a kernel via the usual method (make oldconfig, make -j32, make modules_install, make install) i must manually update my /boot/grub/grub.cfg every time and change the version number of the selected kernel | I don't know of a way to get grub to autoselect at boot-time, pretty sure it has to be in grub.cfg.
If calling grub-mkconfig is an option (I do), it will automatically set the latest kernel to the first boot option as well as making entries for any old kernels / other operating systems it finds.
Otherwise, sort -v does version numbers, and a little sed magic should get it into grub.cfg. The actual script is left as an exercise for the reader.
For the record, I use: Code: | alias eupdate-kernel='zcat /proc/config.gz >| /usr/src/linux/.config && cd /usr/src/linux && make oldconfig && genkernel --no-clean --menuconfig all && emerge "@module-rebuild" && eclean-kernel -dAn1 && grub-mkconfig >| /boot/grub/grub.cfg' | For kernel updates. Take with care, it should delete all but the most recent kernel and write a new grub.cfg with that, but no promises. _________________ Once is happenstance. Twice is coincidence. Three times is enemy action. Four times is Official GNOME Policy.
Last edited by steve_v on Mon Jan 14, 2019 12:40 pm; edited 3 times in total |
|
Back to top |
|
|
mael n00b
Joined: 28 Feb 2018 Posts: 37 Location: Germany
|
Posted: Mon Jan 14, 2019 12:29 pm Post subject: |
|
|
no, the grub-mkconfig tool is not an option because i use a minimalistic custom handwritten grub.cfg
neverless thank you for your help steve...
i still prefer if possible some kind of internal grub.config solution with some kind of a placeholder without some kind of script or external tool like sed _________________ Gigabyte X99-SLI
Intel Core i7-5960X 16 Threads @ 3 Ghz
64 GB DDR4 RAM @ 2,13 Ghz
AMD Radeon 290X 8 GB RAM
Creative Soundblaster Z
Areca ARC-1883ix-16
16 Samsung 860 EVO 250 GB SSDs @ 3,5 TB RAID 6
Hauppauge HVR-5525
Firmwares are up-to-date |
|
Back to top |
|
|
steve_v Guru
Joined: 20 Jun 2004 Posts: 416 Location: New Zealand
|
Posted: Mon Jan 14, 2019 12:37 pm Post subject: |
|
|
mael wrote: | i still prefer if possible some kind of internal grub.config solution with some kind of a placeholder without some kind of script or external tool like sed | Fair enough. I don't know of one unfortunately.
Mayhap someone here does, or if all else fails, you could try the grub mailing list. Good luck. _________________ Once is happenstance. Twice is coincidence. Three times is enemy action. Four times is Official GNOME Policy. |
|
Back to top |
|
|
mike155 Advocate
Joined: 17 Sep 2010 Posts: 4438 Location: Frankfurt, Germany
|
Posted: Mon Jan 14, 2019 4:48 pm Post subject: |
|
|
- Copy grub.cfg to grub.cfg.template
- In grub.cfg.template: replace version numbers with a string, for example VERSION
- write a bash script that
- reads the kernel version number from /usr/src/linux
- copies grub.cfg.template to grub.cfg and replaces all occurrences of VERSION with the Linux version number you just read. sed is the tool of choice
- run that bash script after you run 'make install'
- You could add more logic to your script: removal of outdated module directories, ...
|
|
Back to top |
|
|
tholin Apprentice
Joined: 04 Oct 2008 Posts: 207
|
Posted: Mon Jan 14, 2019 8:22 pm Post subject: |
|
|
If you run make install in the kernel source it should copy the new kernel to /boot and make a symlink to it called vmlinuz. You can use that symlink in grub.cfg. It will not find the newest kernel but the most recently installed kernel but that's probably good enough.
Here is my grub.cfg using that trick.
Code: | menuentry 'Gentoo Linux' {
search --no-floppy --fs-uuid --set=root 234208d0-8893-49d2-b69a-9ab72436e742
linux /vmlinuz intel_iommu=on kvm.ignore_msrs=1 vfio-pci.disable_idle_d3=1 vfio-pci.disable_vga=1 vfio-pci.ids=10de:ffffffff:ffffffff:ffffffff:00030000:ffff00ff,10de:ffffffff:ffffffff:ffffffff:00040300:ffffffff
initrd /early_ucode.cpio /initramfs.cpio.gz
}
|
|
|
Back to top |
|
|
Atha Apprentice
Joined: 22 Sep 2004 Posts: 243
|
Posted: Mon Jan 14, 2019 9:32 pm Post subject: |
|
|
Gentoo genkernel has --symlink, wich will create symlinks in /boot for the current and the previous kernel. Just make a static grub configuration file that will always be included when you run grub-mkconfig. If you make it run before the automatic detection, it will be on top.
Look in /etc/grub.d: you will see files like 10_linux and 30_os-prober. If you make a static entry as 05_linux-static, it will be before the automatic 10_linux. Mine looks something like this:
Code: | #!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.
menuentry 'Gentoo genkernel (current)' --hotkey=l --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-gentoo-genkernel-current' {
load_video
insmod gzio
insmod part_gpt
insmod ext2
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root 12345678-0123-4567-cdef-0123456789ab
else
search --no-floppy --fs-uuid --set=root 12345678-0123-4567-cdef-0123456789ab
fi
echo 'Linux gentoo-current wird geladen …'
linux /kernel root=UUID=01234567-89ab-cdef-0123-456789abcdef ro init=/lib/systemd/systemd mem_encrypt=off spec_store_bypass_disable=on iommu=pt memory_corruption_check=0 psi=1
initrd /initramfs
savedefault
}
menuentry 'Gentoo genkernel (previous)' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-gentoo-genkernel-previous' {
load_video
insmod gzio
insmod part_gpt
insmod ext2
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root 12345678-0123-4567-cdef-0123456789ab
else
search --no-floppy --fs-uuid --set=root 12345678-0123-4567-cdef-0123456789ab
fi
echo 'Linux gentoo-current wird geladen …'
linux /kernel.old root=UUID=01234567-89ab-cdef-0123-456789abcdef ro init=/lib/systemd/systemd mem_encrypt=off spec_store_bypass_disable=on iommu=pt memory_corruption_check=0 psi=1
initrd /initramfs.old
savedefault
} |
With this trick, every kernel you compile with genkernel will be on top and automatically selected, provided it was the last kernel booted (because I use savedefault). I also use hotkey, so "l" (letter L) will be the current linux.
On your own system, simply copy an autogenerated section from your /boot/grub/grub.cfg to /etc/grub.d/05_linux-static and change it so that it uses the symlinks /boot/kernel and /boot/initramfs for the current, and /boot/kernel.old and /boot/initramfs.old for the previous kernel. |
|
Back to top |
|
|
mael n00b
Joined: 28 Feb 2018 Posts: 37 Location: Germany
|
Posted: Tue Jan 15, 2019 8:30 am Post subject: |
|
|
thanks,
your idea was my solution! many thanks for your input atha ...
i just made 3 symlinks (vmlinuz, config, System.map) from /boot/ directly into /usr/src/linux/ and modified my grub.cfg to a more static linking to these new symlinks in /boot/ in combination with the enabled symlink use-flag in gentoo-sources it kills at least one anoying upgrade step
also thanks to you other guys..
CASE CLOSED, THREAD MARKED AS SOLVED _________________ Gigabyte X99-SLI
Intel Core i7-5960X 16 Threads @ 3 Ghz
64 GB DDR4 RAM @ 2,13 Ghz
AMD Radeon 290X 8 GB RAM
Creative Soundblaster Z
Areca ARC-1883ix-16
16 Samsung 860 EVO 250 GB SSDs @ 3,5 TB RAID 6
Hauppauge HVR-5525
Firmwares are up-to-date |
|
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
|
|