GRUB2 Fallback

General support questions
Post Reply
hunter86_bg
Posts: 2019
Joined: 2015/02/17 15:14:33
Location: Bulgaria
Contact:

GRUB2 Fallback

Post by hunter86_bg » 2016/11/24 18:15:14

Hi community,

I have a situation where I can access several VMs only by ssh.I have to update the kernel, but I don't want to lock myself out if the new kernel panics.
Here is my idea, but I can't make it to work.

1. Add "panic=10" to the kernel parameters (/etc/default/grub), in order to reboot on kernel panic after 10 seconds.
2. Enabling grub_default=saved in "/etc/default/grub" (Not sure if this is needed),so I can save the default entry.
3. Modify grub.cfg in such way that when selecting the newest kernel entry it will automatically change the default grub entry to an older kernel.If the VM gets into kernel panic and reboots - it should not select the newest kernel again.
4. Setting in crontab "@reboot root /sbin/grub2-set-default 0", so if the VM manages to boot successfully - the default kernel entry in grub to be set to the newest one.

If anyone has an idea how to do this, I will be really happy.
Thanks in advance.

hunter86_bg
Posts: 2019
Joined: 2015/02/17 15:14:33
Location: Bulgaria
Contact:

Re: GRUB2 Fallback

Post by hunter86_bg » 2016/11/24 18:40:01

Ok, I think I found a solution.

1. Set "panic=10" for all kernels in "/etc/default/grub"
2. Set a fallback entry , in case grub fails to boot the newest kernel for some reason

Code: Select all

echo "set fallback=1" >> /etc/grub.d/40_custom
3. Regenerate the grub menu:

Code: Select all

grub2-mkconfig -o /etc/grub2.cfg
4. Set default grub to an older entry:

Code: Select all

grub2-set-default 1
5. Set to boot only 1 time to latest entry via

Code: Select all

grub2-reboot 0
6. Reboot. If a kernel panic occurs and the kernel reboots - it will fall back to the default "1" - which should be our older kernel.

If anyone has a better solution - be my guest.

Edit: changed the order and added another step.

hunter86_bg
Posts: 2019
Joined: 2015/02/17 15:14:33
Location: Bulgaria
Contact:

Re: GRUB2 Fallback

Post by hunter86_bg » 2016/11/28 12:24:21

I have tested this and everything is fine. Don't forget to

Code: Select all

grub2-set-default 0 
, once you manage to boot the latest kernel.

Post Reply