ubuntu-raid1-conversion
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
ubuntu-raid1-conversion [2009/10/29 10:55] – snarg | ubuntu-raid1-conversion [2009/10/30 17:39] – 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. | + | 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. |
+ | \\ | ||
+ | \\ | ||
+ | |||
+ | {{: | ||
==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 / | + | Disk / |
- | 255 heads, 63 sectors/ | + | 255 heads, 63 sectors/ |
Units = cylinders of 16065 * 512 = 8225280 bytes | Units = cylinders of 16065 * 512 = 8225280 bytes | ||
Disk identifier: 0xeea1cf79 | Disk identifier: 0xeea1cf79 | ||
Line 84: | Line 88: | ||
Using default value 4865 | Using default value 4865 | ||
</ | </ | ||
- | If you like, now use the p command to see what you've set up. The start and End and Blocks should be identical to the first drive. We will now use the " | + | If you like, now use the p command to see what you've set up. The start and End and Blocks should be identical to the first drive. We will now use the " |
< | < | ||
Command (m for help): t | Command (m for help): t | ||
Partition number (1-5): 1 | Partition number (1-5): 1 | ||
- | Hex code (type L to list codes): | + | Hex code (type L to list codes): |
Command (m for help): t | Command (m for help): t | ||
Partition number (1-5): 5 | Partition number (1-5): 5 | ||
- | Hex code (type L to list codes): | + | Hex code (type L to list codes): |
Changed system type of partition 5 to 82 (Linux swap / Solaris) | Changed system type of partition 5 to 82 (Linux swap / Solaris) | ||
Line 108: | Line 112: | ||
| | ||
- | / | + | / |
/ | / | ||
- | / | + | / |
</ | </ | ||
Finally, use the " | Finally, use the " | ||
Line 130: | Line 134: | ||
sudo mdadm --create /dev/md1 -l 1 -n 2 /dev/sdb5 missing | sudo mdadm --create /dev/md1 -l 1 -n 2 /dev/sdb5 missing | ||
</ | </ | ||
- | Note the " | + | Note the " |
- | ==6. Format the new arrays== | + | ==6. Update RAID UUIDs in config file (mdadm.conf) and create |
- | ==7. Deactivate old swap, Activate new RAID-1 swap== | + | In this step we will edit the RAID config file to tell it in the bootup procedure that it needs to assemble a software |
- | ==8. Change partition type labels on first drive to " | + | < |
- | ==9. Add the second member | + | sudo mdadm --query --detail /dev/md0 | grep UUID |
- | ==10. Mount the new root array to a mountpoint== | + | </ |
- | ==11. Bind-mount the old partition to a mountpoint== | + | Repeat for /dev/md1: |
- | ==12. Copy the data from old root partition to new root array.== | + | < |
- | ==13. Adjust UUIDs in /etc/fstab to point to the new arrays== | + | sudo mdadm --query --detail /dev/md1 | grep UUID |
- | ==14. Adjust | + | </ |
- | ==15. Reboot into new root array.== | + | Open a new terminal window and type the following: |
- | ==16. Add old drive root partition to the new root array - making it redundant.== | + | < |
- | ==17. Watch some rebuild stats. - all done.== | + | sudo nano /etc/mdadm/ |
+ | </ | ||
+ | Nano is a simple text editor. Navigate down to the comment "# | ||
+ | < | ||
+ | # definitions of existing MD arrays | ||
+ | ARRAY /dev/md0 uuid=997fffd8: | ||
+ | ARRAY /dev/md1 uuid=02b854fd: | ||
+ | </ | ||
+ | Ensure that you've copy and pasted the RAID UUIDs precicely, and that you haven' | ||
+ | Press CTRL+X | ||
+ | We now run the following command | ||
+ | < | ||
+ | sudo update-initramfs -u | ||
+ | </ | ||
+ | ==7. Format the new arrays== | ||
+ | The first array (/dev/md0) will be formatted as ext4 filesystem, and the second | ||
+ | < | ||
+ | sudo mkfs.ext4 /dev/md0 | ||
+ | sudo tune2fs | ||
+ | sudo mkswap /dev/md1 | ||
+ | </ | ||
+ | The tune2fs command sets a couple of parameters on the filesystem (turns off " | ||
+ | ==8. Mount the new root array to a mountpoint== | ||
+ | We now need to mount the newly created ext4 filesystem in /dev/md0 to a mountpoint (which means we first need to make a mountpoint). A mountpoint is a location in which a filesystem is attached, very similar to the "drive letter" | ||
+ | < | ||
+ | cd /mnt | ||
+ | sudo mkdir temp-newroot | ||
+ | sudo mount /dev/md0 temp-newroot | ||
+ | </ | ||
+ | Type "df -h" to see the disk space free, confirming the array is mounted correctly, as per the following example: | ||
+ | < | ||
+ | /mnt$ df -h | ||
+ | Filesystem | ||
+ | / | ||
+ | udev 249M 252K 249M 1% /dev | ||
+ | none 249M 188K 249M 1% /dev/shm | ||
+ | none 249M 112K 249M 1% /var/run | ||
+ | none 249M | ||
+ | none 249M | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | ==9. Bind-mount the old partition to a mountpoint== | ||
+ | To help in the copy process (so we dont have recursive directories) we are going to bind-mount the current root filesystem to a new mountpoint, which we will first make. This step assumes we are still working in the /mnt directory (we changed to it in the prevous step). | ||
+ | < | ||
+ | sudo mkdir temp-oldroot | ||
+ | sudo mount -o bind / temp-oldroot | ||
+ | </ | ||
+ | You can confirm this has worked by typing "ls / | ||
+ | |||
+ | ==10. Copy the data from old root partition to new root array.== | ||
+ | Here's the command to copy data from the old (current) root filesystem to the new empty root filesystem on the RAID-1 array (/dev/md0). This assumes our current working directory is still /mnt. You probably want to close any open programs as much as possible before you copy all the files. | ||
+ | < | ||
+ | sudo cp -d -p -R -v temp-oldroot/ | ||
+ | </ | ||
+ | You should see a verbose display of files (thats what the -v is) copied. Wait for this to finish. | ||
+ | |||
+ | ==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 (/). | ||
+ | |||
+ | First, open a new terminal window, and use the following commands to find the UUID (universally unique identifier) values for the new root filesystem (/dev/md0) and the new swap area (/dev/md1): | ||
+ | < | ||
+ | sudo blkid /dev/md0 | ||
+ | sudo blkid /dev/md1 | ||
+ | </ | ||
+ | Now go back to the original terminal window and type: | ||
+ | < | ||
+ | sudo nano / | ||
+ | </ | ||
+ | Navigate down to the first " | ||
+ | < | ||
+ | UUID=470118f4-59ec-466a-b8d4-ed46345b1aae / | ||
+ | </ | ||
+ | Now. Edit this line so that the UUID points to the UUID of the new RAID array, by doing the following: | ||
+ | * Backspace the UUID all the way back to the equals sign | ||
+ | * Go to the terminal window where you ran the blkid commands. | ||
+ | * Highlight and copy the UUID value for the /dev/md0 array to the clipboard | ||
+ | * Back to the fstab terminal, and paste the UUID. | ||
+ | * Confirm it's the right number of characters, and that you didnt' accidentally miss one. | ||
+ | * **Repeat these steps for the new swap array (/ | ||
+ | Use CTRL+W to save the fstab and exit nano text file editor. | ||
+ | |||
+ | ==12. Adjust UUID in / | ||
+ | This step will cause the bootloader to load up using the raid array (/dev/md0) instead of the old drive (/ | ||
+ | < | ||
+ | sudo nano / | ||
+ | </ | ||
+ | Look for the section that refers to the first boot menu entry. You're looking for a couple of lines that look like this: | ||
+ | < | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | Replace the both the UUID's on those lines with the UUID for /dev/md0, as descovered in the previous steps, then save the file and exit with CTRL+X | ||
+ | |||
+ | ==13. Unmount filesystems, | ||
+ | We are now ready to unmount the new filesystem and reboot into it. Run this: | ||
+ | < | ||
+ | sudo umount / | ||
+ | sudo umount / | ||
+ | sudo reboot | ||
+ | </ | ||
+ | Which should, if you've done everything correctly, reboot into the new system. | ||
+ | Once booted, confirm you're running from the new RAID-1 array (/dev/md0) by going to a terminal and typing "df -h" and noting the root filesystem line should be pointing at /dev/md0: | ||
+ | < | ||
+ | ~$ df -h | ||
+ | Filesystem | ||
+ | / | ||
+ | udev 249M 252K 249M 1% /dev | ||
+ | none 249M 136K 249M 1% /dev/shm | ||
+ | none 249M 116K 249M 1% /var/run | ||
+ | none 249M | ||
+ | none 249M | ||
+ | </ | ||
+ | < | ||
+ | By typing "cat / | ||
+ | ~$ cat /proc/swaps | ||
+ | Filename | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | ==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" | ||
+ | < | ||
+ | sudo fdisk /dev/sda | ||
+ | </ | ||
+ | Using the fdisk commands (which should be familiar by now), change the partition types labels, then save and exit: | ||
+ | < | ||
+ | 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/ | ||
+ | Units = cylinders of 16065 * 512 = 8225280 bytes | ||
+ | Disk identifier: 0xdcf4dcf4 | ||
+ | |||
+ | | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | |||
+ | 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. | ||
+ | </ | ||
+ | ==15. Add old drive root partition to the new root array - making it redundant.== | ||
+ | This is a one-liner: | ||
+ | < | ||
+ | sudo mdadm --manage /dev/md0 --add /dev/sda1 | ||
+ | </ | ||
+ | ==16. Add the second member (first drive) of the swap array, making it redundant.== | ||
+ | Also a one-liner: | ||
+ | < | ||
+ | sudo mdadm --manage /dev/md1 --add /dev/sda5 | ||
+ | </ | ||
+ | ==17. Watch some rebuild stats. Dont forget the important last step.== | ||
+ | |||
+ | Type "cat / | ||
+ | |||
+ | < | ||
+ | $ cat / | ||
+ | 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_] | ||
+ | [> | ||
+ | | ||
+ | unused devices: < | ||
+ | </ | ||
+ | |||
+ | ==18. Final update to the bootloader to account for the first drive being changed.== | ||
+ | Type this to finalise the bootloader config and Master Boot Record on both hard disks: | ||
+ | < | ||
+ | sudo update-grub | ||
+ | sudo grub-install /dev/sda | ||
+ | sudo grub-install /dev/sdb | ||
+ | </ | ||
+ | \\ | ||
+ | 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:// |
ubuntu-raid1-conversion.txt · Last modified: 2009/10/30 17:46 by snarg