How to extend XFS LVM in Red Hat
In this procedure, I will explain how to extend an XFS logical volume in Red Hat.
Scenario: The Customer requires adding a 1TB LUN to a Production Linux Database server and extending the /data partition by 1TB. The LUN is located on an attached IBM XIV Storage Cluster. The server is a Virtual Machine running on VMware. The filesystem is XFS. Expand the volume, keeping all existing data intact.
How to extend a logical volume (LVM) on Red Hat Linux with XFS filesystem
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).
Step 1 – Create a VM Snapshot (Optional but Highly Recommended)
In my scenario, I will be working on a Linux Virtual Machine, which is hosted on a VMware cluster. Whatever your scenario, make sure you have some kind of snapshot or backup of the server.
Feel free to skip this bit if you don’t use virtualization.
Before changing disk configurations, it’s crucial to create a snapshot of your VM. This serves as a safety net, allowing you to revert to the current state if anything goes wrong during the LVM expansion process.
How to take a snapshot
- VMware Center:
If using VMware products, Use either the vSphere Client (thick client) or the vSphere Web Client. Both offer snapshot functionality. Right-click on the virtual machine and Look for the option “Take Snapshot” or similar. - PowerCLI: If you’re comfortable with scripting, VMware’s PowerCLI provides a powerful way to automate snapshot creation (and many other tasks).
Here is a script to get you started:
Connect-VIServer -Server <your_vcenter_server_name> -User <username> -Password <password>
$vm = Get-VM -Name <your_vm_name>
New-Snapshot -VM $vm -Name <snapshot_name> -Description <snapshot_description> -Memory $true -Quiesce $true
- Replace
<snapshot_name>
with a descriptive name for your snapshot. - Replace
<snapshot_description>
with additional information (optional). -Memory $true
includes the VM’s memory state in the snapshot (optional).-Quiesce $true
attempts to ensure a consistent state of the VM’s file system (recommended if the VM has VMware Tools installed).
How to Take a Snapshot Using vSphere Web Client
- Log in to your vCenter Server.
- Locate your RHEL VM.
- Right-click on the VM and select “Snapshots” -> “Take Snapshot.”
- Provide a name and description for the snapshot.
- Choose the snapshot type (standard or quiesced).
- Click “Take Snapshot.”
Important Note: Taking a snapshot doesn’t guarantee 100% data recovery. It’s still a best practice to back up critical data regularly.
Step 2: Prepare Storage, SSH to VM, and Prep Disk
Next assign the disk resources to the virtual machine. You can see in the picture below I am assigning a new “hard disk 4” with 1024GB of storage.
Prepare Storage
- Edit VM Settings: Right-click the VM in the vCenter inventory and select “Edit Settings.
- “Expand Hard Disk: Locate the existing hard disk you want to expand and click it.
- Increase Capacity: Change the “Provisioned Size” to the desired new size (e.g., increase it by 1 TB).
- Click OK: Save the changes to the VM’s configuration.
SSH to Virtual Machine
- Open your SSH client.
- Connect to your RHEL VM’s IP address using your credentials.
- Once logged in, type:
sudo su -
- Enter your password when prompted.
Prep Disk
Now we need to ensure that the physical volume we attached before is being presented to the server.
sudo pvs
Review the output to identify the physical volume that needs to be extended. In the example below, you can see /dev/sdd1 is showing 1024GB in size. That is the volume I added previously.
Step 3: Identify and Partition the New Disk
- Locate the New LUN:
- Use
lsblk
orfdisk -l
to list all disks attached to the server. - The newly added disk will likely be the last one listed.
- Take note of its device name (e.g.,
/dev/sdb
,/dev/sdc
, etc.).
- Use
- Partition the Disk:
- Use fdisk to partition the disk
fdisk /dev/[device_name]
#Replace [device_name] with correct disk - for example fdisk /dev/sdd1
- Create a new partition:
- Press
n
(new partition) - Press
p
(primary partition) - Press
1
(partition number) - Press Enter twice to accept the default start and end cylinders.
- Press
- Set partition type:
- Press
t
- Press
L
to list partition types. - Type
8e
(Linux LVM) - Press Enter.
- Press
- Write changes:
- Press
w
to write changes and exit.
- Press
- Inform the kernel about the changes:
- Run
partprobe
to update the kernel’s partition table information.
- Run
partprobe
Step 4: Extend the LVM Volume Group and Logical Volume
- List Volume Groups:
- Run
vgs
to identify the volume group where your/data
logical volume resides.
- Run
vgs
- Extend the Volume Group:
vgextend [volume_group_name] /dev/[device_name]1
- Replace
[volume_group_name]
and[device_name]
with the correct values. - Extend the Logical Volume:
lvextend -L +[size] /dev/[volume_group_name]/data /dev/[device_name]1
- Replace
[size]
with the desired size increase (e.g.,+1T
for 1 Terabyte,+1000G
for 1000 Gigabytes).
Step 5: Resize the Filesystem
- Resize the XFS Filesystem:
xfs_growfs /data
- Verify the Changes:
- Run
df -h
to confirm the filesystem has been extended.
- Run
Step 6: Clean Up
- Delete the Snapshot:
- Go back to your vSphere Client/Web Client and delete the snapshot taken in Step 1. This frees up the storage space consumed by the snapshot.
Additional Tips:
- Error Handling:
If you encounter errors during thelvextend
step, try adjusting the size slightly (e.g.,-L +999G
instead of-L +1T
). - Alternative Filesystems:
If you’re using a different filesystem (e.g., ext4), use the appropriate resize command (e.g.,resize2fs
). - Documentation:
Always refer to the official Red Hat documentation for detailed instructions and troubleshooting.
Recent Comments