Language: de en it pl pt-br ro

GRUB 2

Basic summary of the major differences going from GRUB 1 (now known as grub-legacy) to GRUB 2:
  • The menu.lst no longer exists.
  • A file called grub.cfg is now in control of the Grub Screen.
  • grub.cfg is automatically generated by the scripts in /etc/grub.d.
  • The partition numbering is also different. Partitions are numbered from 1 instead of 0 (drives are still numbered from 0):
    Linux      grub1     grub2
    /dev/sda1  (hd0,0)   (hd0,1)
    /dev/sda2  (hd0,1)   (hd0,2)
    /dev/sda3  (hd0,2)   (hd0,3)
    
    /dev/sdb1  (hd1,0)   (hd1,1)
    /dev/sdb2  (hd1,1)   (hd1,2)
    /dev/sdb3  (hd1,2)   (hd1,3)
    
  • Stanzas in grub.cfg are phrased slightly differently compared with the menu.lst and can't be copied directly from the Grub 1 menu.lst to the Grub 2 grub.cfg as the grub.cfg file is the 'result' file. The grub.cfg file should never be altered manually.

The Grub 2 default config file

The /etc/default/grub file contains the grub2 variable settings. For instance, timeout on menu, default entries in the menu to be activated, kernel parameters, the use of grub graphics and so forth.

The Grub 2 script files

/etc/grub.d files control the 'result' file called grub.cfg, which is found in /boot/grub/.

The grub.cfg file should never be altered manually. All alterations are to be done with one or all of the following script files located in /etc/grub.d. os-prober should handle 90% of all cases:

00_header:
05_debian_theme: Sets background, text colors, themes
10_hurd: Locates Hurd kernels
10_linux: Locates Linux kernels based on results of the lsb_release command.
20_memtest86+: If the file /boot/memtest86+.bin exists, it is included in the boot menu.
30_os-prober: Searches for Linux and other OS's on all partitions; includes them in the boot menu.
40_custom: A template for adding custom boot menu entries for other Operating Systems.
60_fll-fromiso: A template for adding custom boot menu entries for fromiso to a USB-stick/SSD-card.
60_fll-fromiso is not to be altered use /etc/default/grub2-fll-fromiso
Read  Booting 'fromiso' with Grub 2

After an alteration is made, grub.cfg needs to know about the changes. In the case of siduction kernel upgrades, the update command is automatically run. In the case of a manual alteration made by you as the system administrator to any of the above files, you need to run:

update-grub

The Debian Grub2 deb package is designed so that a manual alteration by you would be rarely needed.

Upgrading from Grub Legacy to Grub 2

We recommend to upgrade to Grub 2 cleanly and remove Grub 1 totally. You should be aware that you can mess everything up so be very careful.

Step 1:

Ensure that your system is fully dist-upgraded in init 3.

apt-get update
Ctrl+alt+F1
init 3
apt-get dist-upgrade
init 5 && exit
Step 2:

Remove Grub 1 totally:

rm -rf /boot/grub
apt-get purge grub-gfxboot

The result will be that fll-iso2usb* grub-gfxboot* install-usb-gui* will be removed. Type Y to confirm.

Step 3:
apt-get install grub2 os-prober
Grub2

Use the tab key to select OK

Grub2

Use the tab key to select OK

Grub2-conversion 1

Use the keyboard arrow and space bar to place an * (asterisk) to select what hard drive MBR Grub2 is going to write to. (This example to installing to a USB drive).

Step 4:
update-grub
Step 5:
apt-get install install-usb-gui fll-iso2usb
Step 6:

Reboot your PC and the menu.cfg will display the kernel and Operating System list like this:

Grub2-OS list

Should there be a corruption or something did go wrong refer to Overwritten or corrupted Grub2 in the MBR

Editing Grub2 boot options via the edit screen

Grub2-Edit

If, for some reason, you need to make a temporary alteration to the boot options to a kernel highlighted in Grub2, press the letter e to edit the kernel options and by using the using arrow keys, navigate to the line that you wish to edit, then while still in the edit screen use Ctrl+x to boot the computer with your edited options.

For example, to go directly to run level 3, add 3 to the end linux /boot/vmlinuz line.

The edits you make via the edit screen and are not permanent. To make permanent changes, you need to edit the appropriate files. See Grub 2 files.

