Ssh – Bootloader replacement with ssh


I have a PC in our server room which dual boots to windows and linux.

Obviously when we need to reboot the box we can get onto which ever system it is running and reboot.

However, I cannot select the OS to boot at the bootloader for obvious reasons.

Is there a way, other than installing a KVM, where we could replace the bootloader with something that accepts an ssh connection and lets me boot accordingly.

I can't believe I'm the only person who would find this useful.


Best Answer

Most Linux bootloaders provide a way to select a particular boot menu item just for the next reboot:

  • lilo -R cmdline — for LILO;
  • echo "savedefault --default=2 --once" | grub --batch — for GRUB Legacy;
  • grub-editenv could be used for GRUB 2 (here you should set prev_saved_entry to your normal default, and set saved_entry to the system which needs to be booted once, but all this depends on code present in grub.cfg).

You can keep Linux selected by default, and boot Windows when needed using such boot-once mechanism. This may be not very convenient when you need to reboot Windows multiple times, but without boot-once changing the bootloader configuration could be hard when the system is stuck booting Windows by default. Although if you add another very small Linux installation, which boots by default, listens for an SSH connection for a minute, and then specifies a boot-once choice configured in some file and reboots, you may have even persistent Windows reboot configuration with the ability to reconfigure it during that delay.

Another option, if you are using Windows earlier than Vista/2008 (e.g., still using NTLDR and boot.ini), is to use NTLDR as the primary boot manager and chain to the Linux bootloader by loading its boot sector saved in a file. Then you could be able to edit boot.ini both from Windows and Linux (if you are not afraid to use ntfs-3g to access Windows system disk from Linux). However, this scheme is easier to break (especially when using LILO as Linux bootloader, which will require updating the boot sector file after every reconfiguration).

Yet another option is to use PXE remote boot with PXELINUX and chain.c32 to continue boot from a particular HDD partition, which then could be switched by changing a config file on the TFTP server — however, this needs cleartext traffic between the machine and boot servers (DHCP and TFTP).