Specifically a soft Raid 1 array on ubuntu 11.10. This guide is not for raiding your boot/main drive, but rather an extra ‘data’ array.
First thing you will need is a computer/server with 2+ drives (that you don’t mind loosing the data on), the Raid mirror will end up being the smallest of the two. You may use/mix advanced format 4KB drives, but I’ll get to that later.
A note before you begin, initialising a new array will take along time (6 hours for a 2TB array of 2 drives, minimum), so plan to leave your server alone while it does that.
Firstly install mdadm
sudo aptitude install mdadm
You will then be able to
cat /proc/mdstat to verify its working
Next up is to find and prepare your drives. You can use
ls /dev/sd* or
lsblk to get the list of current drives. In my case this was
mdadm uses partitions of type ‘Linux RAID Autodetect’ to build array from, so we now need to create these partitions on our drives. For examples sake we’ll use fdisk here.
sudo fdisk /dev/sdb
If you have any existing partitions (use
p to list) clear them with
Then create the new partition with
n, use the defaults to create the maximum size.
Set the type with
t and set it to ‘fd’ which is ‘Linux RAID Autodetect’ (formatting the new partition is not neccessary at this point).
w to write the changes to disk and
q to exit.
Rinse and repeat for the other drive.
Advanced Format: You can spot advanced format drives by printing the list of partitions a checking the physical sector size, Eg. an AF drive:
Sector size (logical/physical): 512 bytes / 4096 bytes
And a non-AF drive:
Sector size (logical/physical): 512 bytes / 512 bytes
In the above case fdisk will warn you about the logical sector size not matching the physical size when you run it, but fear not, its fine.
If you are mixing AF drives and non-AF drives put the AF drives first in the list when creating the array, this will cause mdadm to use 4KB sector sizes rather than 512B, in my setup /dev/sdc is the AF drive.
Create the array with
sudo mdadm --create /dev/md0 --level=1 --raid-disks=2 /dev/sdc /dev/sdb
You may name it something other than
md0, although it is good practice to use
X is a number.
Doing a cat
/proc/mdstat will show something like
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10] md0 : active raid1 sdb1 sdc1 1953512400 blocks super 1.2 [2/2] [UU] [>.............] resync = 0.1% (65245/1953512400) finish=612.2min speed=65748K/sec unused devices: <none>
Now’s the best time to leave it overnight to finish setting it up. Since I did notice the speed drop to almost nothing when mounted. You may format the drive now (to check that it doesn’t throw any warnings, see the next section).
[…Some time later…]
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10] md0 : active raid1 sdb1 sdc1 1953512400 blocks super 1.2 [2/2] [UU] unused devices: <none>
Done and ready to use
Formatting and using
We’ll use ext4 here, but feel free to use your favourite.
sudo mkfs.ext4 /dev/md0
That should give no warnings, however if it does complain about the offset you could try and stop the array (
mdadm --stop /dev/md0) and create the partitions again but set the display to sectors (with u twice) and create the partitions with the first sector being 2048.
Now for mounting, add the following line to
/etc/fstab and create the directory
/mnt/data (or use any other location)
/dev/md0 /mnt/data ext4 errors=remount-ro 0 2
Filesystem Size Used Avail Use% Mounted on /dev/mapper/root 228G 6.7G 210G 4% / udev 868M 8.0K 868M 1% /dev tmpfs 351M 1.2M 350M 1% /run none 5.0M 0 5.0M 0% /run/lock none 877M 0 877M 0% /run/shm /dev/sda1 228M 67M 149M 32% /boot /dev/md0 1.8T 319G 1.4T 19% /mnt/data
I hope this helps, but let me know if you ran into any problems and if you got around it so I can update this for the next person going Raid.