How to extend XFS LVM in Red Hat
How to extend a logical volume (LVM) on Red Hat Linux with XFS filesystem
Scenario – Customer requires a 1TB LUN adding to a Production Linux Database server and the /data partition extending by 1TB. A Server is a Virtual Machine on VMware. The filesystem is XFS.
This is a very common task performed by Linux system administrators, but to others, this may seem a daunting task. The process may seem difficult but it’s not when you get your head around how Red Hat manages the filesystem and Logical Volumes (LVM)
- Take a snapshot of the VM to create a rollback point
- Log in to vCenter and locate the Virtual Machine. (preferably use the VMware Web Client)
- Right Click on the VM and select Edit Settings
- Add a new Hard Disk, set the size to 1TB, and type to your preference (My policy is to use Thick provision lazy zero)
- SSH to the VM or connect via the VMware Console.
- For ease of use, I will sudo -su to root : type sudo su –
- Type pvs to list the disks attached to the server
- Find the 1TB LUN you just added. it will usually be the last one on the list. make a note of the mount point (eg. /dev/sdd)
- Next work out how many volume groups you have: Type vgs
- Now, for my example, I will be using physical volume /dev/sdd and Volume Group VG01 as that is where /data resides
- type fdisk /dev/sdd (Amend to your physical volume if needed)
- This will open fdisk – note any changes you make here will not be committed to disk until you type W for write!
nto create a new disk partition,
pto create a primary disk partition,
1to denote it as 1st disk partition,
- Press ENTER twice to accept the default of 1st and last cylinder – to convert the whole secondary hard disk to a single disk partition,
t(will automatically select the only partition – partition 1) to change the default Linux partition type (0x83) to LVM partition type (0x8e),
Lto list all the currently supported partition type,
8e(as per the L listing) to change partition 1 to 8e, i.e. Linux LVM partition type,
pto display the secondary hard disk partition setup. Please take note that the first partition is denoted as /dev/hdb1 in Linux,
wto write the partition table and exit fdisk upon completion.
- type partprobe to query service partitions
- now to extend the volume group – type vgextend vg01 /dev/sdd1 (ensure you check your vg and sdd values)
- now to extend the logical volume – type lvextend +1T /dev/vg01/data /dev/sdd1 (ensure you check your vg and sdd values)
- if you get an error its possible the disk might not quite have 1TB, which is 1024gb – try lvextend -L +1000G /dev/vg01/data /dev/sdd1
- now to grow the filesystem – type xfs_growfs /data
- That’s it – all done, you can confirm by typing df -h
- Remember to delete the snapshot so your datastore does not fill up.