User Tools

Site Tools


ubuntu-raid1-conversion

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
ubuntu-raid1-conversion [2009/10/29 15:21] snargubuntu-raid1-conversion [2009/10/30 17:46] (current) snarg
Line 1: Line 1:
 =====Converting a single disk Ubuntu system to RAID1 (adding a second disk)===== =====Converting a single disk Ubuntu system to RAID1 (adding a second disk)=====
 ===Created for Phil, using Ubuntu 9.10 Karmic Koala=== ===Created for Phil, using Ubuntu 9.10 Karmic Koala===
-This Procedure will take a standard install of Ubuntu, and mirror it to a spare hard disk, forming a RAID-1 array. Ubuntu by default on a standard install has 2 partitions. One for the root (/) filesystem and one for swap space. This procedure sets up individual raid arrays for each of these (root filesystem and swap). This procedure makes heavy use of the linux shell (terminal). In Ubuntu you can load a terminal from the Applications menu, under Accessories.  Insert diagram of old versus new setup here..+This Procedure will take a standard install of Ubuntu, and mirror it to a spare hard disk, forming a RAID-1 array. Ubuntu by default on a standard install has 2 partitions. One for the root (/) filesystem and one for swap space. This procedure sets up individual raid arrays for each of these (root filesystem and swap). This procedure makes heavy use of the linux shell (terminal). In Ubuntu you can load a terminal from the Applications menu, under Accessories.  
 +\\ 
 +\\ 
 + 
 +{{:ubuntu-raid1-conversion-before-and-after.png|}}
  
 ==1. Determine device names to be used in the procedure.== ==1. Determine device names to be used in the procedure.==
Line 20: Line 24:
 Command (m for help): p Command (m for help): p
  
-Disk /dev/sdb: 500.1 GB, 500107862016 bytes +Disk /dev/sdb: 40.1 GB, 40020664320 bytes 
-255 heads, 63 sectors/track, 60801 cylinders+255 heads, 63 sectors/track, 4865 cylinders
 Units = cylinders of 16065 * 512 = 8225280 bytes Units = cylinders of 16065 * 512 = 8225280 bytes
 Disk identifier: 0xeea1cf79 Disk identifier: 0xeea1cf79
Line 132: Line 136:
 Note the "missing" keyword. This tells mdadm to start the array, even though it only has one device (aka "degraded"). The "-l 1" sets it to RAID level 1 (mirroring) and the "-n 2" tells it there will be 2 devices in the array. The devices are "/dev/sdb2" and "missing". Note the "missing" keyword. This tells mdadm to start the array, even though it only has one device (aka "degraded"). The "-l 1" sets it to RAID level 1 (mirroring) and the "-n 2" tells it there will be 2 devices in the array. The devices are "/dev/sdb2" and "missing".
  
-==6. Update RAID config file (mdadm.conf) and create new initramfs.==+==6. Update RAID UUIDs in config file (mdadm.conf) and create new initramfs.==
 In this step we will edit the RAID config file to tell it in the bootup procedure that it needs to assemble a software raid array. First we need to find the UUIDs (unique identifier IDs) of the raid arrays.  In this step we will edit the RAID config file to tell it in the bootup procedure that it needs to assemble a software raid array. First we need to find the UUIDs (unique identifier IDs) of the raid arrays. 
 <code> <code>
Line 201: Line 205:
 You should see a verbose display of files (thats what the -v is) copied. Wait for this to finish. You should see a verbose display of files (thats what the -v is) copied. Wait for this to finish.
  
-==11. Adjust UUIDs in /etc/fstab to point to the new arrays==+==11. Adjust filesystem UUIDs in /etc/fstab to point to the new arrays==
 We now need to edit the linux file system table (fstab) in the NEW filesystem on the RAID array, so that when the system boots up, it will be mounting the RAID array (/dev/md0) and not the first hard disk (/dev/sda1) as the root filesystem (/). We now need to edit the linux file system table (fstab) in the NEW filesystem on the RAID array, so that when the system boots up, it will be mounting the RAID array (/dev/md0) and not the first hard disk (/dev/sda1) as the root filesystem (/).
    
Line 210: Line 214:
 </code> </code>
 Now go back to the original terminal window and type: Now go back to the original terminal window and type:
 +<code>
 sudo nano /mnt/temp-newroot/etc/fstab sudo nano /mnt/temp-newroot/etc/fstab
 </code> </code>
Line 225: Line 230:
 Use CTRL+W to save the fstab and exit nano text file editor. Use CTRL+W to save the fstab and exit nano text file editor.
  
