Expanding a LUKS encrypted disk image

Yesterday I wrote about How to create an encrypted LUKS disk image.

Today I wanted to experiment more with it. I wanted to try resizing a LUKS volume, and after one failed attempt I found a way. If you still have the disk image of yesterday’s example, just follow me. 🙂

  1. Safety first! Unmount, luksClose and then backup your image file.
    sudo umount /dev/mapper/myluksvol1 && sudo cryptsetup luksClose myluksvol1
    cp /home/shaakunthala/luksvolume1 /home/shaakunthala/luksvolume1.bak
  2. Now, make more room in the container.
    dd if=/dev/zero of=/home/shaakunthala/luksvolume1 bs=1M count=1024 oflag=append conv=notrunc

    Yesterday we created a 512 MB disk image, now let’s add one more gigabyte. Conv and oflag options tell dd not to overwrite or truncate the image but append zero data.

  3. Open the encrypted volume.
    sudo cryptsetup luksOpen /home/shaakunthala/luksvolume1 myluksvol1
  4. Repair ext4 file system to make sure it’s clean and then resize to claim ‘unallocated’ 1 GB.
    sudo fsck -fvy /dev/mapper/myluksvol1
    sudo resize2fs /dev/mapper/myluksvol1
    sudo fsck -fvy /dev/mapper/myluksvol1 # One last sanity check
  5. Now, if there are no errors the filesystem has successfully grown to the maximum available size of the encrypted partition.
    sudo mount /dev/mapper/myluksvol1 /mnt
    df -h /mnt

I’m still experimenting this and next thing I would like to try out on my own is how to shrink a LUKS encrypted disk image.

Advertisements
Expanding a LUKS encrypted disk image

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s