Sunday, August 2, 2020

File system extend on LUKS encrypted file system

File system extend on LUKS

encrypted file system


Scenario: I have run CentOS 7 server with the LVM and LUKS encrypted partitions. Java based application runs on the server with tomcat and mariadb as back end applications. Alerting system has been notified 0% disk space left in the /var directory.

It has used separate partition for /var, /home, /root, /var/log mount points. Thus the mission is to increase the /var file system while maintaining the same key for LUKS encryption.

Most important to understand is that you do not need consider about LUKS encryption as a separate domain since when you decrypt the LUKS encrypted partition it act like a normal file systems. When ever you extend the LVM partition it will automatically consider extended portion into the LUKS encryption. Yet, it is recommended to take backup of the data before do any changes to the file system or LVM.

Steps you need to follow in order to extend the file system are as follows.


  • If you does not mount the file system first it is required to mount the file system by giving the LUKS encrypted password. Optionally it is possible to use below commands to mount the file system. In our case since /var is mandate file system to run the OS it has already mounted.
         cryptsetup luksOpen /dev/centos/var var
  • To start the extending process of the file system first you required to add new physical volume.

         pvcreate /dev/sdb1

  • Then extend the Volume Group (vg)

    vgextend centos /dev/sdb1
  • Finally increase the Logical Volume (lv)
    
      lvextend -L +30G /dev/centos/var
      
  • Now you have completed the capacity extend on LVM, to complete the work it is required to resize the file system. Since /var directory is busy while the server in use, it is not possible to resize the /var file system on the fly. Thus it is required to boot the CentOS machine to “rescue target”. Otherwise no other ways which you can resize the file system in use. Once you boot the machine to rescue target run the below mention command.

         resize2fs -p /dev/centos/var ( For ext4 file system )

         xfs_growfs /dev/centos/var ( Foe xfs file system )

Now reboot the machine to boot to normal target.