Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
grub-2.00 fallback howto
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
hydrapolic
Tux's lil' helper
Tux's lil' helper


Joined: 07 Feb 2008
Posts: 126

PostPosted: Wed Jul 04, 2012 12:02 pm    Post subject: grub-2.00 fallback howto Reply with quote

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
View user's profile Send private message
mittah
n00b
n00b


Joined: 30 Oct 2012
Posts: 3

PostPosted: Thu May 07, 2015 11:44 am    Post subject: Another way Reply with quote

There is another (imho easier) way to get fallback functionality in GRUB2. You will need not to make custom GRUB scripts.

  1. 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

  2. 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

  3. Check generated grub.cfg for menu has order you are expecting. Correct GRUB_DEFAULT variable in /etc/default/grub if needed.
  4. Force GRUB2 to boot new kernel:
    Code:
    grub2-reboot 0
    umount /boot

  5. 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):
    Code:
    crontab -e

    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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
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