Using spare M2 storage to create RAID1 set

 · Systeemkabouter

The slimbook I ordered was ordered with the basic specs. As soon as I was convinced the laptop would be worthwhile, I ordered extra RAM and storage capacity.

So next to the 256 GB NVME storage I installed a 1 TB M2 stick. I reinstalled the operating on the new storage device, but while setting partitions I set about 256 GB of space aside for later use.

Later is now and I just setup a small RAID1 device using linux mdadm, running a encrypted container on top. I intend to use this storage to run virtual machines for improved read performance and maybe to secure more sensitive data from data loss.

Setting up was pretty straighforward, but is documented here for future reference:

  • created two new partitions, accepting they are not exactly the same size
root@tux:~# fdisk -l /dev/nvme0n1
Disk /dev/nvme0n1: 232,91 GiB, 250059350016 bytes, 488397168 sectors
Disk model: Samsung SSD 980 250GB                   
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 16384 bytes / 131072 bytes
Disklabel type: gpt
Disk identifier: 4925E21F-2FAD-4480-89F4-429C4D3F3BF4

Device           Start       End   Sectors   Size Type
/dev/nvme0n1p1    2048   1050623   1048576   512M EFI System
/dev/nvme0n1p2 1050624 488397134 487346511 232,4G Linux RAID


root@tux:~# fdisk -l /dev/nvme1n1
Disk /dev/nvme1n1: 931,53 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: Samsung SSD 980 PRO 1TB                 
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: 99B17A0E-A5DA-4D54-92C1-7CE85AC8BC1A

Device              Start        End    Sectors   Size Type
/dev/nvme1n1p1       2048    1046527    1044480   510M EFI System
/dev/nvme1n1p2    1046528    3047423    2000896   977M Linux filesystem
/dev/nvme1n1p3    3047424 1455472639 1452425216 692,6G Linux filesystem
/dev/nvme1n1p4 1455472640 1953525134  498052495 237,5G Linux RAID

so apparently I lost about 5 GB of disk storage, I will live.

Then I created the RAID1 md0 device:

root@tux:~# mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/nvme0n1p2 /dev/nvme1n1p4
mdadm: /dev/nvme0n1p2 appears to contain an ext2fs file system
       size=749568K  mtime=Thu Feb  9 17:12:57 2023
mdadm: Note: this array has metadata at the start and
    may not be suitable as a boot device.  If you plan to
    store '/boot' on this device please ensure that
    your boot-loader understands md/v1.x metadata, or use
    --metadata=0.90
mdadm: size set to 243541120K
mdadm: automatically enabling write-intent bitmap on large array
mdadm: largest drive (/dev/nvme1n1p4) exceeds size (243541120K) by more than 1%
Continue creating array? yes
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.

than I created the encrypted container on top of the md0 raid device:

root@tux:~# cryptsetup -y -v --type luks1 luksFormat /dev/md0
WARNING: Device /dev/md0 already contains a 'gpt' partition signature.

WARNING!
========
This will overwrite data on /dev/md0 irrevocably.

Are you sure? (Type uppercase yes): YES
Enter passphrase for /dev/md0: 
Verify passphrase: 
Existing 'gpt' partition signature (offset: 512 bytes) on device /dev/md0 will be wiped.
Existing 'gpt' partition signature (offset: 249386106368 bytes) on device /dev/md0 will be wiped.
Existing 'PMBR' partition signature (offset: 510 bytes) on device /dev/md0 will be wiped.
Key slot 0 created.
Command successful.

check the mdstatus to see if RAID syncing was coming along:

root@tux:~# more /proc/mdstat 
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10] 
md0 : active raid1 nvme1n1p4[1] nvme0n1p2[0]
      243541120 blocks super 1.2 [2/2] [UU]
      [================>....]  resync = 82.7% (201448064/243541120) finish=3.3min speed=210509K/sec
      bitmap: 1/2 pages [4KB], 65536KB chunk

unused devices: <none>

almost done there.

Then it was just a case off unlocking the device, formatting it and mounting it somewhere

root@tux:~# cryptsetup luksOpen /dev/md0 datavol
Enter passphrase for /dev/md0: 
root@tux:~# mkfs.btrfs /dev/mapper/datavol 
root@tux:~# cryptsetup luksOpen /dev/md0 datavol
Enter passphrase for /dev/md0: 
root@tux:~# ls /dev/mapper/
control  datavol  nvme1n1p3_crypt
root@tux:~# mkfs.btrfs /dev/mapper/datavol