[Cialug] reboot into a different OS w/ grub

Zachary Kotlarek zach at kotlarek.com
Mon May 3 15:28:35 CDT 2010


On May 3, 2010, at 2:17 PM, Matthew Nuzum wrote:

> Hi, I saw this on commandlinefu.com:
> http://www.commandlinefu.com/commands/view/5509/reboot-as-a-different-os-in-grub
> $ echo "savedefault --default=2 --once" | grub --batch; sudo reboot


> Will the above help with the above? Can anyone explain how the command
> works? (I've searched the grub manual page and can't find reference to
> savedefault or --once)


http://www.gnu.org/software/grub/manual/html_node/Booting-once_002donly.html

"default saved" asks GRUB to recall the last configuration set with the "savedefault". The "savedefault 0" is the real magic though -- that tells GRUB to remember configuration 0 even though you're currently booting from configuration 1, thus forcing the following boot to go back to configuration 0.

I'm guessing that's what the --once flag does, though I'm not terribly familiar with programatic editing of the GRUB config, so I could just be making that up. But the above config will produce the behavior your desire.

--

That sort of configuration will automatically reboot back to the old config, which will save you from a kernel panic, assuming your system gets around to rebooting after the panic. Depending on the cause of the panic and your kernel config that may or may not happen.

All you need to save you from a lack of networking or filesystem access is a boot script (in the initramfs if you're trying to check pre-root-fs things) that checks for whatever you care about and, on failure, sets your GRUB config to a safe default and reboots. If used in combination with the boot-once GRUB config the failure behavior could just be "reboot" because GRUB would already handle the configuration change internally.

	Zach

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2746 bytes
Desc: not available
Url : http://cialug.org/pipermail/cialug/attachments/20100503/e2de13d7/attachment.bin 


More information about the Cialug mailing list