linux:raid

Setup raid on Ubuntu

Find the active arrays in the /proc/mdstat:

cat /proc/mdstat
Personalities : [raid0] [linear] [multipath] [raid1] [raid6] [raid5] [raid4] [raid10] 
md0 : active raid0 sdc[1] sdd[0]
      209584128 blocks super 1.2 512k chunks

            unused devices: <none>

Unmount the array, stop it and remove it

sudo umount /dev/md0
sudo mdadm --stop /dev/md0
sudo mdadm --remove /dev/md0

Find the devices that were used to build the array with the following command:

lsblk -o NAME,SIZE,FSTYPE,TYPE,MOUNTPOINT

NAME     SIZE FSTYPE            TYPE MOUNTPOINT
sda      100G                   disk 
sdb      100G                   disk 
sdc      100G linux_raid_member disk 
sdd      100G linux_raid_member disk 
vda       20G                   disk 
├─vda1    20G ext4              part /
└─vda15    1M                   part 

Reset the disks back to normal

sudo mdadm --zero-superblock /dev/sdc
sudo mdadm --zero-superblock /dev/sdd

or

sudo wipefs -a -f /dev/sdc
sudo wipefs -a -f /dev/sdd

Remove any of the persistent references to the array. Edit the /etc/fstab file and comment out or remove the reference to your array. Also, comment out or remove the array definition from the /etc/mdadm/mdadm.conf file.

. . .
# ARRAY /dev/md0 metadata=1.2 name=mdadmwrite:0 UUID=7261fb9c:976d0d97:30bc63ce:85e76e91
. . .

Finally, update the initramfs again

sudo update-initramfs -u

To get started, find the identifiers for the raw disks that you will be using

lsblk -o NAME,SIZE,FSTYPE,TYPE,MOUNTPOINT

NAME     SIZE FSTYPE            TYPE MOUNTPOINT
sda      100G                   disk 
sdb      100G                   disk 
sdc      100G                   disk 
sdd      100G                   disk 
vda       20G                   disk 
├─vda1    20G ext4              part /
└─vda15    1M                   part 

Create RAID1 and create the filesystem

sudo mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sdc /dev/sdd
mkfs.ext4 -F /dev/md0

You can ensure that the RAID was successfully created by checking the /proc/mdstat file:

cat /proc/mdstat

Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10] 
md0 : active raid0 sdd[1] sdc[0]
      209584128 blocks super 1.2 512k chunks

            unused devices: <none>

Add the reference to fstab (/data is the existing mount point on my system)

echo '/dev/md0 /data ext4 defaults,nofail,discard 0 0'>>/etc/fstab

To make sure that the array is reassembled automatically at boot, we will have to adjust the /etc/mdadm/mdadm.conf file. You can automatically scan the active array and append the file

sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf
#sudo mdadm --examine --scan --config=mdadm.conf >> /etc/mdadm/mdadm.conf

Afterwards, you can update the initramfs, or initial RAM file system, so that the array will be available during the early boot process:

sudo update-initramfs -u

Check if new space is avaliable

df -h

Note For some reason, ubuntu ignores the name md0 on the next boot, and renames the array to md127. You can check with mdadm –query –detail /dev/md*

Enter your comment:
111 +12 = 
 
  • linux/raid.txt
  • Last modified: 2019/10/31 08:55
  • by 127.0.0.1