Add a crypt data volume to Alpine 3.17
This is how to setup a data volume on an already configured Alpine 3.17 system.
The disk is at: /dev/sdb
, it also could be /dev/vdb
Creating partitions
You can even skip this step and use all the disk at once.
Just rename sdb1
to sdb
in other commands & scripts.
fdisk /dev/sdb
Enter the keyboard sequence:
# p
# n
# p
# 1
# ENTER
# ENTER
# p
# w
Creating LUKS setup
apk add --update cryptsetup lsblk
Creating the LUKS/LVM/EXT4 partition
Make the LUKS drive:
cryptsetup luksFormat --hash sha512 /dev/sdb1
cryptsetup luksOpen /dev/sdb1 enc_storage
Create LVM and ext4 into it:
mkfs.ext4 /dev/mapper/enc_storage
Mount it:
mkdir /mnt/storage
lsblk
echo -e "/dev/mapper/enc_storage\t/mnt/storage\text4\tdefaults\t0\t0\n" >> /etc/fstab
mount -a
lsblk
df -h
Helper script
I often put this in ~/open.sh
to help unlocking the system when I have forgot the commands.
#!/bin/sh -exu
cryptsetup luksOpen /dev/sdb1 enc_storage
mount -a -v
#echo 'Starting docker'
#rc-service docker start
#echo 'Waiting 4sec for Docker to start'
#sleep 4
echo 'Done !'