-==12. Adjust UUID in /boot/grub/menu.lst to point to the new arrays==+==12. Adjust UUID in /boot/grub/menu.lst to point to the new root array==
 This step will cause the bootloader to load up using the raid array (/dev/md0) instead of the old drive (/dev/sda1). This change is only temporary, as we are editting the file on the OLD root partition. We will fix this to be permanent once we reboot into the new system. This step will cause the bootloader to load up using the raid array (/dev/md0) instead of the old drive (/dev/sda1). This change is only temporary, as we are editting the file on the OLD root partition. We will fix this to be permanent once we reboot into the new system.
 <code> <code>
Line 264: Line 269:
  
 ==14. Change partition type labels on first drive to "linux raid autodetect"== ==14. Change partition type labels on first drive to "linux raid autodetect"==
 +Almost There! Now that we are successfully booted up using the new array, we need to convert the old disk (/dev/sda) to become part of the RAID1 arrays, making them redundant. First of all, use fdisk to change the partition types to "Linux raid autodetect"
 +<code>
 +sudo fdisk /dev/sda
 +</code>
 +Using the fdisk commands (which should be familiar by now), change the partition types labels, then save and exit:
 +<code>
 +Command (m for help): t
 +Partition number (1-5): 1
 +Hex code (type L to list codes): fd
 +Changed system type of partition 1 to fd (Linux raid autodetect)
 +
 +Command (m for help): t
 +Partition number (1-5): 5
 +Hex code (type L to list codes): fd
 +Changed system type of partition 5 to fd (Linux raid autodetect)
 +
 +Command (m for help): p
 +
 +Disk /dev/sda: 40.0 GB, 40020664320 bytes
 +255 heads, 63 sectors/track, 4865 cylinders
 +Units = cylinders of 16065 * 512 = 8225280 bytes
 +Disk identifier: 0xdcf4dcf4
 +
 +   Device Boot      Start         End      Blocks   Id  System
 +/dev/sda1                    4679    37584036   fd  Linux raid autodetect
 +/dev/sda2            4680        4865     1494045    5  Extended
 +/dev/sda5            4680        4865     1494013+  fd  Linux raid autodetect
 +
 +Command (m for help): w
 +The partition table has been altered!
 +
 +Calling ioctl() to re-read partition table.
 +
 +WARNING: Re-reading the partition table failed with error 16: Device or resource
 + busy.
 +The kernel still uses the old table. The new table will be used at
 +the next reboot or after you run partprobe(8) or kpartx(8)
 +Syncing disks.
 +</code>
 ==15. Add old drive root partition to the new root array - making it redundant.== ==15. Add old drive root partition to the new root array - making it redundant.==
 +This is a one-liner:
 +<code>
 +sudo mdadm --manage /dev/md0 --add /dev/sda1
 +</code>
 ==16. Add the second member (first drive) of the swap array, making it redundant.== ==16. Add the second member (first drive) of the swap array, making it redundant.==
-==17. Watch some rebuild stats. - all done.==+Also a one-liner: 
 +<code> 
 +sudo mdadm --manage /dev/md1 --add /dev/sda5 
 +</code> 
 +==17. Watch some rebuild stats. Dont forget the important last step.==
  
 +Type "cat /proc/mdstat"  to get an idea of how the resync of both RAID-1 arrays is going. You can run this command as many times as you like, to monitor the progress. At the end of the resync, both arrays should show "[UU]" instead of "[U_]"
 +
 +<code>
 +$ cat /proc/mdstat 
 +Personalities : [raid1] [linear] [multipath] [raid0] [raid6] [raid5] [raid4] [raid10] 
 +md1 : active raid1 sda5[2] sdb5[0]
 +      1493888 blocks [2/1] [U_]
 +        resync=DELAYED
 +      
 +md0 : active raid1 sda1[2] sdb1[0]
 +      37583936 blocks [2/1] [U_]
 +      [>....................]  recovery =  1.1% (415488/37583936) finish=35.7min speed=17312K/sec
 +      
 +unused devices: <none>
 +</code>
 +
 +==18. Final update to the bootloader to account for the first drive being changed.==
 +Use nano to edit your /boot/grub/device.map
 +<code>
 +sudo nano /boot/grub/device.map
 +</code>
 +And make sure it looks like this: (note this should be the same as your bios hard disk boot order)
 +<code>
 +(hd0)   /dev/sda
 +(hd1)   /dev/sdb
 +</code>
 +Type this to finalise the bootloader config and Master Boot Record on both hard disks:
 +<code>
 +sudo update-grub
 +sudo grub-install /dev/sda
 +sudo grub-install /dev/sdb
 +</code>
 +\\
 +ALL DONE!!
 +\\
 +update- 20091030 - Please note that at time of writing there is a bug in GRUB 1.97 which causes a boot delay of about 10-20 seconds for boot partitions on RAID-1. This is a known problem and is being worked on. Please see: [[https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/396564]]
ubuntu-raid1-conversion.1256800892.txt.gz · Last modified: 2009/10/29 15:21 by snarg