GRUB – GRand Unified Bootloader

I am going to discuss, how to add one more OS(which is at seperate partition of harddisk) with GRUB2..

You need to be aware of following,

1) /etc/defaults/grub -> it is the primary configuration file for GRUB2 bootloader
2) /etc/grub.d/”scripts” -> number of scripts which executes in order based on their numeric value
3) /boot/grub/grub.cfg -> which is automatically generated based on execution of /etc/defaults/grub and /etc/grub.d/”scripts”

if you are not aware of such, click here

In my case I installed a new OS at seperate partition, and need to add it with my GRUB2. And my laptop is already dual bootable which holds Windows 7 and Linux earlier.

Using fdisk, I may share you my hard disk partition.

$ sudo fdisk -l


Disk /dev/sda: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0xe175b05b

Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 7 HPFS/NTFS
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 7715 61760512 7 HPFS/NTFS
/dev/sda3 7715 26167 148212736 5 Extended
/dev/sda4 26167 38914 102391808 83 Linux
/dev/sda5 9044 22160 105355264 7 HPFS/NTFS
/dev/sda6 22160 26167 32183296 7 HPFS/NTFS
/dev/sda7 7715 9044 10671104 83 Linux

Partition table entries are not in disk order

GRUB2 is available at

$ sudo grub-probe -t device /boot/grub


/dev/sda4
patition..

My task is to add new OS at /dev/sda7 partition with GRUB2, here we go

1) I created a script /etc/grub.d/30_otherLFS

#!/bin/sh
exec tail -n +3 $0

# My LFS
# on /dev/sda7

menuentry “LinuxFromScratch” {
insmod ext2
set root=(hd0,7)
linux /boot/vmlinuz-3.7.9-lfs-7.3-rc1 root=/dev/sda7 ro
}

Reason behind naming as “30_otherLFS”

I need to make it run at position 3, so that it may also get an entry inside my /boot/grub/grub.cfg

Keep in mind,

After modifying anything, we need to run so that it may updated at grub.cfg file

$ sudo update-grub

Generating grub.cfg …

Found background image: boss-grub.png
Found linux image: /boot/vmlinuz-3.7.9-audhil -> my new kernel is updated inside grub.cfg
Found linux image: /boot/vmlinuz-3.7.8-pimpi3
Found initrd image: /boot/initrd.img-3.7.8-pimpi3
Found linux image: /boot/vmlinuz-3.7.8-pimpi3.old
Found initrd image: /boot/initrd.img-3.7.8-pimpi3
Found linux image: /boot/vmlinuz-2.6.39-bpo.2-686-pae
Found initrd image: /boot/initrd.img-2.6.39-bpo.2-686-pae
Found linux image: /boot/vmlinuz-2.6.32-5-686
Found initrd image: /boot/initrd.img-2.6.32-5-686
done

You can note entry of new OS inside grub.cfg file as follows

### BEGIN /etc/grub.d/30_otherLFS ###

# My LFS
# on /dev/sda7

menuentry “LinuxFromScratch” {
insmod ext2
set root=(hd0,7)
linux /boot/vmlinuz-3.7.9-lfs-7.3-rc1 root=/dev/sda7 ro
}
### END /etc/grub.d/30_otherLFS ###

Presence of,

1) vmlinuz-3.7.9-lfs-7.3-rc1 -> image of respective kernel
2) config-3.7.9 -> configuration file of respective kernel for future reference is important

so be sure of copying these two files from your new kernel inside /boot directory of /dev/sda4 partition where GRUB2 is actually available.

You may do this in other way also, if so please share.

After rebooting you may press shift button for some time, then you may see the menu window of GRUB2 bootloader and you can choose which OS you need to boot…Have Fun….

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s