Sub topic 7
Growing the ext4 or XFS filesystem
This chapter assumes you can use sudo, understand block devices and mount points, and have already extended a logical volume with lvextend. The logical volume is the storage container below the filesystem. Extending that container does not automatically make the filesystem use the new space.
A filesystem is the structure that organizes files and directories on a block device. Linux commonly uses ext4 or XFS on servers. Each filesystem has its own resize command.
The two layers you must grow
Storage growth usually has this order:
- Make space available in the volume group.
- Extend the logical volume.
- Grow the filesystem inside the logical volume.
- Verify the result from the mounted filesystem.
This chapter focuses on step 3. If you grow only the logical volume, lsblk may show a larger device while df still shows the old filesystem size.
A logical volume can be larger than the filesystem stored inside it. The unused part is not available to applications until the filesystem grows.
Identify the filesystem and mount point
Before resizing, confirm that the logical volume and mount point are the ones you intend to change. Do not guess the device name from memory.
findmnt /srv/data
lsblk -f
df -hT /srv/dataA possible findmnt result might identify /dev/vg_data/lv_app as the source and xfs as the filesystem type. The FSTYPE column from lsblk -f also shows whether the filesystem is ext4 or xfs.
The following table shows the argument each resize command expects:
| Filesystem | Command | Argument |
|---|---|---|
| ext4 | `resize2fs` | Logical volume device, such as `/dev/vg_data/lv_app` |
| XFS | `xfs_growfs` | Mounted filesystem path, such as `/srv/data` |
Check that the logical volume has already grown:
sudo lvs -o lv_name,vg_name,lv_size,lv_path
lsblkIf the LV still has its old size, stop and extend it first. Running a filesystem resize command cannot create capacity that the LV does not provide.
Growing an ext4 filesystem
resize2fs changes the size of an ext2, ext3, or ext4 filesystem. In the common online-growth case, the filesystem can remain mounted while it grows.
For the example LV mounted at /srv/data, run:
sudo resize2fs /dev/vg_data/lv_appWhen no size is supplied, resize2fs grows the filesystem to fill the available size of the block device. You can also provide a specific filesystem size, but filling the LV is usually the desired result after an LV extension.
After the command finishes, check the mounted filesystem:
df -hT /srv/dataThe df output is important because it reports the capacity available to applications. lsblk reports block-device sizes, which do not always equal usable filesystem space.
Growing an XFS filesystem
XFS supports growing a mounted filesystem. The xfs_growfs command uses the mount point rather than the LV device.
sudo xfs_growfs /srv/dataThe mount point must be active. If /srv/data is not mounted, the command cannot perform the normal XFS growth operation.
Verify the result:
df -hT /srv/dataXFS does not support shrinking. You can grow it later, but you cannot safely reduce its size in place. Plan the target size carefully before extending an XFS logical volume.
Common errors and their causes
The filesystem did not grow
If lvs shows a larger LV but df shows the old size, the filesystem resize step was skipped or failed. Run the correct filesystem-specific command, then check df again.
The wrong path was used
For ext4, use the block-device path:
sudo resize2fs /dev/vg_data/lv_appFor XFS, use the mounted directory:
sudo xfs_growfs /srv/dataUsing the wrong kind of path can produce an error or target something other than the intended filesystem.
The filesystem has no mount point
An XFS filesystem normally needs to be mounted for xfs_growfs. Find the expected mount point in /etc/fstab or mount the filesystem through the normal operational procedure. Do not mount an unknown device over a directory without confirming the device identity first.
The LV is not large enough
A resize command cannot exceed the block device size. If the filesystem tool reports that there is no additional space, compare:
sudo lvs /dev/vg_data/lv_app
lsblk -f /dev/vg_data/lv_app
df -hT /srv/dataThe LV must be extended before the filesystem can use new capacity.
A filesystem check is requested
Online growth is normally supported for ext4 and XFS, but a damaged filesystem is a separate problem. Do not force repair commands on a mounted production filesystem. Follow your distribution's maintenance procedure, take account of service availability, and ensure that a current backup exists.
A combined example
This example grows an ext4 filesystem after the LV has already been extended:
sudo lvs -o lv_path,lv_size /dev/vg_data/lv_app
sudo resize2fs /dev/vg_data/lv_app
df -hT /srv/dataFor XFS, replace the middle command:
sudo lvs -o lv_path,lv_size /dev/vg_data/lv_app
sudo xfs_growfs /srv/data
df -hT /srv/dataThe final df result should show a larger filesystem size and more available space. Applications using /srv/data can then use that capacity without changing their configuration.
Exercise
The LV /dev/vg_data/lv_app was extended successfully, and it is mounted at /srv/data with XFS. Which command grows the filesystem?
Show answer
Run sudo xfs_growfs /srv/data, then run df -hT /srv/data to verify the usable capacity.