Linux LUKS – How to Resize a LUKS Device, Revisited

linuxluks

I have read:

And others.

I'm trying to resize from 250 GB to 500 GB. Previously, the partition /dev/sda2, was 250 GB, I've now resized the partition to 500 GB.

However, what about the LUKS device, which resides at /dev/sda2? How do I resize that?

Well, the manual (for cryptsetup) provides us with "resize". However, when I check with cryptsetup status, my device is already 500 GB.

Furthermore, when I check in parted, it (the encrypted device /dev/dm-0 or /dev/mapper/cryptdevice which is a symlink) also shows up as 500 GB.

It appears my encrypted device is already the correct size!

Why then, when I actually mount the encrypted device (/dev/mapper/cryptdevice), does it show up as 250 GB?

Did I miss a step? What else do I need to do?

I've obviously rebooted many times between doing this. I've started from a bootable USB device, executed cryptsetup, rebooted, etc. It still shows up as 250 GB, when I would expect it to be 500 GB.

Note that I never actually resized anything beyond the partition itself. After resizing the partition, cryptsetup and parted started reporting the encrypted volume as also being resized — but again, when I mount it, it is still only 250 GB.

I don't have LVM on top of this, I just have:

/dev/sda2, which contains a LUKS encrypted file system. I open this with cryptsetup luksOpen /dev/sda2 cryptdevice, etc.

Best Answer

You still have to resize the filesystem using the resized block device. The precise method and possible limitations depend on each filesystem.

Here are two examples to resize the filesystems to the whole available size for EXT4 and XFS. An other filesystem will require an other specific command.

  • An EXT4 filesystem can be enlarged online or offline (and can also be shrunk, but only offline).

    resize2fs /dev/mapper/cryptdevice
    
  • An XFS filesystem can only be enlarged, and online (can't be shrunk back once done).

    The filesystem must be mounted to be grown. The command requires the mountpoint rather than the block device.

    mount -t xfs /dev/mapper/cryptdevice /mnt
    
    xfs_growfs /mnt
    

You actually missed this step twice from the links:

  • Resize LUKS Volume(s)

    in the question:

    # Step 5: Resize encrypted volume (Trying to give it some space)
    > resize2fs -p /dev/CryptVolumeGroup/root 101G
    

    but in the answer:

    Enlarge the rootfs logical volume. No need to un-mount since ext4 and be enlarged while mounted: lvresize -r -L +100G archvg/home

    lvresize -r resizes automatically the underlying filesystem, hence no specific command in the answer. Resizing the filesystem for your specific case not using LVM wasn't present in this answer.

  • Increase the size of a LUKS encrypted partition

    As a final step, the file-system needs to be expanded to the new size. With the resize2fs(8) command the file-system is extended to the new size of the LUKS volume.

    $ sudo resize2fs /dev/mapper/sdb1_crypt
    resize2fs 1.42.13 (17-May-2015)
    Filesystem at /dev/mapper/sdb1_crypt is mounted on /media/gerhard/Daten; on-line resizing required
    old_desc_blocks = 2, new_desc_blocks = 4
    The filesystem on /dev/mapper/sdb1_crypt is now 14647925 (4k) blocks long.
    
  • Resizing LVM-on-LUKS

    Resizing the encrypted volume

    Now we are going to resize the encrypted volume itself. By taking in account the total size of the logical volume minus some safety space:

    # resize2fs -p /dev/CryptVolumeGroup/Home 208G
    
Related Question