Creating extra storage in Software RAID 1 to an existing install

One day you decide to have a Desktop with a single HD. The next day it crashes and you loose a lot of data (you should have taken backups). Adding some extra reliability is adding Software RAID. In this example I will create a RAID1 device with 2 * 1 TB disks The program you will need is mdadm. As I am using ubuntu I will be using aptitude as a package manager. dimi@belhamel:~$ sudo aptitude install mdadm Next you will have to create partitions on your device, which we will do using fdisk. (you could use gparted or whatever). First of all find out which disks you will use: dimi@belhamel:~$ cat /proc/partitions major minor #blocks name 8 0 488386584 sda 8 1 292937211 sda1 8 2 102400 sda2 8 3 195345408 sda3 8 32 976762584 sdc 8 16 976762584 sdb You can see /dev/sdc and /dev/sdb seem to have no partitions and have a size of approx 1TB. We will now make sure the disk is recognised as a RAID disk: dimi@belhamel:~$ sudo fdisk /dev/sdc Below I am showing which command I did. Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0xd5b8c164. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. The number of cylinders for this disk is set to 121601. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with: 1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK) Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) Command (m for help): Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): Value out of range. Partition number (1-4): 1 First cylinder (1-121601, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-121601, default 121601): Using default value 121601 Command (m for help): t Selected partition 1 Hex code (type L to list codes): fd Changed system type of partition 1 to fd (Linux raid autodetect) Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. Now do the same for your other Disk. Create the RAID (syncing your disks) dimi@belhamel:~$ sudo mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1 Syncing the disks, took me about 4 hours. I prefer to let the disks do the work and only after create a FS. Of course you can create the FS while the disk is syncing. The following command shows you the progress of the disksync and can show you if a disk is broken. dimi@belhamel:~$ sudo watch cat /proc/mdstat To show you the config of your array. dimi@belhamel:~$ sudo mdadm --detail --scan ARRAY /dev/md0 level=raid1 num-devices=2 metadata=00.90 UUID=c0b88b02:f8c5e393:1b194400:1cc5e945 After reading some online fora I added this line to mdadm.conf dimi@belhamel:~$ sudo vi /etc/mdadm/mdadm.conf # definitions of existing MD arrays ARRAY /dev/md0 level=raid1 num-devices=2 metadata=00.90 UUID=c0b88b02:f8c5e393:1b194400:1cc5e945 Create a filesystem on your all new RAID1 array. dimi@belhamel:~$ sudo mkfs.ext4 /dev/md0 mke2fs 1.41.9 (22-Aug-2009) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 61054976 inodes, 244189984 blocks 12209499 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=0 7453 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 102400000, 214990848 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 22 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. dimi@belhamel:~$ sudo tune2fs -m 0 /dev/md0 tune2fs 1.41.9 (22-Aug-2009) Setting reserved blocks percentage to 0% (0 blocks) You created an all new software RAID. You can check disk performances with hdparm: for i in 1 2 3 4 5; do hdparm -tT /dev/md0; done I get these values: /dev/md0: Timing cached reads: 12974 MB in 2.00 seconds = 6495.58 MB/sec Timing buffered disk reads: 328 MB in 3.00 seconds = 109.29 MB/sec I hope this small howto was helpfull. For any other Distro's it should be comparable to this howto.