Setting Up RAID1 with LVM on Ubuntu

This guide covers building a software RAID1 mirror with LVM on Ubuntu using two 10TB drives. The combination of mdadm for mirroring and LVM for volume management provides redundancy against single drive failure while maintaining the flexibility to resize, snapshot, or extend storage without repartitioning.

Overview

The storage stack consists of mdadm software RAID1 at the base layer, with LVM physical volumes, volume groups, and logical volumes built on top of the RAID device. This arrangement allows the RAID layer to handle data redundancy while LVM manages space allocation and provides advanced features such as snapshots and online resizing.

/dev/sdb, /dev/sdc  RAID1 (/dev/md0) → LVM PV → VG → LVs

This process destroys all data on both drives. Verify device names with lsblk before executing any commands:

lsblk

Output should show the disks intended for this purpose, not the device names:

root@server ~ # lsblk
NAME              MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINTS
sda                 8:0    0   9.1T  0 disk  
sdb                 8:16   0   9.1T  0 disk  
...

Install the required packages:

sudo apt update
sudo apt install mdadm lvm2 -y

Remove any existing partition tables or filesystem signatures from both drives:

BEFORE that happens, make sure the device names are consistent, the following commands will WIPE the drives.

sudo wipefs -a /dev/sda
sudo wipefs -a /dev/sdb

Create the RAID1 Array

Build the RAID1 array using both drives:

sudo mdadm --create /dev/md2 --level=1 --raid-devices=2 /dev/sda /dev/sdb

The array is immediately usable but will perform an initial synchronization in the background. On 10TB drives this process can take several hours. Monitor sync progress:

cat /proc/mdstat

Save the array configuration to ensure it reassembles correctly after reboot:

sudo mdadm --detail --scan | grep '/dev/md2' | sudo tee -a /etc/mdadm/mdadm.conf
sudo update-initramfs -u

Reboot the server (it may take longer to reboot than before if there is some automatic disk checking mechanism for new disks) and check md2 is still there with cat /proc/mdstat:

root@server45 ~ # cat /proc/mdstat 
Personalities : [raid1] 
md2 : active raid1 sdb[1] sda[0]
      9766304768 blocks super 1.2 [2/2] [UU]
      [>....................]  resync =  0.6% (62070528/9766304768) finish=795.9min speed=203206K/sec
      bitmap: 73/73 pages [292KB], 65536KB chunk
...

The synchronisation will take a long time, just ignore it for now. The array is meantime usable.

Configure LVM

Initialize the RAID device as an LVM physical volume:

sudo pvcreate /dev/md2

Create a volume group named vg_data on the physical volume:

sudo vgcreate vg_media /dev/md2

Create a logical volume using all available space in the volume group. The volume group can be divided into multiple logical volumes if needed:

sudo lvcreate -l 100%FREE -n lv_storage vg_media

Format and Mount the Filesystem

Create an ext4 filesystem on the logical volume:

sudo mkfs.ext4 /dev/vg_media/lv_storage

Create a mount point and mount the filesystem:

sudo mkdir -p /mnt/storage
sudo mount /dev/vg_media/lv_storage /mnt/storage

Add an entry to /etc/fstab to mount the filesystem automatically on boot:

echo '/dev/vg_media/lv_storage /mnt/storage ext4 defaults,nofail 0 2' | sudo tee -a /etc/fstab

Reboot and check it all came up.

Verify Configuration

Check RAID array status:

sudo mdadm --detail /dev/md2

Verify LVM physical volumes, volume groups, and logical volumes:

sudo pvs
sudo vgs
sudo lvs

Confirm the filesystem is mounted and available:

df -h /mnt/storage

Advantages of This Configuration

Online resizing is possible using lvextend and resize2fs without unmounting the filesystem. This is useful when adding additional storage to the volume group, such as a third mirrored pair of drives.

LVM snapshots provide a consistent point-in-time copy of data, useful for backups or before making risky changes to the filesystem.

The volume group can be divided into multiple logical volumes at any time without repartitioning. This allows separation of different use cases such as media storage, backup repositories, or virtual machine images into distinct volumes.

Monitoring and Maintenance

RAID1 redundancy only provides protection if drive failures are detected promptly. Configure email notifications for RAID events:

sudo dpkg-reconfigure mdadm

Check array health regularly using either method:

cat /proc/mdstat
sudo mdadm --detail /dev/md0

The Ubuntu mdadm package installs a monthly mdcheck cron job by default to verify array consistency. Monitor the results of these automated checks, particularly after they run.

AI assistance is used on this site for language, formatting, and turning research into a consistent template. It is not used to perform the underlying research or verify technical claims. Every command, configuration, and step in this post is tested by hand before publication.

Leave a Reply

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

19 + 14 =