How to resize /var on RHEL?

How to resize /var on RHEL?

Issue Description:

AI Center requires 200GB in the disk that /var/lib is mounted to. In most deployments /var will need to be resized.

Resizing the Logical Volume

  1. If using a cloud provider, check their documentation first to see if they already provide steps.
  2. To resize the volume, there must be space in the volume group:
    • To find what logical volume /var is using, run: lsblk -f
    • For example, below it is using rootvg-varlv:
└─sda4 LVM2_member vGS8hW-aVf9-zodD-zTyZ-WY5N-WOrr-Ync3oM
├─rootvg-tmplv xfs 8223ca3e-0846-4c6a-baac-2a072a757b25 /tmp
├─rootvg-usrlv xfs 49a57fef-cb55-48c3-9f13-d746399a21c0 /usr
├─rootvg-optlv xfs f9642b48-7fd6-4439-983b-d22aef8402f4 /opt
├─rootvg-homelv xfs 1180a33f-3302-4241-9e4a-ac6783e082c2 /home
├─rootvg-varlv xfs c305c7b2-e4e2-43f2-ac12-fff2fdc1d517 /var
└─rootvg-rootlv xfs e7733fad-07d1-40d9-a250-e8b5a810da1e /
  1. Check to see if there is enough space in the volume group:
    • Run: vgdisplay
    • In the below example 5GB is free
--- Volume group ---
VG Name rootvg
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 11
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 6
Open LV 6
Max PV 0
Cur PV 2
Act PV 2
VG Size 95.01 GiB
PE Size 4.00 MiB
Total PE 24323
Alloc PE / Size 23040 / 90.00 GiB
Free PE / Size 1283 / 5.01 GiB
VG UUID PYavye-DC71-6d4z-avDV-fJyO-NsB4-5KoQIb
  1. If there is not enough space there are two options:
    1. Expand the underlying disk - See the section Expanding the Disk
    2. Add a new disk and add it to the volume group. See the section Adding a Disk to the Volume Group
  2. Once there is enough space, run the following command:
    • lvresize -r -L +G /dev/mapper/
    • In the example given, this would be: lvresize -r -L +150G /dev/mapper/rootvg-varlv
    • The '-r' automatically resizes the file system.

Adding a Disk to the Volume Group

  1. Identify the name of the volume group
    • Run the command vgdisplay
    • For example the volume group name was rootvg
  2. Identify the disk that should be added to the volume group:
    • Run: lsblk
    • An admin should be consulted regarding the disk where it should be added (as the raw disk cannot be used for this operation)
    • In the example being used, lsblk returned the following disk and the sdb1 partition was added to our volume group:
sdb 8:16 0 32G 0 disk
└─sdb1 8:17 0 32G 0 part
  1. Once the disk has been identified, it needs to be labeled as a volume group:
    • pvcreate /dev/
    • Example the command would be: pvcreate /dev/sdb1
  2. Extend the current volume group:
    • vgextend
    • Example: vgextend rootvg /dev/sdb1
  3. After the volume has been extended continue with the remaining step of resizing.

Expanding the Disk

  1. This is something that must first be done by the admin at the hypervisor level.
  2. After the disk is resized, the disk may need its partition expanded (not necessary if there was no partition)
To check if there is a partition run lsblk.
  1. In the below example, sdc does not have a partition.
sda 8:0 0 64G 0 disk
└─sda1 8:1 0 64G 0 part /mnt
sdb 8:16 0 256G 0 disk
├─sdb1 8:17 0 255.9G 0 part /
├─sdb14 8:30 0 4M 0 part
└─sdb15 8:31 0 106M 0 part /boot/efi
sdc 8:32 0 1023G 0 disk
└─DEMO-example 253:0 0 100G 0 lvm /mnt/example
  1. In this example, sda has a few partitions. If this disk was being expanded, the partition would also need to be expanded (the partition to expand would be sda4, since it is provisioned to the volume group).
sda 8:0 0 64G 0 disk
├─sda1 8:1 0 500M 0 part
├─sda2 8:2 0 500M 0 part
├─sda3 8:3 0 2M 0 part
└─sda4 8:4 0 63G 0 part
├─rootvg-tmplv 253:0 0 2G 0 lvm /tmp
├─rootvg-usrlv 253:1 0 10G 0 lvm /usr
├─rootvg-optlv 253:2 0 2G 0 lvm /opt
├─rootvg-homelv 253:3 0 1G 0 lvm /home
├─rootvg-varlv 253:4 0 73G 0 lvm /var
└─rootvg-rootlv 253:5 0 2G 0 lvm /
  1. If a partition is used, determine which partition to expand
    • Run: pvscan
    • In my environment pvscan returned the following:
PV /dev/sda4 VG rootvg lvm2 [<63.02 GiB / 0 free]
PV /dev/sdb1 VG rootvg lvm2 [<32.00 GiB / 5.01 GiB free]
  • Lets say that we were expanding the partition /dev/sda4
  • The end number is important as it identifies the partition.
  1. If a partition was used, expand the partition using the growpart command:
    • growpart
    • In our example the command would be growpart /dev/sda 4
  2. The physical volume needs to be resized:
    • pvresize
    • For example, in the given scenario this would be: pvresize /dev/sda4
    • If no partition was used, it would just be the disk name. (so for example: pvresize /dev/sdc)
  3. After the disk has been resized, continue the remaining steps of resizing.