2011-12-19

Grub2 Configuration Examples

Grub2 Configuration Examples

ABSTRACT
I use Ubuntu11.10 as my "main Operating System (OS)" that uses GRUB2 to boot.
In order several other OS, I added my own boot entries to Grub.

Bellow you will find GRUB entries than allows me to boot the following OSes:
  • Ubuntu 11.10
  • Windows Vista
  • CentOS release 6.1
  • Puppy Linux 5.2.2
  • Parted Magic 2011_11_24
  • Parted Magic 2011_11_24 from an ISO image file
  • Oracle VM (OVM) 3.1

MY DISK AN PARTITIONING STRUCTURE

In order to understand how to access the partitions from GRUB2 i need to know the partitioning structure of my disks.
Where the several OS are located.

The Structure of my two Disks (sda 1TB and sdb 3TB) using the command "df":
root@ubu11:/etc/grub.d# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 49G 31G 19G 63% /media/565EC2BA5EC291E3
/dev/sda2 786G 111M 785G 1% /media/Backup
/dev/sda3 485M 53M 407M 12% /media/4e3a3a1c-5a1e-48d3-bf31-abc1f621ef10
/dev/sdb2 481G 58G 400G 13% /
/dev/sdb4 2.3T 194G 2.0T 10% /media/Data

The Structure of my Disk (sda 1TB) using "fdisk" (i could not display the structure of the 3 TB disk using this program):
root@ubu11:/etc/grub.d# fdisk /dev/sda

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000001

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 102414374 51206163+ 7 HPFS/NTFS/exFAT
/dev/sda2 102414375 1748723444 823154535 7 HPFS/NTFS/exFAT
/dev/sda3 1748723712 1749747711 512000 83 Linux
/dev/sda4 1749747712 1953523711 101888000 5 Extended
/dev/sda5 1749749760 1953523711 101886976 8e Linux LVM


AUTOMATICALLY GENERATED ENTRIES
Grub2 automatically generate entries by "autoprobing" exitent bootable OSes.

In the generated file "/boot/grub/grub.cfg" I got find the following entries (besides others) generated during the installation and update.

The entry of the own (main) Ubuntu 11.10 OS:
menuentry 'Ubuntu, with Linux 3.0.0-14-generic' --class ubuntu --class gnu-linux --class gnu --class os {
recordfail
set gfxpayload=$linux_gfx_mode
insmod gzio
insmod part_gpt
insmod ext2
set root='(hd1,gpt2)'
search --no-floppy --fs-uuid --set=root a76be1e4-00f2-4282-953f-751eceac0ad1
initrd /boot/initrd.img-3.0.0-14-generic
}

linux /boot/vmlinuz-3.0.0-14-generic root=UUID=a76be1e4-00f2-4282-953f-751eceac0ad1 ro quiet splash vt.handoff=7
And the Windows Vista entry that GRUB2 automatically generated by its OS probing functionality:
menuentry "Windows Vista (loader) (on /dev/sda1)" --class windows --class os {
insmod part_msdos
insmod ntfs
set root='(hd0,msdos1)'
search --no-floppy --fs-uuid --set=root 565EC2BA5EC291E3
chainloader +1
}


MY OWN HAND WRITTEN ENTRIES
Perform the following steps as "root":
# cd /etc/grub.d/
# vim -g 40_custom

Append the following entries to the file " /etc/grub.d/40_custom ":

#-------------------------------------------------------------------------------------------------
# I have two hard disks
# 1st) SATA SAMSUNG HD 103UJ - 1 TB => /dev/sda
# 2nd) SATA Hitachi HDS7203 - 3 TB => /dev/sdb
#
# I configured the BIOS to boot from the 2nd HD containing Ubuntu 11.10 as main OS with GRUB2.
# This file contains the own configuration of this GRUB2.

# In the configuration entries bellow the following HD GRUP mapping is used:
# Physical HD GRUB2 Notation
# --------------- -------------------------------
# 1st HD /dev/sda (hd1, ...) i.e. 2nd HD for GRUB
# 2nd HD /dev/sdb (hd0, ...) i.e. 1st HD for GRUB
# GRUB2 seems to regard the own HD (from which the Computed gets
# booted) as the first one and the other as the second.
#-------------------------------------------------------------------------------------------------


# Physically this OS is installed on the 1st HD, on the 3rd partition.
# For GRUB on the 2nd HD, 3rd partition => (hd1, msdos3)
# I do not know why, but I needed to use "insmod ext2" in order to see the 3rd partition and needed
# to use "msdos3" in order to access it.
# (I do not know if the other insmod are realy needed. I did not try without them.)
menuentry "CentOS release 6.1 (on /dev/sda2)" {
insmod gzio
insmod part_gpt
insmod ext2
insmod part_msdos
set root='(hd1,msdos3)'
linux /vmlinuz-2.6.32-131.0.15.el6.x86_64 ro root=/dev/mapper/vg_cent-lv_root rd_LVM_LV=vg_cent/lv_root rd_LVM_LV=vg_cent/lv_swap rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=sg-latin1 crashkernel=auto rhgb quiet
initrd /initramfs-2.6.32-131.0.15.el6.x86_64.img
}

