Data Disks - marco1475/linux-htpc GitHub Wiki
-
Install
gptfdisk
andmdadm
:pacman -S gptfdisk mdadm
-
Create a single partition on the first drive:
-
Start the
gdisk
partitioning utility on the first drive:gdisk /dev/sdb
-
Create the partition:
- Press
n
and hitEnter
to create a new partition. - Press
Enter
to accept the default partition number (in this case 1). - Press
Enter
again to accept the default first sector (in this case 2048). TODO: Different disks have different-sized sectors. What is this in MiB? - Enter
-100M
to set the last sector to be 100 MiB before the last sector, to account for small size differences between identical hard drives. - Enter
fd00
to set the partition type toLinux RAID
.
- Press
-
Press
p
to print out the partition table:Number Start (sector) End (sector) Size Code Name 1 2048 7813832334 3.6 TiB FD00 Linux RAID
-
Press
w
to write the partition table to disk.
-
-
Create a single partition on the second drive:
-
Start the
gdisk
partitioning utility on the first drive:gdisk /dev/sdc
-
Create the partition:
- Press
n
and hitEnter
to create a new partition. - Press
Enter
to accept the default partition number (in this case 1). - Press
Enter
again to accept the default first sector (in this case 2048). TODO: Different disks have different-sized sectors. What is this in MiB? - Enter
-100M
to set the last sector to be 100 MiB before the last sector, to account for small size differences between identical hard drives. - Enter
fd00
to set the partition type toLinux RAID
.
- Press
-
Press
p
to print out the partition table:Number Start (sector) End (sector) Size Code Name 1 2048 7813832334 3.6 TiB FD00 Linux RAID
-
Press
w
to 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
-
mdadm
output: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.conf
configuration file:-
Append the output of
mdadm --scan
to/etc/mdadm.conf
:mdadm --detail --scan >> /etc/mdadm.conf
-
Re-arrange the
/etc/mdadm.conf
file 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.conf
so 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
MAILADDR
entry themdmonitor
service 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_udev
hook to/etc/mkinitcpio.conf
'sHOOKS
section:HOOKS="base udev keyboard autodetect modconf block mdadm_udev keymap encrypt filesystems fsck"
-
Regenerate the
initramfs
image:mkinitcpio -p linux
-
-
Encrypt the
/dev/md0
partition usingdm-crypt
:cryptsetup -s 512 luksFormat /dev/md0
- Type
YES
when prompted for confirmation that all data on/dev/md0
will 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
UUID
of/dev/md0
by executing either of these commands:lsblk -no name,uuid ls -l /dev/disk/by-uuid/
-
Edit the
/etc/crypttab
file to open the encrypted partition:<name> <device> <password> <options> cryptdata UUID=ed10b92a-e474-4844-83c7-9f2511dc8249 none luks
- Use
/dev/md0
'sUUID
here.
- Use
-
Edit the
/etc/fstab
file 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/cryptdata
already is the result of a unique partition mapping, there is no need to specify anUUID
for it. - If you use
/dev/mapper/cryptdata
'sUUID
you might get error messages about failed unmounts during shutdown.
- Since