Operating Systems

Setting up RAID 1 mirroring in Debian

Redundancy is ambiguous because it seems like a waste if nothing unusual happens. Except that something unusual happens-usually.

mdadm is used to manage MD devices aka Linux Software RAID. install it:

# apt-get install mdadm

Find your new disks

# dmesg | grep "Attached SCSI disk"
[ 8.831474] sd 1:0:0:0: [sda] Attached SCSI disk
[ 8.864724] sd 2:0:0:0: [sdb] Attached SCSI disk
[ 8.904818] sd 3:0:0:0: [sdc] Attached SCSI disk
[ 8.943406] sd 4:0:0:0: [sdd] Attached SCSI disk

Check them for signatures

# mdadm -E /dev/sd[a-d]

if the disk is new then the result will be something like:

mdadm: No md superblock detected on /dev/sdc.

go ahead and partition one of your disks:

# cfdisk /dev/sdb

cfdisk will ask you what labeltype you would like, choose GPT

Only do this on one of your drives then dump the partitiontable with sfdisk

# sfdisk -d /dev/sdc > /tmp/sdc.fs
# sfdisk /dev/sdd < /tmp/sdc.fs

Check your system for old MD devices

# mdadm --detail --scan
ARRAY /dev/md/0 metadata=1.2 name=server11:0 UUID=2b6bb7a9:378a9a49:2198cc6e:bd03fc19
ARRAY /dev/md/1 metadata=1.2 name=server11:1 UUID=b0134f3c:8386919d:37b6091e:7885209c

I have MD0 and MD1 since before so i choose to create MD2.

# mdadm --create /dev/md2 --level=mirror --raid-devices=2 /dev/sdc1 /dev/sdd1

to add you new MD run

# mdadm --detail --scan >> /etc/mdadm/mdadm.conf

Then go ahead and create your filesystem

mkfs.ext4 /dev/md2

now we need to add mounting of our new RAID1 on system boot, instead of adding /dev/md2 to the /etc/fstab we will find out the UUID of our MD:

# lsblk -o NAME,UUID
├─sda1  2b6bb7a9-378a-9a49-2198-cc6ebd03fc19
│ └─md0 819acf13-ea5f-4d28-ba03-043b6832ea47
└─sda2  b0134f3c-8386-919d-37b6-091e7885209c
  └─md1 842dd132-c098-4901-adc8-e0f95fa9c54e
├─sdb1  2b6bb7a9-378a-9a49-2198-cc6ebd03fc19
│ └─md0 819acf13-ea5f-4d28-ba03-043b6832ea47
└─sdb2  b0134f3c-8386-919d-37b6-091e7885209c
  └─md1 842dd132-c098-4901-adc8-e0f95fa9c54e
└─sdc1  f8362424-3dca-398e-f079-4758ed6655d2
  └─md2 721a40ee-6825-46f3-ae63-cf2b79ad1f5f
└─sdd1  f8362424-3dca-398e-f079-4758ed6655d2
  └─md2 721a40ee-6825-46f3-ae63-cf2b79ad1f5f

Lets compile a line for the fstab

UUID=721a40ee-6825-46f3-ae63-cf2b79ad1f5f /storage ext4 defaults 0 0

Save the file and then try to mount your new drive

# mount /storage

By Nimpen J. Nordström

System Developer and Network Security Enthusiast

Leave a Reply

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