cryptsetup-resize - Linux


Overview

cryptsetup-resize allows you to resize an existing LUKS (Linux Unified Key Setup) encrypted block device. It can increase or decrease the size of the encrypted volume without losing any data.

Syntax

cryptsetup-resize [--size|-s <new_size>] [--offset|-o <new_offset>] [--align-payload|-p] [--align-headers|-a] [--header-size|-H <new_header_size>] [--real-sector-size|-S <new_sector_size>] [--cipher|-c <new_cipher_spec>] [--key-size|-k <new_key_size>] [--iv-size|-v <new_iv_size>] <device>

Options/Flags

  • -s, –size: Specifies the new size of the encrypted volume.
  • -o, –offset: Specifies the new offset of the encrypted volume header.
  • -p, –align-payload: Aligns the payload to the sector size.
  • -a, –align-headers: Aligns the headers to the sector size.
  • -H, –header-size: Specifies the new header size.
  • -S, –real-sector-size: Specifies the new sector size.
  • -c, –cipher: Specifies the new cipher specification.
  • -k, –key-size: Specifies the new key size.
  • -v, –iv-size: Specifies the new initialization vector (IV) size.

Examples

Increase the size of an encrypted volume:

cryptsetup-resize --size 20G /dev/sda2

Decrease the size of an encrypted volume:

cryptsetup-resize --size 10G /dev/sda2

Change the header size of an encrypted volume:

cryptsetup-resize --header-size 4096 /dev/sda2

Common Issues

  • LUKS header too small: If the new header size is smaller than the current header size, you may encounter an error. Resize the header first using cryptsetup-resize --header-size <new_header_size>, then resize the volume.
  • LUKS header not found: Ensure that the device specified is a valid LUKS encrypted volume.

Integration

  • Use resize2fs to resize the filesystem within the encrypted volume.
  • Use fdisk or parted to resize the physical partition that contains the encrypted volume.

Related Commands

  • cryptsetup: Manages LUKS encrypted block devices.
  • resize2fs: Resizes ext2/3/4 filesystems.
  • fdisk: Partitions disks.