Resizing an LVM PV + LUKS volume on a live Fedora 23 system

I just installed Fedora 23 on a new laptop, happily clicking my way through the GUI installer.  The installer very nicely partitioned my disks to a small boot partition, and a larger LUKS-encrypted volune, and created an LVM PV from that LUKS-encrypted volume, then carved out several LVs for /, /home, etc.  Everything is up and running within 15 minutes, and I’ve started copying over my files from my old laptop.

Then … I decide to create a new LV to hold my VM images, and suddenly realize I forgot to tell the installer to use all available storage for my PV!  I see this:

fdisk -l
 Disk /dev/sda: 238.5 GiB, 256060514304 bytes, 500118192 sectors
 ...
 Device Boot Start End Sectors Size Id Type
 /dev/sda1 * 2048 1026047 1024000 500M 83 Linux
 /dev/sda2 1026048 226492415 225466368 107.5G 83 Linux

I have around 120GB of space where I could create a new PV … but I really want a single PV of 238 GiB.  And heck, this is a new laptop install, worst case is everything blows up and I lose an hour.

Fixing this was surprisingly easy!

** These steps may very well delete any and all data on your hard drive, and render your system unable to boot.  If you value your data, make backups.  Proceed with caution **

Adjust the partition boundary using fdisk

# fdisk /dev/sda

Welcome to fdisk (util-linux 2.27.1).
...
Command (m for help): p
Disk /dev/sda: 238.5 GiB, 256060514304 bytes, 500118192 sectors
...
/dev/sda1 * 2048 1026047 1024000 500M 83 Linux
/dev/sda2 1026048 226492415 225466368 107.5G 83 Linux

Command (m for help): d 
Partition number (1,2, default 2): 2

Partition 2 has been deleted.

Command (m for help): n
Partition type
 p primary (1 primary, 0 extended, 3 free)
 e extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 
First sector (1026048-500118191, default 1026048): 
Last sector, +sectors or +size{K,M,G,T,P} (1026048-500118191, default 500118191): 

Created a new partition 2 of type 'Linux' and of size 238 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.

# partprobe -s
/dev/sda: msdos partitions 1 2

Adjust the LUKS volume size

cryptsetup resize luks-a522aeb6-2526-4868-82ba-c36b01dc5d53

Adjust the LVM PV size

# pvscan
PV /dev/mapper/luks-a522aeb6-2526-4868-82ba-c36b01dc5d53 VG fedora lvm2 [107.51 GiB / 8.00 MiB free]
Total: 1 [107.51 GiB] / in use: 1 [107.51 GiB] / in no VG: 0 [0 ]

# pvresize /dev/mapper/luks-a522aeb6-2526-4868-82ba-c36b01dc5d53
Physical volume "/dev/mapper/luks-a522aeb6-2526-4868-82ba-c36b01dc5d53" changed
1 physical volume(s) resized / 0 physical volume(s) not resized

# pvscan
PV /dev/mapper/luks-a522aeb6-2526-4868-82ba-c36b01dc5d53 VG fedora lvm2 [237.98 GiB / 130.48 GiB free]
Total: 1 [237.98 GiB] / in use: 1 [237.98 GiB] / in no VG: 0 [0 ]

And that’s it!  I now have a VG composed of a single PV occupying the entire drive!

Leave a comment