Penguin
Note: You are viewing an old revision of this page. View the current version.

I need to reinstall grub in my master boot record

Boot off a liveCD, and chroot(8) into your main root partition.

Remember that grub numbering starts at 0: /dev/hda1 becomes (hd0,0), etc.

Run 'grub'. Issue root (hdx,x) if you know where your /boot directory is, or use find /boot/grub/stage1 to find it if you don't. Then issue setup (hdx) to install GRUB in the master boot record of drive hdx, or setup (hdx,x) to setup inside a partition.

I get a grub> prompt on boot

This means GRUB can't find your config file. You can still boot into the system by issuing appropriate commands.

Eg., if I have a system which has a single disk, partitioned with /dev/hda1 as /boot and /dev/hda5 as /root, and I have a Kernel called vmlinuz in /boot, I can do:

root (hd0,0)
kernel /vmlinuz root=/dev/hda5 ro
boot

and it'll boot quite happily -- this time. Note that I set the GRUB root to (hd0,0), which corresponds to /dev/hda1, and so the path to the kernel is relative to the top of /dev/hda1 (which is /boot when mounted correctly). Also note that the GRUB shell features tab completion on filenames, so you can do kernel /[tab] and get a list of possible values. You can also use this to work out which FileSystems are which, as GRUB will understand most Linux FileSystems you're likely to have.

However, the real problem is that GRUB can't find your config file. First, check that you have one - it should be in /boot/grub/menu.lst by default, but some distributions put it at /boot/grub/grub.conf. If the latter is the case, make a symlink between the two and reboot to test: ln -s /boot/grub/grub.conf /boot/grub/menu.lst

If that still doesn't work, it's possible that GRUB is looking in the wrong place for your config. If you installed GRUB using something like grub-install --root-device/boot '(hd0)'= it will install to /boot/grub/ etc, however if your /boot is on a separate partition (as I described in the example above) then it's fairly likely that GRUB is looking in /boot/boot/grub/ for menu.lst -- and not finding it.

Easiest fix (it stops this happening again in the future, so perhaps the best fix?) is to symlink /boot into /boot by doing ln -s /boot /boot/. You should now be able to cd into /boot/boot/grub and it'll have your menu.lst there.

Using a different kernel for the next reboot only

  grub
  savedefault --default=N --once
  (where N is the number of the kernel you want to boot once)
  quit

Reboot your machine. It will boot using kernel "N".

grub-reboot N will do essentially the same thing and prompt to reboot the machine

Using GRUB with a serial console

In the GRUB config file (normally /boot/grub/menu.lst) add these lines to the top to enable the serial console in addition to the regular console:

  serial --unit=0 --speed=9600
  terminal --timeout=10 serial console

GRUB will now display on the serial console as well as locally. It will wait for a keypress for 10 seconds to determine which input is being used, before timing out and carrying on the boot process. If a key is pressed then the regular menu will be displayed and you can select a kernel as usual.

The first line configures the serial link with the following options (defaults to 9600, 8n1 from what I can gather):

  • --unit=X which serial port to use. 0 = ttyS0, 1 = ttyS1 etc
  • --speed=X the rate in bps the serial link should run at
  • --word=X number of data bits
  • --parity=X parity to use, where X is one of 'no', 'even', 'odd'
  • --stop=X number of stop bits to use

The second line specifies which devices should be used for input/output. You can set it up so that it only displays locally, only on the serial console, or on both.

  • --timeout=X the number of seconds GRUB should wait for a keypress before continuing
  • serial if this option is present, the serial console will be used
  • console if this option is present, the local console will be used

If both serial and console are present, then grub will use whichever method accepts a keypress first

Making your kernel do serial too!

If you have GRUB setup to use a serial console then you probably want to compile your kernel with serial console support and append the following options to your boot line, so your kernel messages appear on your serial console too. If you don't do this you'll have a big empty screen between grub loading the kernel and your getty loading, when you think that your kernel has hung!

console=ttyS0,19200n8

So a full kernel boot line might look like kernel /boot/vmlinuz ro root/dev/hda1 console=tty0 console=ttyS0,19200n8=


GRUB resources on the web