# Boots the directory "/PuppyLinux522" on the same HD as GRUB (1st HD, 2nd Partiton => "(hd0,gpt2)")
# This is the same partition as the one where this file GRUB configuration file is stored.
menuentry "Puppy Linux 5.2.2 (auf /PuppyLinux522)" {
insmod ext2
set root='(hd0,gpt2)'
search --no-floppy --fs-uuid --set=root a76be1e4-00f2-4282-953f-751eceac0ad1
linux /PuppyLinux522/vmlinuz pdev=sdb2 psubdir=PuppyLinux522
initrd /PuppyLinux522/initrd.gz
}

# Boots the directory "/PMagicLinux" on the same HD as GRUB (1st HD, 2nd Partiton => "(hd0,gpt2)")
# This is the same partition as the one where this file GRUB configuration file is stored.
mmenuentry "Parted Magic 2011_11_24 (auf /PMagicLinux)" {
recordfail
insmod gzio
insmod part_gpt
insmod ext2
insmod part_msdos
set root='(hd0,gpt2)'
search --no-floppy --fs-uuid --set=root a76be1e4-00f2-4282-953f-751eceac0ad1
linux /PMagicLinux/pmagic/bzImage root=/dev/sdb2 directory=PMagicLinux edd=off noapic load_ramdisk=1 prompt_ramdisk=0 rw vga=791 loglevel=0 max_loop=256 keymap=de_CH-latin1
initrd /PMagicLinux/pmagic/initrd.img
}

# Boots the ISO image file "pmagic_2011_11_24_x86_64.iso" in the directory "/ISOs" on the same HD
# as GRUB but on another partition (1st HD, 4nd Partiton => "(hd0,gpt4)")
menuentry "Parted Magic 2011_11_24 ISO (on (hd0,gpt4)/ISOs/pmagic_2011_11_24_x86_64.iso" {
set isofile="/ISOs/pmagic_2011_11_24_x86_64.iso"
loopback loop (hd0,gpt4)$isofile
linux (loop)/pmagic/bzImage iso_filename=$isofile boot=pmagic edd=off noapic load_ramdisk=1 prompt_ramdisk=0 rwnomce sleep=0 loglevel=0 keymap=de_CH-latin1 vga=791
initrd (loop)/pmagic/initrd.img
}


After having addad the entries from above, I regenerated the file " /boot/grub/grub.cfg":
# grub-mkconfig -o /boot/grub/grub.cfg
Generating grub.cfg ...
Found background image: DanjaForGrubBackground.png
Found linux image: /boot/vmlinuz-3.0.0-14-generic
Found initrd image: /boot/initrd.img-3.0.0-14-generic
Found linux image: /boot/vmlinuz-3.0.0-13-generic
Found initrd image: /boot/initrd.img-3.0.0-13-generic
Found linux image: /boot/vmlinuz-3.0.0-12-generic
Found initrd image: /boot/initrd.img-3.0.0-12-generic
Found linux image: /boot/vmlinuz-2.6.38-11-generic
Found initrd image: /boot/initrd.img-2.6.38-11-generic
Found linux image: /boot/vmlinuz-2.6.38-8-generic
Found initrd image: /boot/initrd.img-2.6.38-8-generic
Found memtest86+ image: /boot/memtest86+.bin
Found Windows Vista (loader) on /dev/sda1
done


This entry worked once but I do not use it any more because this Linux version is very restricted and Parted Magic offers the same functionality and more:
menuentry "OK: Gparted Live 0.10.0 (auf /Data/ISOs)" {
set isofile="/ISOs/gparted-live-0.10.0-3.iso"
loopback loop (hd0,gpt4)$isofile
linux (loop)/live/vmlinuz boot=live config union=aufs noswap noprompt ip=frommedia findiso=$isofile toram=filesystem.squashfs
initrd (loop)/live/initrd.img
}

