Create RAID1 on debian

While perfectioning the setup of my homeserver I decided to put the data partition(s) on RAID1. Although the mainboard claims to have a raid controller this is only a fakeRAID, so using a software RAID under linux is probably better. Anyways the work has to be done by the CPU.
As the system itself is installed on a SSD it will not be part of the raid. So things are quite easy to achieve.

This is a post from my old blog http://tech.cbjck.de. It has been moved here and slightly edited for better readability. It's also been adjusted to the new layout.
The content however is old and might be outdated.


First all (new) disk have to be formatted and partition for the RAID.

Partion the drives

First we have to format and partition all the drives for the raid. I’ve done this using gdisk.

gdisk /dev/sdb
GPT fdisk (gdisk) version 0.8.5

Partition table scan:
  MBR: not present
  BSD: not present
  APM: not present
  GPT: not present

Creating new GPT entries.

Command (? for help):

Enter o to create a new empty GPT partition table.

This option deletes all partitions and creates a new protective MBR.
Proceed? (Y/N):>

Confirm by typing Y

Command (? for help):

Type n to create a new partition and confirm the following questions by pressing Enter.

Partition number (1-128, default 1): 
First sector (34-3907029134, default = 2048) or {+-}size{KMGTP}: 
Last sector (2048-3907029134, default = 3907029134) or {+-}size{KMGTP}: 

When being asked for filesystem type enter fd00 to create a Linux RAID partition.

Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): fd00
Changed type of partition to 'Linux RAID'

Command (? for help):

Type p to print the current settings and check if everything is alright.

Disk /dev/sdb: 3907029168 sectors, 1.8 TiB
Logical sector size: 512 bytes
Disk identifier (GUID): 3A43229D-A00E-4BD7-A033-752CCF729163
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 3907029134
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048      3907029134   1.8 TiB     FD00  Linux RAID

Command (? for help):

Now type w to write the changes to disk. Confirm the following question with Y

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to /dev/sdd.
The operation has completed successfully.

Repeat this for all disks that should be part of tha data raid.

parted -l

will give you a list of all hard drives.

Create RAID

Install mdadm

aptitude install mdadm

The installer will ask if any MD arrays will be needed for booting. In my case the answer is no, so type none or leave the prompt empty.
However RAID arrays should be started on boot (answer yes).

Now create the first array:

mdadm --create --verbose /dev/md0 --auto=yes --level=1 --raid-devices=2 /dev/sdb /dev/sde

This will create the virtual device /dev/md0 consisting of the two real devices /dev/sdb and /dev/sde. The creation will take a while, you can watch the progress by

mdadm --detail /dev/md0

My server has three of these virtual devices, so I have to repeat this twice.
The created devices can be used as “normal” hard drives. you can create a filesystem on them, usem them in a lvm, …

Leave a Reply

Your email address will not be published. Required fields are marked *