« Setting up a Professional Quality Mail Server with Ubuntu Karmic Server 9.10.HOWTO: Setup apt-cacher, caching service for installation packages »

HOWTO: Convert from single disk to RAID 1 without reinstalling

30/12/08

HOWTO: Convert from single disk to RAID 1 without reinstalling

You should see the new menu, the one that talks about RAID :)

Select the first menu option and if all went well your system will come up using the RAID1 array. You will also see that you have a file called /this_is_mirror. If you have a file called /this_is_sda1 then you have done something wrong. You missed a step or didn't do the steps in the right order.

Once you are sure you have the RAID array working, and all is well. You need to delete the old partitions on /dev/sda and make them the same as they are on /dev/sdb. You can copy the partition info from the new disk to the old disk. You will need to umount /dev/sda1 if you have remounted it after the reboot.

Use fdisk to delete the old partitions before copying the new partition table over. Remember it is /dev/sda that you need to do the deletions on.

sudo fdisk /dev/sda
Command (m for help): p 
 
Disk /dev/sda: 4294 MB, 4294967296 bytes 
255 heads, 63 sectors/track, 522 cylinders 
Units = cylinders of 16065 * 512 = 8225280 bytes 
Disk identifier: 0x000df6a9 
 
   Device Boot      Start         End      Blocks   Id  System 
/dev/sda1   *           1         486     3903763+  83  Linux 
/dev/sda2             487         522      289170   82  Linux swap / Solaris 
 
Command (m for help): d 
Partition number (1-4): 2 
 
Command (m for help): d 
Partition number (1-4): 1 
 
Command (m for help): p 
 
Disk /dev/sda: 4294 MB, 4294967296 bytes 
255 heads, 63 sectors/track, 522 cylinders 
Units = cylinders of 16065 * 512 = 8225280 bytes 
Disk identifier: 0x000df6a9 
 
Device Boot      Start         End      Blocks   Id  System 

You may need to reboot here depending on what you have mounted. Once the system comes back up you can copy the partition table over.

sudo -i 
sfdisk -d /dev/sdb | sfdisk /dev/sda 
exit 
Checking that no-one is using this disk right now ... 
OK 
 
Disk /dev/sda: 522 cylinders, 255 heads, 63 sectors/track 
Old situation: 
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0 
 
   Device Boot Start     End   #cyls    #blocks   Id  System 
/dev/sda1          0       -       0          0    0  Empty 
/dev/sda2          0       -       0          0    0  Empty 
/dev/sda3          0       -       0          0    0  Empty 
/dev/sda4          0       -       0          0    0  Empty 
New situation: 
Units = sectors of 512 bytes, counting from 0 
 
   Device Boot    Start       End   #sectors  Id  System 
/dev/sda1            63   8209214    8209152  fd  Linux RAID autodetect 
/dev/sda2       8209215   8385929     176715  fd  Linux RAID autodetect 
/dev/sda3             0         -          0   0  Empty 
/dev/sda4             0         -          0   0  Empty 
Warning: no primary partition is marked bootable (active) 
This does not matter for LILO, but the DOS MBR will not boot this disk. 
Successfully wrote the new partition table 
 
Re-reading the partition table ... 
 
If you created or changed a DOS partition, /dev/foo7, say, then use dd(1) 
to zero the first 512 bytes:  dd if=/dev/zero of=/dev/foo7 bs=512 count=1 
(See fdisk(8).) 

add the drive /dev/sda to both of the arrays (md0 & md1) and allow them to to sync. You can watch this process with the command in a second terminal. Do not reboot until the resync has finished for both arrays and you see [UU] in the output from /proc/mdstat for both.

watch -n 7 cat /proc/mdstat
sudo mdadm --add /dev/md0 /dev/sda1 
sudo mdadm --add /dev/md1 /dev/sda2 
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]  
md1 : active raid1 sda2[2] sdb2[1] 
      88256 blocks [2/1] [_U] 
        resync=DELAYED 
 
md0 : active raid1 sda1[2] sdb1[1] 
      4104512 blocks [2/1] [_U] 
      [===>.................]  recovery = 19.6% (806976/4104512) finish=1.4min speed=36680K/sec 
 
unused devices: <none> 

On a real system this can take hours ~1 hour/250Gb. On VMware with a tiny disk it takes a few minutes. Time for another coffee ;o

We now have a working RAID 1 system where if one disk fails we can still carry on working. We need to make it so we can still boot from either drive when the other has failed. This is repeating some of what we have already setup but it means you can see it is done.

We will be setting the MBR:

on the first hard disk /dev/sda or in grub terms (hd0), to look in the first partition on the first drive for the /boot directory. (hd0,0) in grub speak.
and on the second hard disk /dev/sdb or in grub terms (hd1), to look in the first partition on the second drive for the /boot directory, which is (hd1,0) for grub. Look at the output below for the setup commands.

The commands I used were

sudo grub 
root (hd0,0) 
setup (hd0) 
root (hd1,0) 
setup (hd1) 
quit 
grub> root (hd0,0) 
 
grub> setup (hd0) 
 Checking if "/boot/grub/stage1" exists... yes 
 Checking if "/boot/grub/stage2" exists... yes 
 Checking if "/boot/grub/reiserfs_stage1_5" exists... yes 
 Running "embed /boot/grub/reiserfs_stage1_5 (hd0)"...  20 sectors are embedded. 
succeeded 
 Running "install /boot/grub/stage1 (hd0) (hd0)1+20 p (hd0,0)/boot/grub/stage2 /boot/grub/menu.lst" 
... succeeded 
Done. 
 
grub> root (hd1,0) 
 
grub> setup (hd1) 
 Checking if "/boot/grub/stage1" exists... yes 
 Checking if "/boot/grub/stage2" exists... yes 
 Checking if "/boot/grub/reiserfs_stage1_5" exists... yes 
 Running "embed /boot/grub/reiserfs_stage1_5 (hd1)"...  20 sectors are embedded. 
succeeded 
 Running "install /boot/grub/stage1 (hd1) (hd1)1+20 p (hd1,0)/boot/grub/stage2 /boot/grub/menu.lst" 
... succeeded 
Done.

Do not forget to update the BIOS, so that it will try one of the two disks and if that fails try booting from the other disk.


Pages: 1 · 2 · 3 · 4 · 5 · 6 · 7

No feedback yet

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
PoorExcellent
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)
What can birds and aeroplanes both do?
antispam test