GRUB legacy

GRUB legacy is the predecessor of GRUB2, recently I have been doing backups of a HDD and need to transfer the contents into a new HDD. The previous HDD was using CentOS 6.2, CentOS is using grub 0.97 which is grub legacy.

http://pkgs.org/centos-6-rhel-6/centos-rhel-i386/grub-0.97-75.el6.i686.rpm.html gives insights on where the files are if the location is at its default states.

Here I will document how to install grub into MBR using chroot.

Mount the hard disk

you need a liveCD. After you have booted with the liveCD do the below, this example has three partitions.

/dev/sda1 / ext4

/dev/sda2 swap

/dev/sda3 /home ext4

mount /dev/sda1 /mnt/

mount /dev/sda3 /mnt/home/

Mount proc and bind the mounted hdd to /dev

mount -t proc none /mnt/proc

mount -o bind /dev /mnt/dev/

Change root from / to /mnt/

chroot /mnt /bin/bash

This will transfer from “/” to the root mounted on /mnt/, now you can execute bash commands on the mounted harddisk just like it is loaded on your system, whichever you changed will be updated and stored in the mounted hard disk.

Run GRUB

As from http://pkgs.org/centos-6-rhel-6/centos-rhel-i386/grub-0.97-75.el6.i686.rpm.html, the default path for grub is in /sbin/.

/sbin/grub

grub> prompt appears.

find /boot/grub/stage1, this step is optional, executing this command will output the partition where the vmlinuz and initrd files are located.

Since /dev/sda1 is the / directory, /root/ is under / as well as there are no additional partition for /root.

/dev/sdXY = hdX,Y, where X is the harddrive number and Y is the partition number for /dev/sda1 the equivalent is hence hd0,0. 0 is the first number of the harddisk and partition.

root (hd0,0)

setup (hd0)

quit

This installs the grub into MBR.

Kernel panic!

My system encountered kernel panic and stopped. This is because the previously backup grub.conf file points to UUID and the UUID does not exist.

My way of doing it is to remove the UUID and statically define the partition like this:

kernel /boot/vmlinuz-version root=/dev/sda1 ro

UUID is a dynamic way to figure out which partition is which, however it gives problem in my situation. So the kernel line in the grub.conf may look like this:

kernel /boot/vmlinuz-2.6.38-8-generic root=UUID=c2bb0352-8fa3-457a-8bcd-00a35a2783fc ro

To check your partitions’ UUID do this:

blkid

For my situation the UUIDs presented by blkid command were all different from UUIDs in /etc/fstab as well as in grub.conf.

Note that /boot/grub/menu.lst is a symbolic link of /boot/grub/grub.conf, changing grub.conf also changes menu.lst.

Advertisements
This entry was posted in Linux, System OS and tagged , , , , . Bookmark the permalink.

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