There are many advantages to using LVM to manage your disk partitions, one of which is how easy it is to extend the file system to use free space. I recently completed some work using crypto_luks encrypt a RHEL 7 vm, which used LVM to manage its disk partitions. Once I was finished, I noticed that one of the partitions was much too small. I originally tried to just extend the file system, which did not work because the partition was now encrypted, so I had to play around a bit until I figured out the process.
The first thing I did was check how much space I had left in my volume group, which I used pvs to do:

[root@image-resize-12 cache]# pvs
PV         VG      Fmt  Attr PSize     PFree
/dev/sdb   vg_encr lvm2 a--  <1023.00g <967.00g

As you can see, I had a ton of room to extend the partition. The next step I needed to take was to unmount the file system. More than likely when you try to unmount, you will get an error, “target is busy”. So you may need to check the processes running on said partition, using lsof:

[root@image-resize-12 ~]# umount /var
umount: /var: target is busy
[root@image-resize-12 ~]# lsof /var
COMMAND    PID    USER   FD   TYPE DEVICE SIZE/OFF    NODE NAME
dhclient  3139    root    4w   REG  253,9     5530 1923978 /var/lib/NetworkManager/dhclient-5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03-eth0.lease
atd       3389    root  cwd    DIR  253,9       31 2424326 /var/spool/at
omiserver 4216    root  cwd    DIR  253,9       49      81 /var/opt/omi/run
omiserver 4216    root    3w   REG  253,9        0 6465953 /var/opt/omi/log/omiserver.log

Now I will stop the services running, or even kill the process, and unmount the disk. The next step I took was to luksClose the partition I was trying to extend:

[root@image-resize-12 ~]# cryptsetup luksClose /dev/mapper/var

Now we can finally use lvexted to extend our partition:

[root@image-resize-12 ~]# lvextend -L+36G /dev/mapper/vg_encr-lv_var
Size of logical volume vg_encr/lv_var changed from 4.00 GiB (1024 extents) to 40.00 GiB (10240 extents).
Logical volume vg_encr/lv_var successfully resized.

So now that our encrypted partition is extended, we have to let crypto_luks know about the extra space:

[root@image-resize-12 ~]# cryptsetup --verbose resize /dev/mapper/var
Command successful.

Now, we must grow our file system. Since this was a RHEL 7 machine, our partitions had the xfs file system, so I used xfs_growfs for this. If you are not using the xfs file system, you can use resize2fs to grow the file system:

[root@image-resize-12 ~]# xfs_growfs /dev/mapper/var
meta-data=/dev/mapper/var        isize=512    agcount=4, agsize=262016 blks
=                       sectsz=512   attr=2, projid32bit=1
=                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=1048064, imaxpct=25
=                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
=                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 1048064 to 10485248

Finally, we check to see the file system has added the space, using df:

[root@image-resize-12 ~]# df -h
/dev/mapper/var      40G  641M   40G   2% /var

One thought to “Extending An Encrypted RHEL 7 LVM Partition”

  • Jon

    GREAT TIP!

    Reply

Leave a comment

Your email address will not be published. Required fields are marked *

X