Setting up RAID1 in Debian Wheezy 7.4

I started configuring an HP ProLiant N54L microserver today and when I got to the raid array part I noticed that some of the tutorials for debian are not quite working, so I made this step by step tutorial for the others having problems out there.

Creating the RAID 1 Array Using mdadm

root@somehost # apt-get install mdadm

Step 2: Choose your RAID type

The server I`m using supports RAID0 and RAID1, but I was looking for mirroring redundancy and fault tolerance so I chose RAID1…

The following table shows some of the main differences between RAID0 and RAID1 in a nutshell:

RAID0 RAID1
Mirroring, redundancy and fault tolerance No Yes
Striping Yes, data is split evenly across all dikcs in the array No, data is fully stored on each disk
Performance Faster write speeds compared to RAID1 Same performance as RAID0 but write is slower
Applications Where speed is important Where data loss is unacceptable

Step 3: Find your hdds

root@somehost # fdisk -l

The output should be something similar to:

Disk /dev/sda: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders, total 488397168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000e7ea8

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 499711 248832 83 Linux
/dev/sda2 501758 488396799 243947521 5 Extended
/dev/sda5 501760 488396799 243947520 8e Linux LVM

Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000

Device Boot Start End Blocks Id System
/dev/sdb1 1 1953525167 976762583+ ee GPT

Disk /dev/sdc: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000

Device Boot Start End Blocks Id System
/dev/sdc1 1 1953525167 976762583+ ee GPT

The ones I’m interested in are /dev/sdb1 and /dev/sdc1

Step 4: Edit /etc/mdadm/mdadm.conf

root@somehost # vi /etc/mdadm/mdadm.conf

Add the following lines at the end of the file:

DEVICE /dev/sd[bc]1
ARRAY /dev/md0 devices=/dev/sdb1,/dev/sdc1

*Note change sdb1 and sdc1 with your drives

Step 5: Create the RAID array

 

root@somehost # mdadm -C /dev/md0 –level=raid1 -raid-devices=2 /dev/sdb1 /dev/sdc1

 

After entering the command mdadm will ask if it should continue creating the array, you should type “Yes”

Continue creating array? yes

mdadm: array /dev/md0 started.

Step 6: Query your RAID for status information

root@somehost # mdadm --detail /dev/md0

And the output should be something along the lines of:

/dev/md0:
 Version : 1.2
 Creation Time : Thu Feb 20 13:20:02 2014
 Raid Level : raid1
 Array Size : 976629568 (931.39 GiB 1000.07 GB)
 Used Dev Size : 976629568 (931.39 GiB 1000.07 GB)
 Raid Devices : 2
 Total Devices : 2
 Persistence : Superblock is persistent

Update Time : Thu Feb 20 13:20:02 2014
 State : clean, resyncing (PENDING)
 Active Devices : 2
Working Devices : 2
 Failed Devices : 0
 Spare Devices : 0

Name : hpproliant:0 (local to host hpproliant)
 UUID : 9c9c5ca2:a4b26264:5d73d487:373aa79c
 Events : 0

Number Major Minor RaidDevice State
 0 8 17 0 active sync /dev/sdb1
 1 8 33 1 active sync /dev/sdc1

Step 7: This is probably os specific but in my case the array didn’t start rebuilding automatically so I had to input the following command to get it started

[sourcecode]root@somehost# mdadm –readwrite /dev/md0[/sourcecode]

You can monitor the process with:

root@somehost# watch cat /proc/mdstat

 

Every 2.0s: cat /proc/mdstat Thu Feb 20 14:11:09 2014

Personalities : [raid1]
md0 : active raid1 sdc1[1] sdb1[0]
 976629568 blocks super 1.2 [2/2] [UU]
 [==========>..........] resync = 51.0% (498891200/976629568) finish=48.7min speed=163438K/sec

unused devices: <none>

Once this is done you can check the output of the “mdadm –detail /dev/md0” command again and this time it will be something like:

/dev/md0:
 Version : 1.2
 Creation Time : Thu Feb 20 13:20:02 2014
 Raid Level : raid1
 Array Size : 976629568 (931.39 GiB 1000.07 GB)
 Used Dev Size : 976629568 (931.39 GiB 1000.07 GB)
 Raid Devices : 2
 Total Devices : 2
 Persistence : Superblock is persistent

Update Time : Thu Feb 20 15:14:19 2014
 State : clean
 Active Devices : 2
Working Devices : 2
 Failed Devices : 0
 Spare Devices : 0

Name : hpproliant:0 (local to host hpproliant)
 UUID : 9c9c5ca2:a4b26264:5d73d487:373aa79c
 Events : 17

Number Major Minor RaidDevice State
 0 8 17 0 active sync /dev/sdb1
 1 8 33 1 active sync /dev/sdc1

Step 8: Format the new RAID array

root@somehost# mkfs.ext4 /dev/md0

mke2fs 1.42.5 (29-Jul-2012)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
61046784 inodes, 244157392 blocks
12207869 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
7452 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

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

Step 9: Create a mount point for your new RAID and make it automount

Create a directory for your mount point, it doesn’t really matter where it is and change the permissions to 775.

root@somehost# mkdir /home/raid1_md0

root@somehost#  chmod 775 /home/raid1_md0

Find the UUID of your RAID array

root@somehost# blkid | grep md0

 

/dev/md0: UUID="a0fa881f-d12f-47d7-971a-e711a71be7b7" TYPE="ext4"

Now open fstab

root@somehost# vi /etc/fstab

And add the following line at the end of the file

 

UUID=a0fa881f-d12f-47d7-971a-e711a71be7b7 /home/raid1_md0  ext4    defaults            0

 

*Note: Of course change the UUID and the folder path to yours

You can mount the array by typing “mount -a”

And if everything went fine you`ll probably see it in the output of “df”

root@somehost# df

Filesystem 1K-blocks Used Available Use% Mounted on
rootfs 329233 147561 164674 48% /
udev 10240 0 10240 0% /dev
tmpfs 192948 400 192548 1% /run
/dev/mapper/hpproliant-root 329233 147561 164674 48% /
tmpfs 5120 0 5120 0% /run/lock
tmpfs 385880 0 385880 0% /run/shm
/dev/sda1 233191 18346 202404 9% /boot
/dev/mapper/hpproliant-home 224001588 191740 212431160 1% /home
/dev/mapper/hpproliant-tmp 376807 10257 347094 3% /tmp
/dev/mapper/hpproliant-usr 8647944 779672 7428976 10% /usr
/dev/mapper/hpproliant-var 2882592 284564 2451596 11% /var
/dev/md0 961303696 204436 912267784 1% /home/raid1_md0

Reboot the machine and enjoy 🙂