Filesystems – Extend a LUKS Encrypted Partition to Fill Disk

filesystemsluks

I recently upgraded my disk from a 128GB SSD to 512GB SSD. The / partition is encrypted with LUKS. I'm looking for help extending the partition to use all the free space on the new disk. I've already dd'd the old drive onto the new one:

[root@localhost ~]# fdisk -l /dev/sda
Disk /dev/sda: 477 GiB, 512110190592 bytes, 1000215216 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x00009f33

Device     Boot   Start       End   Sectors   Size Id Type
/dev/sda1  *       2048   1026047   1024000   500M 83 Linux
/dev/sda2       1026048 250064895 249038848 118.8G 83 Linux

There's about 380GB of unused space after sda2.

More relevant info:

[root@localhost ~]# vgs
  VG             #PV #LV #SN Attr   VSize   VFree
  fedora_chocbar   1   3   0 wz--n- 118.75g 4.00m

[root@localhost ~]# lvs
  LV   VG             Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home fedora_chocbar -wi-a----- 85.55g                                                    
  root fedora_chocbar -wi-a----- 29.30g                                                    
  swap fedora_chocbar -wi-a-----  3.89g

[root@localhost ~]# pvs
  PV                    VG             Fmt  Attr PSize   PFree
  /dev/mapper/encrypted fedora_chocbar lvm2 a--  118.75g 4.00m

There seems to be a lot of info regarding how to do this, but very little explanation. I appreciate any help on this.

Best Answer

OK! The definitive answer finally. My steps to expand a LUKS encrypted volume...

  1. cryptsetup luksOpen /dev/sda2 crypt-volume to open the encrypted volume.
  2. parted /dev/sda to extend the partition. resizepart NUMBER END.
  3. vgchange -a n fedora_chocbar. Stop using the VG so you can do the next step.
  4. cryptsetup luksClose crypt-volume. Close the encrypted volume for the next steps.
  5. cryptsetup luksOpen /dev/sda2 crypt-volume. Open it again.
  6. cryptsetup resize crypt-volume. Will automatically resize the LUKS volume to the available space.
  7. vgchange -a y fedora_chocbar. Activate the VG.
  8. pvresize /dev/mapper/crypt-volume. Resize the PV.
  9. lvresize -l+100%FREE /dev/fedora_chocbar/home. Resize the LV for /home to 100% of the free space.
  10. e2fsck -f /dev/mapper/fedora_chocbar-home. Throw some fsck magic at the resized fs.
  11. resize2fs /dev/mapper/fedora_chocbar-home. Resize the filesystem in /home (automatically uses 100% free space)

I hope someone else finds this useful. I now have 300+GB for my test VMs on my laptop!

Related Question