View previous topic :: View next topic |
Author |
Message |
hydrapolic Tux's lil' helper
Joined: 07 Feb 2008 Posts: 126
|
Posted: Wed Jul 04, 2012 12:02 pm Post subject: grub-2.00 fallback howto |
|
|
This is a howto for those that would like to run grub2 with fallback. The problem is obvious: you administer a Gentoo machine that you don't have physical access to, or it takes too long to access it. However, as a good sysadmin, you want to keep your kernel up to date. It's not unusal to forget to compile in some driver and boooom ! Ping fails and you get nervous thinking about what you did wrong...
I'm happily using kernel 3.3.8 and I realy want to try out the new 3.4.4 release !
# /usr/sbin/grub2-set-default 0
# cat /boot/grub2/grub.cfg
Code: |
load_env
function savedefault {
saved_entry=1
save_env saved_entry
}
set default="${saved_entry}"
set timeout=5
menuentry 'Gentoo 3.4.4' {
savedefault
root=hd0,1
linux /kernel-3.4.4-gentoo root=UUID=ad584938-9193-4cbc-8b87-3b74929205b4 panic=5
initrd /initramfs-3.4.4-gentoo.img
}
menuentry 'Gentoo 3.3.8' {
root=hd0,1
linux /kernel-3.3.8-gentoo root=UUID=ad584938-9193-4cbc-8b87-3b74929205b4 panic=5
initrd /initramfs-3.3.8-gentoo.img
}
|
grub2-set-default stores the saved_entry variable in /boot/grub2/grubenv. load_env loads the variables (saved_entry) and sets the default entry to 0 (because we set it to 0). Grub2 tries to load Gentoo 3.4.4 but since it ends with a kernel panic (I "forgot" to include my sata drivers), the system reboots in 5 seconds (panic=5). However, before the system rebooted, the savedefault function stored saved_entry=1 in grubenv. After the reboot, grub2 loads the saved_entry of 1 and boots Gentoo 3.3.8. Don't forget to use your own UUID (use blkid).
Comments are welcome (pm). Thank you !
More info about grub2: http://wiki.gentoo.org/wiki/GRUB2_Quick_Start |
|
Back to top |
|
|
mittah n00b
Joined: 30 Oct 2012 Posts: 3
|
Posted: Thu May 07, 2015 11:44 am Post subject: Another way |
|
|
There is another (imho easier) way to get fallback functionality in GRUB2. You will need not to make custom GRUB scripts.
- Edit /etc/default/grub:
Code: | GRUB_DEFAULT=1 # your 100% working kernel (remember, numbering begins from 0, and 0 in autogenerated grub.cfg is your new untrusted kernel)
GRUB_CMDLINE_LINUX="panic=5" # and others yours kernel parameters
GRUB_DISABLE_SUBMENU=y # to be sure in order of elements
|
Set up kernel with 'make install' (to be sure GRUB2 able to detect it) and generate grub.cfg:
Code: | mount /boot
cd /usr/src/linux
make install
grub2-mkconfig -o /boot/grub/grub.cfg
|
Check generated grub.cfg for menu has order you are expecting. Correct GRUB_DEFAULT variable in /etc/default/grub if needed.
Force GRUB2 to boot new kernel:
Code: | grub2-reboot 0
umount /boot
|
If system has started up successfully, set new kernel to boot next time. There are several ways to do it, I'm using cron (fcron and vixie-cron both supports "@reboot" special word, which runs item on systems start up):
and add rule:
Code: | @reboot mount /boot; grub2-reboot 0; umount /boot |
In step 5 you can use OpenRC's 'local' service, systemd's custom unit and so on.
So we have: if kernel has booted successfully, next time it will boot again (grub2-reboot 0), if not, GRUB2 will boot previous reliable kernel (GRUB_DEFAULT=1).
Every next kernel update you will have to do step 2 only. |
|
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
|
|