-
Notifications
You must be signed in to change notification settings - Fork 2
Encrypted RAID Array and Disk Creation Reference
As of 02/2016, the best cobbled together Google Unix wisdom is that using LVM as a RAID manager, while it offers higher flexibility, still doesn't have management tool and ease parity with pure MDADM. LVM RAID utilizes MDADM under the hood anyways, so there's not real gain if you're not using LVM.
- Here is a basic script that takes a single device
/dev/sdXas an argument, and deletes any existing partition (not partitions), and then creates a whole disk partition with type "fd" akaLinux-Raid
#!/bin/bash
echo "d
n
p
t
fd
w" | fdisk $1
- This sample command creates a RAID 5 array with no hot spares:
mdadm -Cv /dev/md200 -l 5 -n 4 /dev/sdc1 /dev/sdd1 /dev/sde1 /dev/sdf1
- This sample command creates a RAID 1 (Mirrored) array with no hot spares:
mdadm -Cv /dev/md200 -l 1 -n 2 /dev/sda1 /dev/sdb1
- Breakdown of command:
-Cv = -C + -v, Create mode with verbosity
/dev/md200 = RAID Array device name. For CentOS 7, md2** and above is recommended
-l = RAID Level, 1 is mirror, 5 is striped with parity
-n = # of disks to use
/dev/sd... = Device names to go into array
- This command will add new disks to existing startup mdadm.conf file. Be sure you don't have multiple entries of the same disks:
mdadm -D -s /dev/md200 >> /etc/mdadm.conf
- This command will lead you through the prompts to encrypt your disk:
cryptsetup luksFormat /dev/md200
- Here, we've named the drive mapper
vms, but it can be whatever you like:
cryptsetup open /dev/md200 vms
mkfs.xfs /dev/mapper/vms
-
Get UUID for
/dev/md200drive from runninglsblk -ftree -
Create entry in
/etc/crypttabfor disk to be found on boot (assuming mapper named "vms"):echo "vms UUID='Some-Hex-Entry-from-Above' none" >> /etc/crypttab -
Create Folder to mount to (here also assuming "vms"):
mkdir /vms -
Add Auto-Mount Entry to
/etc/fstab:/dev/mapper/vms /vms xfs defaults 0 2
- Prepare individual
/dev/sdXdevices for RAID array. - Create RAID array using
mdadm, e.g./dev/md200 - Add MDADM config of newly create array to
/etc/mdadm.conffile, ensuring no duplicate entries - Encrypt Array
- Unencrypt Array to allow filesystem creation
- Add Crypt Entry to
/etc/crypttabto unlock on boot with password prompt - Create mount point in OS
- Add
/etc/fstabentry