Add a LUKS Encrypted Drive in Ubuntu
Partition
Partition the disk with gdisk /dev/sdb
as type Linux LVM 8e00
.
Setup LUKS
cryptsetup luksFormat /dev/sdb1
cryptsetup luksOpen /dev/sdb1 sdb1_crypt
pvcreate /dev/mapper/sdb1_crypt
vgcreate server-hdd-vg /dev/mapper/sdb1_crypt
lvcreate -l 100%FREE -n root /dev/server-hdd-vg
mkfs.ext4 /dev/server-hdd-vg/root
mkdir /mnt/hdd
mount /dev/server-hdd-vg/root /mnt/hdd
Unlock disk automatically
Generate keyfile
sudo dd if=/dev/urandom of=/root/keyfile-sdb1_crypt bs=1024 count=4
chmod 0400 /root/keyfile-sdb1_crypt
cryptsetup luksAddKey /dev/sdb1 /root/keyfile-sdb1_crypt
Get the UUID for sdb1
ls -l /dev/disk/by-uuid
Edit /etc/crypttab
sdb1_crypt UUID=<DISK UUID> /root/keyfile-sdb1_crypt luks
Get the UUID for /dev/mapper/server--hdd--vg-root
blkid
Edit /etc/fstab
UUID=<MAPPER UUID> /mnt/hdd ext4 defaults 0 2
Adding a disk to an existing volume group
vgextend server-hdd-vg /dev/mapper/sdc1_crypt
pvscan
lvdisplay
lvextend /dev/server-hdd-vg/root /dev/mapper/sdc1_crypt
resize2fs /dev/server-hdd-vg/root