Posts Tagged ‘computer

06
Nov
12

Swapping Raid Disks – Part 2 Fixing /boot

In the previous part post Swapping Raid Disks – Part 1 MDADM we showed how to completely swap all disks in a Linux Software Raid array.  One of the Raid partitions we swapped was the /boot partitions.  We now need to ensure that grub is installed to these new partitions so the system can still boot once we destroy the old disks.  You can use the device map file and grub-install to do this however i will be using the grub cli.

The first thing to do is run grub and use the find command to see how grub addresses the disks with the /boot partitions.  The (hdX,X) values will more then likley be different on your system. you will also need to do this as root

[root@server ~]#grub
Probing devices to guess BIOS drives. This may take a long time.
GNU GRUB  version 0.97  (640K lower / 3072K upper memory)
[ Minimal BASH-like line editing is supported.  For the first word, TAB
lists possible command completions.  Anywhere else TAB lists the possible
completions of a device/filename.]
grub> find /grub/stage1
find /grub/stage1
(hd0,1)
(hd1,1)
(hd8,1)
(hd9,1)

From this we can see that grub can see 4 /boot partitions ((hd0,1), (hd2,1), (hd8,1) & (hd9,1)). We now need to ensure that grub is installed on all of these partitions. If you know which disks are the new disks and which are the old disks you can get away with installing grub just on the new disks but it will do know harm to install on all disks.

Installing grub requires three steps. Telling grub which device we will be working on with a map; Telling grub which partitions is the boot/root partitions and installing grub

grub> device (hd0) /dev/sda
device (hd0) /dev/sda
grub> root (hd0,1)
root (hd0,1)
 Filesystem type is ext2fs, partition type 0xfd
grub> setup (hd0)
setup (hd0)
 Checking if "/boot/grub/stage1" exists... no
 Checking if "/grub/stage1" exists... yes
 Checking if "/grub/stage2" exists... yes
 Checking if "/grub/e2fs_stage1_5" exists... yes
 Running "embed /grub/e2fs_stage1_5 (hd0)"...  26 sectors are embedded.
succeeded
 Running "install /grub/stage1 (hd0) (hd0)1+26 p (hd0,1)/grub/stage2 /grub/grub.conf"... succeeded
Done.

Here is an example of hd9 (/dev/sdj) as well

grub> device (hd9) /dev/sdj
device (hd9) /dev/sdj
grub> root (hd9,1)
root (hd9,1)
 Filesystem type is ext2fs, partition type 0xfd
grub> setup (hd9)
setup (hd9)
 Checking if "/boot/grub/stage1" exists... no
 Checking if "/grub/stage1" exists... yes
 Checking if "/grub/stage2" exists... yes
 Checking if "/grub/e2fs_stage1_5" exists... yes
 Running "embed /grub/e2fs_stage1_5 (hd9)"...  26 sectors are embedded.
succeeded
 Running "install /grub/stage1 (hd9) (hd9)1+26 p (hd9,1)/grub/stage2 /grub/grub.conf"... succeeded
Done.

you will also need fix the grub.conf/menu.1st file to ensure it specifies the correct root drive to use. In my case i know my boot partitions are on hd8 & hd9 however as above you can create entries for all hdX partitions show in the find command. Below is a copy of my modified menu file

title CentOS
	root (hd8,1)
	kernel /vmlinuz-2.6.32-220.17.1.el6.x86_64 [Removed for simplicity]
	initrd /initramfs-2.6.32-220.17.1.el6.x86_64.img
title CentOS (if the first disk in the array dies you will need to use this)
	root (hd9,1)
	kernel /vmlinuz-2.6.32-220.17.1.el6.x86_64 [Removed for simplicity]
	initrd /initramfs-2.6.32-220.17.1.el6.x86_64.img
title CentOS (backp hd0 wont work after you format the old disks)
	root (hd0,1)
	kernel /vmlinuz-2.6.32-220.17.1.el6.x86_64 [Removed for simplicity]
	initrd /initramfs-2.6.32-220.17.1.el6.x86_64.img
title CentOS (backp hd1 wont work after you format the old disks)
	root (hd1,1)
	kernel /vmlinuz-2.6.32-220.17.1.el6.x86_64 [Removed for simplicity]
	initrd /initramfs-2.6.32-220.17.1.el6.x86_64.img

If you are using a system with grub v2 you can use the search command to set the root instead of having 4 seperate menu items. CentOS dose not support grub v2 yet and i have not needed to do this on another system. however Arch linux has a good article on grub v2 which should help
At this point you should reboot and check that at least the first two menu options work and allow you to boot. If they do not the last two options should work. Review the steps you have taken to see if you have made any errors. If they come up successfully you should be able to format the original partitions and reuse them.

In my situation i wanted to keep all the data and reclaime the space at the beginning of the disk so i decided to do something crazy with dd (part 3 coming soon)