LVM series continues. If you want to start from the beginning, check our first post. You can review our last post, about EXT2/EXT3/EXT4 lvm management.
In this post, we are going to review how to manage an XFS filesystem over LVM.
For the exercises we will start with an LV called lv_xfsfssample in VG vg_storage1.
Formatting LV with XFS
Let’s format this LV with XFS filesystem.
mkfs.xfs /dev/vg_storage1/lv_xfsfssample
Mounting the filesystem
We will work with the filesystem mounted whenever is possible.
Usually it will be configured in fstab, but we are going to mount our filesystem manually in /mnt/temp.
mkdir /mnt/temp mount /dev/vg_storage1/lv_xfsfssample /mnt/temp
Increasing the size of the filesystem
This is one of the most important reasons to use LVM, to be able to modify the size of our volumes.
It is important to note that this process depends on the filesystem.
This is what we are about to do and the order we will follow:
- Make sure the VG has enough space.
- Increase the size of the LV.
- Resize the filesystem.
Checking VG free space
If you don’t know what VG you need to check, you can use tools such as df, lvdisplay or vgdisplay, as we saw in some of the last posts.
In our examples, our VG is vg_storage1, so you can check how much free space is available like this:
vgdisplay vg_storage1 | grep Free
If there is a free amount of space equal or bigger than the amount we want to increase, we can keep going with the process.
If there is not, you have to raise the storage in that VG or reduce some other LV to release space.
Increasing the size of the LV
The next step is to raise the size of the logical volume, we will do that with “lvextend“.
In this example, we will increase the size of lv_xfsfssample in 1 GB. Let’s remember that our filesystem is mounted in /mnt/temp, so there’s no need to unmount it, we can do this without affecting the service.
lvextend -L+1G /dev/vg_storage1/lv_xfsfssample
Resizing the filesystem
At this point, you can take a few minutes to check the size of the filesystem and the size of the LV. You will see that LV is 1 GB bigger than the filesystem.
So now we have to resize the filesystem to be able to use all the space available in the LV.
This can be done by using “xfs_growfs” tool.
Remember that we didn’t umount the filesystem, so we can do this online.
xfs_growfs /dev/vg_storage1/lv_extfssample
Now we have the filesystem using all available space in LV.
Decreasing the size of the filesystem
Unfortunately, we face a limitation with this filesystem. XFS cannot shrink or reduce.
If you need to reduce an XFS filesystem, you will have to workaround it. For instance:
- Make a backup, destroy the LV and create a new one with the correct size, format it and then restore the backup.
- Create another LV with the correct size, then format it and transfer the data from the original filesystem. Finally, delete the original LV and reconfigure the mount points as needed.
We will continue our LVM series with ReiserFS filesystem management.