How to grow a filesystem sitting on a LUKS volume with it remains open?

Solution Verified - Updated

Environment

  • Red Hat Enterprise Linux 6
  • Red Hat Enterprise Linux 7
  • Red Hat Enterprise Linux 8
  • Red Hat Enterprise Linux 9
  • LUKS

Issue

  • I need to grow a filesystem sitting on a LUKS encrypted volume whose backing device is a logical volume luks_lv sitting on a volume group luks_vg as shown below:
# df
Filesystem           1K-blocks     Used Available Use% Mounted on
/dev/dm-3              6190656   141304   5735000   3% /luks                             <<<<
 
# lsblk
NAME                                                   MAJ:MIN RM  SIZE RO TYPE  MOUNTPOINT
sdc                                                      8:32   0   10G  0 disk  
└─sdc1                                                   8:33   0   10G  0 part  
  └─luks_vg-luks_lv (dm-2)                             253:2    0    6G  0 lvm   
    └─luks-a9b47d2a-2daf-4a86-83cf-784ee707f294 (dm-3) 253:3    0    6G  0 crypt /luks   <<<<

# vgs
  VG       #PV #LV #SN Attr   VSize  VFree
  luks_vg    1   1   0 wz--n- 10.00g 4.00g                                               <<<<

# lvs
  LV      VG       Attr       LSize  Pool Origin Data%  Move Log Cpy%Sync Convert
  luks_lv luks_vg  -wi-ao----  6.00g                                                     <<<<
# 
  • I ran resize2fs to resize the filesystem after extending the logical volume on which the filesystem was sitting. However it said 'Nothing to do!' as shown below:
# lvextend luks_vg/luks_lv -L +1G
  Extending logical volume luks_lv to 7.00 GiB
  Logical volume luks_lv successfully resized

# resize2fs /dev/mapper/luks-a9b47d2a-2daf-4a86-83cf-784ee707f294 
resize2fs 1.41.12 (17-May-2010)
The filesystem is already 1572352 blocks long.  Nothing to do!
  • How to grow a filesystem sitting on a LUKS volume with it remains open?

Resolution

  • Perform cryptsetup resize after extending the backing device of the LUKS volume (the logical volume luks_lv in this example) so that LUKS rediscovers the size of the volume:
# cryptsetup status luks-a9b47d2a-2daf-4a86-83cf-784ee707f294
/dev/mapper/luks-a9b47d2a-2daf-4a86-83cf-784ee707f294 is active and is in use.
  type:  LUKS1
  cipher:  aes-cbc-essiv:sha256
  keysize: 256 bits
  device:  /dev/mapper/luks_vg-luks_lv
  offset:  4096 sectors
  size:    12578816 sectors  <<<<<<<<<<
  mode:    read/write

# cryptsetup resize !$
cryptsetup resize luks-a9b47d2a-2daf-4a86-83cf-784ee707f294

# cryptsetup status luks-a9b47d2a-2daf-4a86-83cf-784ee707f294
/dev/mapper/luks-a9b47d2a-2daf-4a86-83cf-784ee707f294 is active and is in use.
  type:  LUKS1
  cipher:  aes-cbc-essiv:sha256
  keysize: 256 bits
  device:  /dev/mapper/luks_vg-luks_lv
  offset:  4096 sectors
  size:    14675968 sectors  <<<<<<<<<<
  mode:    read/write
  • Once the LUKS encrypted device is resized it's necessary to update the filesystem superblock about the extra space:

    • If the filesystem in use is ext3 or ext4, run the resize2fs command:
# resize2fs /dev/mapper/luks-a9b47d2a-2daf-4a86-83cf-784ee707f294
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/luks-a9b47d2a-2daf-4a86-83cf-784ee707f294 is mounted on /luks; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/mapper/luks-a9b47d2a-2daf-4a86-83cf-784ee707f294 to 1834496 (4k) blocks.
The filesystem on /dev/mapper/luks-a9b47d2a-2daf-4a86-83cf-784ee707f294 is now 1834496 blocks long.
  • If the filesystem in use is XFS, then run the xfs_growfs command:
# xfs_growfs  /dev/mapper/luks-a9b47d2a-2daf-4a86-83cf-784ee707f294
  • Finally, use the df command to validate if the filesystem space was updated:
# df
Filesystem           1K-blocks     Used Available Use% Mounted on
/dev/dm-3              7222776   142580   6713560   3% /luks                             <<<<

Root Cause

  • LUKS finds its volume size only when it opens. Therefore you need to run cryptsetup resize so that LUKS rediscovers the volume size after you extend the size of the backing device of the LUKS volume.

  • Otherwise, follow the steps documented in this knowledge base article.

Category
Tags

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.