Raid Software (MDx)
Note: If you've problem like ERROR: sector 0. You could use --force option.
Global overview (info)
cat /proc/mdstat
Detailed information
mdadm --misc --detail /dev/mdx
Create a new raid (drives and/or partitions)
mdadm --create /dev/mdx --level=1 --raid-devices=2 /dev/sdaX /dev/sdbX
Add a drive to an existing raid
mdadm /dev/mdx --manage --add /dev/sdbx
Declare an array as failed
mdadm --fail /dev/mdx /dev/sdax
Copy partitions (identical partitions)
Especially useful if you've changed a drive (e.g. broken), or if you badly manipulate a disk. Let say it happens on /dev/sda
:
# if MBR
sfdisk -d /dev/sdb | sfdisk /dev/sda
# elif GPT (-R for replicate)
sgdisk -R=/dev/sda /dev/sdb
Remove raid partitions
umount -l /dev/mdX
mdadm --stop /dev/mdX
mdadm --zero-superblock /dev/sdaX
mdadm --zero-superblock /dev/sdbX ... etc.
Resync is pending
Might happened if you reboot during a sync, the following command will continue the sync:
mdadm --readwrite /dev/mdx
Tips
Add raid on current running system (with root, EFI)
I was not able to do it, but I keep the process and link in case I try again in future
Let say you have two disk, on already configured, another with none
root@ephemeral:~# fdisk -l
Disk /dev/nvme0n1: 894.25 GiB, 960197124096 bytes, 1875385008 sectors
Disk model: SAMSUNG MZQLB960HAJR-00007
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: CA6E3FC8-B2C1-8642-AB8D-366D44E0C6C0
Device Start End Sectors Size Type
/dev/nvme0n1p1 262144 1875251199 1874989056 894.1G Linux root (x86-64)
/dev/nvme0n1p2 1875251200 1875382960 131761 64.3M Linux filesystem
/dev/nvme0n1p14 2048 8191 6144 3M BIOS boot
Partition table entries are not in disk order.
Disk /dev/nvme1n1: 894.25 GiB, 960197124096 bytes, 1875385008 sectors
Disk model: SAMSUNG MZQLB960HAJR-00007
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
The whole idea is to:
- copy the partition of current running system (nvme0n1) into the empty drive (nvme1n1) (see above section e.g.
sgdisk -R=/dev/nvme1n1 /dev/nvmen0n1
) - declare the empty drive main partition(s) (nvme1n1p1) as pseudo raid 1, e.g. for one partition
mdadm --create --verbose /dev/md0 --force --level=1 --raid-devices=1 /dev/nvme0n1p1
- declare the prepared drive as the booted device (fstab edit, update grub, raid type)
# how to obtain UUID for /dev/md0 ?
# update fstab
/dev/md0 / ext4 rw,discard,errors=remount-ro,x-systemd.growfs 0 1
# Regenerate initrd with mdadm kernel module included
update-initramfs -k all -u
# NOTE I had the following error -> W: Couldn't identify type of root file system for fsck hook
# update grub (unsure of this step)
# grub-install /dev/nvme1n1p1
# set the future partition as Raid Linux
cfdisk /dev/nvme1n1
- copy the data of current running system main partitions into the prepared drive
dd if=/dev/nvme0n1p1 of=/dev/nvme1n1p1 bs=1M conv=noerror,sync
dd if=/dev/nvme0n1p2 of=/dev/nvme1n1p2 bs=1M conv=noerror,sync
dd if=/dev/nvme0n1p14 of=/dev/nvme1n1p14 bs=1M conv=noerror,sync
dd if=/dev/nvme0n1p15 of=/dev/nvme1n1p15 bs=1M conv=noerror,sync
- reboot, ensure system is working
- declare the main partition(s) of previous main disk as raid type (
cfdsik /dev/nvme0n1
) - now you can add the main partition(s) of previous main disk as part of raid
mdadm /dev/md0 --add /dev/nvme0n1p1