Grub boot loader

From Edgar BV Wiki
Jump to navigation Jump to search

Upgrading from v1 to v2

To upgrade to grub v2, you should:

  1. Install grub v2 (but don't remove the grub 1 yet).
  2.
     Follow the instruction displayed the package installation (i.e grub v1 now has an entry to cascade to grub v2, so reboot and try it, then you can actually enable grub2 bootloader by running upgrade-from-grub-legacy). 

Grub2 / debian package grub-pc:

Differences:

  1. No /boot/grub/menu.lst. It has been replaced by /boot/grub/grub.cfg.
  2. The main menu file, /boot/grub/grub.cfg is not meant to be edited, even by 'root'.
  3. grub.cfg is overwritten anytime there is a update, a kernel is added/removed or the user runs `update-grub` *
  4. The user can use a custom file, /etc/grub.d/40_custom, in which the user can place his own entries. This file will not be overwritten.
  5. The primary configuration file for changing menu display settings is /etc/default/grub.
  6. There are multiple files for configuring the the menu - /etc/default/grub mentioned above, and all the scripts in /etc/grub.d/ folder.

Reinstalling GRUB 2 from LiveCD

If you cannot boot from GRUB 2 and need to reinstall it, here is the simple method. For more details or for advanced options, refer to the Ubuntu community documentation here: Grub2 - Reinstalling GRUB 2:

   * Boot the Karmic or Lucid LiveCD (Try without installing).
   * From the Desktop, open a terminal - Applications, Accessories, Terminal.
   * Determine your normal system partition - `sudo fdisk -l` (That is a lowercase L)
   * If you aren't sure, run `df -Th`. Look for the correct disk size and ext3 or ext4 format.
   * Mount your normal system partition:
     Code:
     sudo mount /dev/sdXY /mnt
         o Example: sudo mount /dev/sda1 /mnt
         o Note: The partition to mount is normally the partition on which Ubuntu was installed: sda1, sdb5, etc. If you have a separate /boot partition, use the device on which the /boot partition is located. Grub 2 works best when installed in the MBR of the drive to which BIOS boots. Also remember that you mount the partition (including the number) in this step, but you do not include the partition number when you run the "sudo grub-install" command later.
         o Note: GRUB 2 counts the first drive (X) as "0", but the first partition (Y) as "1"
   * Only if you have a separate boot partition:
         o
           Code:
           sudo mount /dev/sdXY /mnt/boot
           with sdXY being your /boot partition designation.
   * Reinstall GRUB 2:
     Code:
     sudo grub-install --root-directory=/mnt /dev/sdX
   *
         o Example: sudo grub-install --root-directory=/mnt /dev/sda
         o Note: Substitute the device on which Ubuntu was installed - sda, sdb, etc. Do not specify a partition number.
   * Unmount the partition:
     Code:
     sudo umount /mnt
   * Reboot.

use

update-grub

to set changes to the boot configuration and to search for kernels to add to /etc/grub/grub.cfg.

   *
     menuentry "System Rescue CD" {
     set root=(hd0,10)
     linux /sysrcd/rescuecd subdir=sysrcd setkmap=us
     initrd /sysrcd/initram.igz
     }
   * Note the new partition naming convention. Devices start counting from "0" as done previously. sda is designated as "hd0", sdb is "hd1", etc. However the first partition is now designated as sda1. Counting partitions does not start with "0". sda5 is "5".
   * If the user wishes to get visual confirmation in the terminal that the 40_custom file contents are being added when "update-grub" is executed, the following line can be added to the /etc/grub.d/40_custom file:
         o
           Quote:
           echo "Adding 40_custom menu entries." >&2
         o Place this line immediately after the first line - "#!/bin/bash" - and before the "exec tail -n +3 $0" line.
  1. Tip: If you want to have your custom entries at the top of the menu (say you want custom titles), create a new file and name it "07_xxxx". Since the files in /etc/grub.d/ are read sequentially, those in "07_custom" will be placed before those of "10_linux". I recommend not naming a custom menu file lower than 06 so that any theme run from 05_debian_theme is allowed to run before any custom menu is created. After creating the file, run sudo update-grub and then check the value of "DEFAULT" in /etc/default/grub. If it doesn't point to the correct menuentry, change the value of DEFAULT to the correct menuentry value.

from this article

recovering in grub

  1. you should make it to the grub menu now.

(from http://ubuntuforums.org/showthread.php?t=1594052)

?
ls - shows you all devices
ls (devname)/boot/grub - should show you a directory listing. You need this directory
set prefix=(devname)/boot/grub
set root=(devname)
set
insmod linux
linux /vmlinuz root=/dev/devname ro
initrd /initrd.img
boot

Grub 1

To install grub do

>> apt-get install grub

Then to activate grub on the MBR do

>> grub-install /dev/hdXX #(device where to put the bootloader - generally the / partition if you run mount)

To create the /boot/grub/menu.lst you do

>> update-grub

around the top is the line

default 0

This sets the option that will be run by default (starts at 0 and goes up). Look at the options and see which one will be run - it seems to want to put 2.4 kernels ahead of 2.6 kernels!

Then you run grub

This puts you in the grub menu.

In the grub menu do:

grub> root (hd0,0)

grub> setup (hd0)

Then reboot and see how it went!


grub on a new hd

To put grub on a new HD, first create a grub boot floppy with


grub-floppy


then reboot into the grub floppy.


In the grub menu do:

grub> root (hd0,0)

grub> setup (hd0)


and then reboot!


A typical basic /boot/grub/menu.lst


default 0

timeout 5

color cyan/blue white/blue


title Debian GNU/Linux, kernel 2.6.26-2-amd64

root (hd0,0)

kernel /vmlinuz-2.6.26-2-amd64 root=/dev/mapper/tripenclosure-root ro quiet

initrd /initrd.img-2.6.26-2-amd64


title Debian GNU/Linux, kernel 2.6.26-2-amd64 (single-user mode)

root (hd0,0)

kernel /vmlinuz-2.6.26-2-amd64 root=/dev/mapper/tripenclosure-root ro single

initrd /initrd.img-2.6.26-2-amd64