Data Disks - marco1475/linux-htpc GitHub Wiki
-
Install
gptfdiskandmdadm:pacman -S gptfdisk mdadm -
Create a single partition on the first drive:
-
Start the
gdiskpartitioning utility on the first drive:gdisk /dev/sdb -
Create the partition:
- Press
nand hitEnterto create a new partition. - Press
Enterto accept the default partition number (in this case 1). - Press
Enteragain to accept the default first sector (in this case 2048). TODO: Different disks have different-sized sectors. What is this in MiB? - Enter
-100Mto set the last sector to be 100 MiB before the last sector, to account for small size differences between identical hard drives. - Enter
fd00to set the partition type toLinux RAID.
- Press
-
Press
pto print out the partition table:Number Start (sector) End (sector) Size Code Name 1 2048 7813832334 3.6 TiB FD00 Linux RAID -
Press
wto write the partition table to disk.
-
-
Create a single partition on the second drive:
-
Start the
gdiskpartitioning utility on the first drive:gdisk /dev/sdc -
Create the partition:
- Press
nand hitEnterto create a new partition. - Press
Enterto accept the default partition number (in this case 1). - Press
Enteragain to accept the default first sector (in this case 2048). TODO: Different disks have different-sized sectors. What is this in MiB? - Enter
-100Mto set the last sector to be 100 MiB before the last sector, to account for small size differences between identical hard drives. - Enter
fd00to set the partition type toLinux RAID.
- Press
-
Press
pto print out the partition table:Number Start (sector) End (sector) Size Code Name 1 2048 7813832334 3.6 TiB FD00 Linux RAID -
Press
wto write the partition table to disk.
-
-
Create the RAID array:
mdadm --create --verbose --level=1 --metadata=1.2 --raid-devices=2 --name=raid1_data /dev/md0 /dev/sdb1 /dev/sdc1-
mdadmoutput:mdadm: size set to 3906784064K mdadm: automatically enabling write-intent bitmap on large array mdadm: array /dev/md0 started. -
While the RAID array is being built you can check on its progress by calling
cat /proc/mdstat:md0 : active raid1 sdc1[1] sdb1[0] 3906784064 blocks super 1.2 [2/2] [UU] [>....................] resync = 0.2% (11688832/3906784064) finish=459.0min speed=141432K/sec bitmap: 30/30 pages [120KB], 65536KB chunk unused devices: <none>
-
-
Update the
mdadm.confconfiguration file:-
Append the output of
mdadm --scanto/etc/mdadm.conf:mdadm --detail --scan >> /etc/mdadm.conf -
Re-arrange the
/etc/mdadm.conffile so that the added line (below) is where it logically belongs:ARRAY /dev/md0 metadata=1.2 name=babylon5:raid1_data UUID=fe9fce4d:6abcc818:4da7d7fd:882a0be8 -
Add an e-mail address to
/etc/mdadm.confso you will be notified if something goes wrong:MAILADDR [email protected]- Note that you have to have a [E-mail Forwarder](e-mail forwarder) set up.
- Note that without the
MAILADDRentry themdmonitorservice will fail at startup.
-
-
Assemble the RAID array:
mdadm --assemble --scan -
Format the RAID filesystem:
mkfs.ext4 /dev/md0- You don't need to worry about chunk size or stripe width, because this is a RAID1 array.
-
Ensure the RAID array gets built on boot:
-
Add the
mdadm_udevhook to/etc/mkinitcpio.conf'sHOOKSsection:HOOKS="base udev keyboard autodetect modconf block mdadm_udev keymap encrypt filesystems fsck" -
Regenerate the
initramfsimage:mkinitcpio -p linux
-
-
Encrypt the
/dev/md0partition usingdm-crypt:cryptsetup -s 512 luksFormat /dev/md0- Type
YESwhen prompted for confirmation that all data on/dev/md0will be overwritten. - Enter the passphrase that will unlock the partition (hint: full+server+partition) and verify it.
- Type
-
Open the encrypted partition:
cryptsetup open --type luks /dev/md0 cryptdata- The encrypted partition can now be accessed through
/dev/mapper/cryptdata.
- The encrypted partition can now be accessed through
-
Format the encrypted partition:
mkfs.ext4 /dev/mapper/cryptdata -
Write down the UUIDs of the newly-encrypted and formatted partitions.
lsblk -no name,uuid- Note that the encrypted partition has a different UUID locked vs. unlocked.
-
Close the partition:
cryptsetup close cryptdata
-
Open the encrypted partition:
cryptsetup open --type luks /dev/md0 cryptdata -
Get the
UUIDof/dev/md0by executing either of these commands:lsblk -no name,uuid ls -l /dev/disk/by-uuid/ -
Edit the
/etc/crypttabfile to open the encrypted partition:<name> <device> <password> <options> cryptdata UUID=ed10b92a-e474-4844-83c7-9f2511dc8249 none luks- Use
/dev/md0'sUUIDhere.
- Use
-
Edit the
/etc/fstabfile to mount the opened partition:<file system> <dir> <type> <options> <dump> <pass> # /dev/mapper/cryptdata /dev/mapper/cryptdata /data ext4 defaults,errors=remount-ro 0 2- Since
/dev/mapper/cryptdataalready is the result of a unique partition mapping, there is no need to specify anUUIDfor it. - If you use
/dev/mapper/cryptdata'sUUIDyou might get error messages about failed unmounts during shutdown.
- Since