Ask Your Question
1

Extend a LUKS encrypted partition to fill disk

asked 2016-11-07 15:46:26 -0600

bouquetbouquet gravatar image

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
edit retag flag offensive close merge delete

Comments

easiest would be using blivet-gui from a Fedora Live system

florian gravatar imageflorian ( 2016-11-07 16:32:22 -0600 )edit

I looked into that tool but (afaik) you can't resize LUKS volumes with it.

EDIT: I looked closer and there is a resize capability. Either I'm doing it wrong or it doesn't work. I'll have to play with it some more. In any case, I'd rather use command line tools.

bouquetbouquet gravatar imagebouquetbouquet ( 2016-11-07 16:56:16 -0600 )edit

Thanks vtrefny! I'll give that a try later. I've been trying to unwrap the layers of this onion in a logic manner and I think I get it now. If you want some karma at stack exchange you can answer it there, too. http://unix.stackexchange.com/questio...

bouquetbouquet gravatar imagebouquetbouquet ( 2016-11-08 12:24:44 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2016-11-08 07:30:54 -0600

vtrefny gravatar image

You can't resize a PV that is part of an active VG. The easiest way here would be creating a new PV (another partition) and extended the VG (add the new PV to the VG). You'll have to resize the LVs after that, because this will just add an "extra" free space to the VG.

(You can do this using blivet-gui, or just via commandline using pvcreate and vgextend.)

edit flag offensive delete link more
0

answered 2016-11-11 10:12:17 -0600

bouquetbouquet gravatar image

updated 2016-11-11 10:30:12 -0600

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!

edit flag offensive delete link more

Comments

This worked perfectly - Frickin' thank you! I used Gparted in stead of Parted just 'cause it's less scary. And also by accident found I didn't need to Open the volume to do the parted operation.

BAI KC gravatar imageBAI KC ( 2019-02-05 09:16:07 -0600 )edit

Question Tools

Stats

Asked: 2016-11-07 15:46:26 -0600

Seen: 1,830 times

Last updated: Nov 11 '16