How To Online/Offline Resize a ext3/4 filesystem on a Redhat Linux VM


How to do a Filesystem Resize (ext3/ext4) on Redhat running on VMware
A filesystem resize can be done in several ways, online, offline, with LVM or without LVM. This document will describe two different scenarios.
1.    An online resize of ext3/ext4 filesystem where a virtual disk (vmdk) is online added to a VMware Redhat guest OS
2.    An offline resize of ext3/ext4 in a VMware Redhat guest OS where a virtual disk (vmdk) is resized/expanded on the ESXi host
So let’s start with an online filesystem resize of ext3/4 filesystems on the Redhat guest OS. A new disk (eagerd zero thick) was added as a prerequirement. The whole procedure in this document is described by using the command line only.
There is also a graphical user interface `system-config-lvm` that can perform the job, but that tool is out of scope in this document.
Online resize a ext3/4 filesystem
There are several steps that have to be done. These are in general:
  1. Scanning for new LUN’s
  2. Partition the new LUN’s and partprobe
  3. Create the physical volume
  4. Extend the volume group and the logical volume
  5. Extend the filesystem online
Rescan for new LUN's
Depending on the number of virtual controllers, you have to scan for your new LUN's on each of these. In case you know on which the disk was added, then of course, you need to scan only the appropriate one.
Rescan for new LUN's on the first SCSI Controller (LSI Logic Parallel)
# echo "- – -" > /sys/class/scsi_host/host0/scan*
Rescan for new LUN's on the second SCSI Controller (Paravirtualized)
# echo "- – -" > /sys/class/scsi_host/host1/scan*
Create a Primary Partion on the new devices
# fdisk /dev/sdx??
# fdisk /dev/sdy??
Partprobe the new devices
Partprobe is a program that informs the operating system kernel of partition table changes, by requesting that the operating system re-read the partition table.
# partprobe /dev/sdx??
# partprobe /dev/sdy??
Create the Pysical Volumes
# pvcreate /dev/sdx??
Physical volume "/dev/sdx??" successfully created
# pvcreate /dev/sdy??
Physical volume "/dev/sdy??" successfully created
Extend the Volume Group
# vgextend VGOracle /dev/sdx??
Volume group "VGOracle" successfully extended
# vgextend VGOracle /dev/sdy??
Volume group "VGOracle" successfully extended
Extend the Logical Volume
# lvextend -L 72G /dev/VGOracle/LVOracleu??
Extending logical volume LVOracleu?? to 72.00 GB
Logical volume LVOracleu01 successfully resized
Online Resize the ext3/ext4 Filesystem
After the logical volume is resized successfully, you can resize, in fact any filesystem that is online resizable. The following are examples for the ext3/ext4 filesystems.
# resize2fs /dev/VGOracle/LVOracleu??
# resize4fs /dev/VGOracle/LVOracleu??
How to offline resize a ext3/4 filesystem
In this example, I show how to do an offline resize of a ext3/4 filesystem where a virtual disk was resized, instead of adding a new one. The only tricky part is changing the partition table of a physical volume.
The general steps are:
1.    Resize the virtual disk on the ESXi host for that particular VM
2.    Reboot the guest OS
3.    Fdisk with the new partion layout
4.    Partprobe or reboot
5.    Physical volume resize (pvresize)
6.    Logical volume resize (lvextend)
7.    Filesystem resize (resize2fs/4fs)
How to create a new Logical Volume
Create the Volume
# lvcreate -n LVOracleu?? -L 72G VGOracle
Logical volume "LVOracleu??" created
Create the Filesystem
# mkfs.ext3 -b 4096 -L u?? -m 0 /dev/VGOracle/LVOracleu??
# mkfs.ext4 -b 4096 -L u?? -m 0 /dev/VGOracle/LVOracleu??
Modify the /etc/fstab
/dev/VGOracle/LVOracleu??   /u??   ext3    defaults    0 0
/dev/VGOracle/LVOracleu??   /u??   ext3    defaults    0 0
/dev/VGOracle/LVOracleu??   /u??   ext4    defaults    0 0
/dev/VGOracle/LVOracleu??   /u??   ext4    defaults    0 0
From my point of view, the easiest way, if you want to online resize your ext3/ext4 filesystem on a virtual machine, is to add another virtual disk instead of resizing the available ones. A prerequirement is of course, that you are working with the LVM, and obviously you should not do the resize during peak load hours. J
Cheers, William (
This entry was posted in Linux, OS. Bookmark the permalink.

Leave a Reply