How to use soft raid 1 on Linux

In last post, we talked about how to install Ubuntu Desktop 22.04 LTS with software raid 1. After installation, I still have 2 8TB SSD disk which need to make a soft raid 1. So I record the procedure and share with you.

Environment

Ubuntu Server 22.04

Two 8 TB SSD: /dev/nvme2n1, /dev/nvme3n1

How to create and mount soft raid on Linux

1
2
3
4
5
6
7
# zero out the partition table on the specified disk
sudo sgdisk -Z /dev/nvme2n1
sudo sgdisk -Z /dev/nvme3n1
# install soft raid software
sudo apt install mdadm
# before start, we need to modify some environment variables or the process speed will be very slow due to history cause(In the very very beginning, the hardware is very slow, so the default value is very small)
sudo vim /etc/sysctl.conf
1
2
dev.raid.speed_limit_min = 100000
dev.raid.speed_limit_max = 8000000 #default is 200000
1
2
3
4
5
6
7
8
9
sudo sysctl -p # see whether changes take effect
sudo mdadm --create /dev/md1 --bitmap=internal --level=1 --raid-devices=2 /dev/nvme2n1 /dev/nvme3n1 # start raid process
cat /proc/mdstat # see the raid status, it takes time to finish sync
sudo fdisk /dev/md1 # create a new partition table on created raid device md1, you can press m for help.
sudo mkfs.ext4 /dev/md1p1 # make file system for md1 partition 1
mkdir ~/Desktop/SSD-8T # create mount target folder
sudo mount /dev/md1p1 /home/username/Desktop/SSD-8T # mount it manually
sudo blkid /dev/md1p1 # see the UUID of this partition
sudo vim /etc/fstab # add the mount command to /etc/fstab in order to make automatical mount
1
UUID=230fscd1-6938-4717-b21a-b26454148d28  /home/username/Desktop/SSD-8T  ext4  defaults  0  2
1
sudo mount -a # if output is nothing, everything works fine

How to check raid health status

1
sudo mdadm -D /dev/md1

How to delete a raid device

One day, if you do not want to use raid, you can do as follows.

1
2
3
sudo mdadm --stop /dev/md1
sudo mdadm --zero-superblock /dev/nvme2n1
sudo mdadm --zero-superblock /dev/nvme3n1

Maybe you will find that when you restart your PC, the /dev/md1 becomes /dev/md127 and everything still works fine. I encountered this situation though, I ignore this as it does not matter. If you want to solve this, you can refer to:

  1. https://unix.stackexchange.com/questions/544841/my-raid-1-always-renames-itself-to-dev-md127-after-rebooting-debian-10

  2. https://forums.linuxmint.com/viewtopic.php?t=320969

Reference

  1. https://askubuntu.com/questions/1299978/install-ubuntu-20-04-desktop-with-raid-1-and-lvm-on-machine-with-uefi-bios