# Resize a luks encrypted lvm volume (short guide)

## RaraRasputin

Resize a luks encrypted lvm volume

BIG FAT WARNING:

This procedure worked once for me on a small test partition. There is no garanty that it will work in your setup. You may damage or completly lose your data if something goes wrong. So make sure you have a working backup and you know what you are doing! I urge you to try this guide on some testing data on a testing system before you apply it to important data. Maybe you even should not see this post as a guide but as the listing of steps I performed and by pure chance had success with  :Wink: 

Assumptions:

- you have an LVM logical volume encrypted with luks, not an LVM volume group on an encrypted disk.

- LVM logical volume name is "lvmlv" in volume group "test"

- Name of encrypted lv is "crypt-lvmlv"

- Filesystem is ext2 or ext3

- we resize to 400 Megabytes (using 1024 as a base, i.e. 400*1024 = 409,600 kilobytes)

- you understand what you are doing and have a working backup

Just for the protocol: in my setup, the volume group was seated on a single physical volume.

1. Check the filesystem and resize it using resize2fs. 

Your encrypted device must be opened, but the filesystem must not be mounted, so perform one of the following steps as necessary:

```
cryptsetup luksOpen /dev/mapper/test-lvmlv crypt-lvmlv

umount /dev/mapper/crypt-lvmlv
```

Then (anyway):

```
e2fsck -f /dev/mapper/crypt-lvmlv

resize2fs -p /dev/mapper/crypt-lvmlv 400M
```

If there is not enough space on the device, resize2fs will refuse to work.

2. Resize the encrypted device:

```
cryptsetup resize /dev/mapper/crypt-lvmlv -b 819200
```

Note that 819200 is the number of 512 byte sectors in 400M.

3. Close the encrypted device and resize the logical volume:

```
cryptsetup luksClose /dev/mapper/crypt-lvmlv

lvresize -L 405M -A y -v /dev/test/lvmlv
```

I added some extra megabytes reduce the risk of losing data due to rounding. 5 Mb should be enough because the "physical extent" in lvm defaults to 4 Mb.

That's it!

Reopen your crypto-device and mount your filesystem:

```
cryptsetup luksOpen /dev/test/lvmlv crypt-lvmlv

e2fsck /dev/mapper/crypt-lvmlv

mount /dev/mapper/crypt-lvmlv /mnt/myMount
```

----------

