LUKS volume over LVM

Medical Technology, Healthcare & Government IT

Category Groups

Setup LUKS over LVM

sudo aptitude install cryptsetup-luks ##Installing LUKS under Ubuntu
apt-get install lvm2     ##Install LVM

Create one 5G files corresponding to physical volumes:

sudo dd if=/dev/zero of=/pv00.luks bs=1M count=0 seek=5000
ls -l /pv*.luks

Attach all of them to loopback devices:

sudo losetup /dev/loop0 /pv00.luks
losetup -a

Setup all devices as LUKS volumes (answer all prompts):

sudo cryptsetup luksFormat /dev/loop0

Open all LUKS devices:

sudo cryptsetup luksOpen /dev/loop0 pv00.luks.device

Create LVM Physical Volumes from each LUKS device:

sudo pvcreate /dev/mapper/pv00.luks.device

Create LVM Volume Group from all LUKS PVs:

sudo vgcreate vg0 /dev/mapper/pv00.luks.device

Carve out a LVM Logical Volume from the vg0 Volume Group:

sudo lvcreate --size 4800M --name mysql-data vg0

Format and mount the data Logical Volume with whatever filesystem you choose:

sudo mkfs.ext4 /dev/vg0/mysql-data
sudo mount /dev/vg0/mysql-data /var/lib/mysql

At the end of all this, mysql will contain a filesystem that can be expanded by adding more LUKS volumes to the mix.

For automatic mount LUKS volume after rebooting need to run the following perl script:

/root/ --logical-volume mysql-data --volume-group vg0 --mount-point /var/lib/mysql /pv00.luks
/root/ --logical-volume mysql-data --volume-group vg0 --mount-point /var/lib/mysql /pv00.luks

Pearl Scripts

Original Link

Leave a Reply