# 2011.12.19 - OK but not used any more, because Parted Magic 2011_11_24 that I have installed is a newer version and 64 bit.
# With the 64 bit version I can perform all operations. This is not the case on by 64 bit computer with this
# version 4.10 on 32 bit mode.
# I created the directory /PartedMagicLinux on root of the directory tree of the Ubuntu 11.10, than I copyed the
# content of the USB memory stick containing Parted Magic Version 4.10 32 bit into it.
menuentry "Parted Magic 32 bit Version: 4.10 (on /PartedMagicLinux)" {
recordfail
insmod gzio
insmod part_gpt
insmod ext2
insmod part_msdos
set root='(hd0,gpt2)'
search --no-floppy --fs-uuid --set=root a76be1e4-00f2-4282-953f-751eceac0ad1
linux /PartedMagicLinux/pmagic/bzImage root=/dev/sdb2 directory=PartedMagicLinux edd=off noapic load_ramdisk=1 prompt_ramdisk=0 rw vga=791 loglevel=0 max_loop=256 keymap=de_CH-latin1
initrd /PartedMagicLinux/pmagic/initramfs
}

OK but not used any more because I uninstalled Ora VM Server
menuentry "OK: Oracle VM Server-ovs (xen-4.0.0 2.6.32.21-41ovs)" --class gnu-linux --class gnu --class os {
insmod part_msdos
insmod ext2
set root=(hd1,msdos2)
multiboot /boot/xen.gz dom0_mem=826M
module /boot/vmlinuz-2.6.32.21-41xen ro root=UUID=ace79edc-24cf-4831-b313-015306190462
module /boot/initrd-2.6.32.21-41xen.img
}


The following entries does not work yet:
menuentry "OnWork: ISO: Fedora 14" {
set isofile="/ISOs/Fedora-14-i686-Live-Desktop.iso"
loopback loop (hd0,gpt4)$isofile
linux (loop)/isolinux/vmlinuz boot=isolinux iso-scan/filename=$isofile noeject noprompt --
initrd (loop)/isolinux/initrd0.img
}


The these entries are only examples that I have taken from the Internet:
menuentry "Example: Lucid ISO" {
loopback loop (hd0,1)/boot/iso/ubuntu-10.04-desktop-i386.iso
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=/boot/iso/ubuntu-10.04-desktop-i386.iso noprompt noeject
initrd (loop)/casper/initrd.lz
}

menuentry "Example: Karmic 64-bit ISO" {
loopback loop (hd0,1)/boot/iso/ubuntu-9.10-desktop-amd64.iso
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=/boot/iso/ubuntu-9.10-desktop-amd64.iso noprompt quiet splash
initrd (loop)/casper/initrd.lz
}

menuentry "Example: Gparted Live ISO" {
set isofile="/boot/iso/gparted-live-0.10.0-3.iso"
loopback loop (hd0,1)$isofile
linux (loop)/live/vmlinuz boot=live config union=aufs noswap noprompt ip=frommedia findiso=$isofile toram=filesystem.squashfs
initrd (loop)/live/initrd.img
}

menuentry "Example: SystemRescue CD ISO" {
set isofile="/boot/iso/systemrescuecd-x86-1.5.8.iso"
loopback loop (hd0,1)$isofile
linux (loop)/isolinux/rescue64 setkmap=us isoloop=/systemrescuecd-x86-1.5.8.iso
initrd (loop)/isolinux/initram.igz
}

menuentry "Example: Parted Magic ISO" {
set isofile="/boot/iso/pmagic-5.2.iso"
loopback loop (hd0,1)$isofile
linux (loop)/pmagic/bzImage iso_filename=$isofile boot=live load_ramdisk=1 prompt_ramdisk=0 noeject noprompt
initrd (loop)/pmagic/initramfs
}

menuentry "Example: Boot IMG - Seagate Tools" {
linux16 /memdisk bigraw
initrd16 /SeaTools.img
}

# Courtesy of cbowman57 in Post #54; with Clonezilla ISO located in sda9's root directory (/)
menuentry "Example: Clonezilla live" {
set isofile="(hd0,9)/clonezilla-live-1.2.8-3-amd64.iso"
loopback loop $isofile
linux (loop)/live/vmlinuz boot=live live-config noswap nolocales edd=on nomodeset ocs_live_run=\"ocs-live-general\" ocs_live_extra_param=\"\" ocs_live_keymap=\"\" ocs_live_batch=\"no\" ocs_lang=\"\" vga=788 ip=frommedia nosplash toram=filesystem.squashfs findiso=$isofile
initrd (loop)/live/initrd.img
}

# Modified from the post by Dancer_69
menuentry "Example: Gentoo 11 Live DVD" {
set isofile="/boot/iso/gentoo-livedvd-x86-amd64-32ul-11.0.iso"
loopback loop (hd1,6)$isofile
linux (loop)/boot/gentoo root=/dev/ram0 init=/linuxrc dokeymap looptype=squashfs loop=/image.squashfs cdroot initrd=/boot/gentoo.igz isoboot=/boot/iso/gentoo-livedvd-x86-amd64-32ul-11.0.iso
initrd (loop)/boot/gentoo.igz
}