2012-06-14 09:02 UTC
Getting software RAID running under Debian using mdadm is quite easy. First we have to make sure we have mdadm installed.
# apt-get install mdadm
Then we have to prepare the disks to use. All the disks that are members of the RAID must have a partition for RAID use. I strongly advise to use the one-disk-one-partition approach. If you later on need multiple partitions you can create them on the assembled RAID device. I'm going to create a mirrored pair of disks. I think this is most common situation, especially for home use. Let's say we have two disks; /dev/sda and /dev/sdb. Create a partition on each using all available disk space that looks like this.
# fdisk -l /dev/sda
Disk /dev/sda: 2000.4 GB, 2000398934016 bytes
81 heads, 63 sectors/track, 765633 cylinders
Units = cylinders of 5103 * 512 = 2612736 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x42e81cd4
Device Boot Start End Blocks Id System
/dev/sda1 1 765634 1953513560 fd Linux raid autodetect
The partition ID can be set to 0xfd to indicate Linux RAID but I discovered that the ID you set during partitioning does not matter. Mdadm will set it to 0xfd anyway when the array is created.
After both drives are partitioned as above it is time to enable mdadm. It's all done using a single command.
# mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda1 /dev/sdb1
This will tell mdadm to create a new mirrored (--level=1) RAID device (/dev/md0) using the two disks given. The array creation process will begin immediately. The mdadmin status is reached by looking in /proc/mdstat.
# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sda1[0] sdb1[1]
1953512400 blocks super 1.2 [2/2] [UU]
[>....................] resync = 1.4% (27963520/1953382336) finish=694.1min speed=41967K/sec
unused devices: <none>
When rebuilding is complete the mdadm status will look like this.
# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sda1[0] sdb1[1]
1953512400 blocks super 1.2 [2/2] [UU]
unused devices: <none>
"[UU]" indicates that the two drives are up and running. If this changes to for example "[_U]" then one drive has failed! The device /dev/md0 can be accessed as a normal disk and partitioned as needed. It is even possible to create a file system directly onto an md-device.
# mkfs.ext4 /dev/md0
# e2label /dev/md0 my-new-raid
# mount /dev/md0 /data
To make sure the mdadm daemon runs correctly and that the kernel is informed about the array UUID we should also generate an appropriate config file. This step is not absolutely mandatory since the kernel will autodetect all arrays on boot but it makes sure that the arrays get the same device path on every boot.
# /usr/share/mdadm/mkconf > /etc/mdadm/mdadm.conf
# update-initramfs
Write a comment