Dual and multi booting with Grub 2

As Grub2 is modular in configuration, it allows a simple command to seek out any newly installed operating systems and if one is found, it tries to implement the change to update the menu.cfg. The simple command is:

update-grub

Should you have a need to add a custom entry to menu.cfg or if the 30_os-prober fails to write to grub.cfg with chainloader menus use your favourite text editor to make the amendments to /etc/grub.d/40_custom.

Examples of customising the 40_custom file:

menuentry "second mbr"{
set root=(hd1)
chainloader +1
}
menuentry "second partition"{
set root=(hd0,2)
chainloader +1
}

Then after you have made your changes run:

update-grub

Should it complain that does not know the grub device of a disk, it means that the devicemap must be regenerated.

Ensure that you choose the partition not the MBR when installing the other operating system:

grub-mkdevicemap --no-floppy
update-grub

Warnings can be safely ignored.

Should you make a mistake, the update will probably overwrite your MBR and you will need to fix it with Grub2 - MBR Overwritten.

To only re-write grub2 to MBR from the hard drive:

/usr/sbin/grub-install --recheck --no-floppy /dev/sda

This line may need to be run more than once, until its convinced you really mean it.

MBR Bootsector overwritten by Windows, a corrupted and /or to recover Grub2

NOTE: to restore a Grub2 bootloader you need to have an siduction.iso. Alternatively use chroot with any live.iso.

To rewrite the grub2 to the MBR and/or to recover grub 2 in general, you will need boot up a siduction.iso:

  1. To identify and confirm your partitions (e.g. [h,s]d[a..]X) all the following actions need root privileges, so to get root (#):
    $ sux
    
  2. When in root type in:
    fdisk -l
    cat /etc/fstab
    
    This is to get the correct names.
  3. When you have acertained the correct partition, create the mount point:
    mkdir -p /media/[hdxx,sdxx,diskx]
    
  4. Mount it:
    mount /dev/xdxx /media/xdxx
    
  5. Now rewrite Grub to MBR of the first harddisk (generic):
    /usr/sbin/grub-install --recheck --no-floppy --root-directory=/media/xdxx /dev/sda
    

Using chroot to recover an overwritten or corrupted Grub in the MBR

To recover Grub, if it has been overwritten or corrupted in the MBR, set up a chroot environment. Any live.iso will suffice as the chroot takes you to your hard disk installed system so you can restore the appropriate grub version, grub1 (grub-legacy) or grub2.

Boot up a live siduction.iso that is appropriate for your system (32 or 64 bit CD, DVD, USB stick or an SSD card) and open the konsole. Type in sux and press enter to give you root permissions.

Using fdisk -l or blkid, ascertain which partition is the boot partition and get the correct names. If you prefer a GUI use Gparted:

blkid

and to check that fstab matches the output of the blkid:

cat /etc/fstab

Let's assume your root filesystem is on /dev/sda2

mkdir /mnt/siduction-chroot
mount /dev/sda2 /mnt/siduction-chroot

Next, you need to mount /proc, /run, /dev and /sys as follows:

mount --bind /proc /mnt/siduction-chroot/proc
mount --bind /run /mnt/siduction-chroot/run
mount --bind /sys /mnt/siduction-chroot/sys
mount --bind /dev /mnt/siduction-chroot/dev
mount --bind /dev/pts /mnt/siduction-chroot/dev/pts

If you boot using an EFI system partition you will also need to mount it. Assuming this is /dev/sda1:

mount /dev/sda1 /mnt/siduction-chroot/boot/efi

Your chroot environment is now set up, access it with:

chroot /mnt/siduction-chroot /bin/bash

Now you are able to use apt's local cache or alter files that you need to fix as if you were properly booted to the OS, in this case to fix Grub back onto the MBR.

To restore Grub 2

apt-get install --reinstall grub-pc

To ensure that grub was installed to the correct disk or partition, run:

dpkg-reconfigure grub-pc

To restore Grub 2 EFI

apt-get install reinstall grub-efi-amd64

To restore Grub 1 (grub-legacy)

apt-get install --reinstall grub-legacy

Follow the installers instructions.

To release the chroot:

Ctrl+d

Reboot your PC.

Page last revised 15/01/2012 1400 UTC