-1

I have a system with several Red Hat installations on a single hard drive. I would like to automatically select the default installation to boot during runtime. The Red Hat way of doing this (which differs slightly from the Grub documentation) is to enter the grub shell and say

savedefault --stage2=<Stage 2 File> --default=<default>

which saves into the specified.

I use chainloading, so there are several grub.conf files on the disk. I only want to alter the stage2 file associated with the one tied to the MBR in /boot, not the individual ones associated with the installations themselves. In grub, if I say

find /boot/grub/stage2

or

find /grub/stage2

I get back valid lists of full pathnames to the partitions and files involved. In the former case, something like

(hd0,1)
(hd0,2)

and in the latter

(hd0,0)

It's the latter case I want to change. However, if I then say

root (hd0,0)

savedefault --stage2=/grub/stage2 --default=1

or variants like

savedefault --stage2=(hd0,0)/grub/stage2
savedefault --stage2=(hd0,0)/boot/grub/stage2

or similar, I get

Error 15: File not found

I vaguely suspect that I'm not mounting the partition properly, and that it perhaps read-only the way I'm doing things, but nothing I do seems to change the proper stage2 file. Note that if I just say

savedefault --stage2=/boot/grub/stage2 --default=1

or leave the '--stage2=...' option off entirely, the command succeeds, but changes the stage2 file on the partition the currently running OS was booted from - not the one associated with the MBR grub.conf which actually controls the initial boot.

What am I missing here?

SixDegrees
  • 781
  • 1
  • 8
  • 19

1 Answers1

0

So, it appears the answer is to brute-force overwrite the stage2 grub file. This is where the saved menu entry is stored.

Grub legacy guarantees that certain variables are hard-coded into specific locations in this file (see here). Note that these offsets are given relative to a 512-byte offset in the case of stage2. In our particular case, we want to alter the saved entry number, at offset 0x200 + 0xC. To change it to a 1, we say

printf '\x01' | dd conv-notrunc of=/boot/grub/stage2 bs=1 seek=$((0x20c))

and on the next reboot, grub will automatically select menu entry 1.

This is what the grub-set-default command is supposed to do, but it is missing in Redhat distributions, and the alternative 'fix' described above doesn't work.

SixDegrees
  • 781
  • 1
  • 8
  • 19