Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to schedule a reboot to a temporary partition from the command line on a X86 Linux box without manual intervention. Is it possible that this can be done.

As I see it I have only one option as of this moment Change the boot loader config file using a program and then a revert after booting into the temporary partition (which as you might imagine is extremely dangerous and stupid).

share|improve this question
    
what bootloader? grub? grub2? other? –  quack quixote Dec 10 '09 at 6:55

3 Answers 3

I don't see what's so dangerous or stupid about it:

  • Add lines to boot from temporary partition
  • Make temporary partition default
  • Reboot
  • When you're done, remove the lines and set the default back

If anything goes wrong, you can always select your normal OS.

I have a question though, what are you planning to do? Whatever you're doing may be simpler to do in a chroot or a VM.

share|improve this answer
    
it's the automated part i think he's concerned about... –  quack quixote Dec 10 '09 at 8:10
    
Yeah your solution is better than mine. –  Brendan Long Dec 10 '09 at 19:17

I think you're looking for a boot-once solution. The examples below are shown with Grub v1; they should be easily translatable to a Grub v2-style configuration.

You need to add a basic boot config for your temporary partition. Your grub config might look like the below. You'd activate a reboot into the temporary partition by executing grub-set-default 1 followed by reboot.

On Debian with Grub v1, the boot config is /boot/grub/menu.lst and the saved default boot is written to /boot/grub/default. The grub-set-default command changes the value in this file to the boot entry to be auto-booted on reboot. On reboot, grub boots that entry, and the savedefault 0 resets /boot/grub/default back to the regular boot entry for subsequent boots.

With this solution you don't need to edit the config and reset it every time you want to boot the temporary partition. However, you do need to have the entry in the grub config to begin with. You could possibly make it work with a chainloader if you don't know the kernel and/or initrd lines ahead of time. (I've never tried to use Grub to chainload Grub, so I don't know how well that would work.)

  default saved

  # boot entry 0
  title    Default boot
  root     hd(0,0)
  kernel   /boot/vmlinuz-2.6.xx UUID=xxxxxxx ro
  savedefault

  # boot entry 1
  title    Temp boot
  root     hd(0,1)
  kernel   /boot/vmlinuz  UUID=yyyyyyyy ro
  savedefault 0

  # boot entry 2, chainloader version of boot entry 1
  title    Temp boot
  root     hd(0,1)
  savedefault 0
  makeactive
  chainloader +1
share|improve this answer

The nature of booting means that the only things available at boot time are the boot program and its configuration. Therefore, if you are going to modify anything, it will have to be somewhere in the bootloader.

The happy news is that modifying the configuration (in grub, a text file) is a pretty safe operation. You can even save backup copies to fall back on. And grub itself can be worked from a command line if you get into a sticky situation.

If you want to see "dangerous", that would be those options or programs that rewrite the partition tables! Grub had (or maybe has) a command like that some years ago, and I wiped out a laptop the first time I tried it. (I did fix it, but it took a long time).

The key to your project will be (in grub, anyway) that there's a keyword default that you can use to designate which partition you want to boot from. I think just moving that keyword around will change what you boot. You might also think about booting from a thumb drive as your "temporary" boot partition.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.