Académique Documents
Professionnel Documents
Culture Documents
in Linux
By Eric Zhiqiang Ma,
LVM is a great tool to manage hard disks on Linuxyou can abstract the hard drives away and manage
logical volumes from volume groups, you can dynamically add or remove hard drives while the file
systems on the logical volumes need not to backed up and recovered, and you may create many
snapshots of the logical volumes as you like. In this post, I will introduce how to extend a mounted
ext4 file system on a LVM logical volume on Linux.
This is a common situation that we may face: the file system such as the ext4 file system mounted to
/home on a logical volume we allocated is almost used up and we may want to add a new hard drive to
make it larger. LVM allows us achieve this easier.
In this post, I will use this example: we have a volume group vg from which a logical volume
lv_home is mounted to /home as an ext4 file system. Now, we have bought a new 1TB hard drive
and installed it (assume /dev/sdb) to the computer, and are to extend the capacity of the /home. The
steps are followed. All commands are executed as root or by sudo.
Before you move on following the steps, make sure you know what you are doing and back up all you
data.
Then, create a physical volume from /dev/sdb1 and extend the volume group vg by vgextend
(manual):
pvcreate /dev/sdb1
vgextend vg /dev/sdb1
You can check the volume groups by vgdisplay and see that vg is extended with the addition
capacity of around 931GB if everything goes well.
Note that this method also works for shrink the LV and file system size (bug with caution since it is a
more danger operation than extending the size). But for shrinking a LV, it is better to umount the file
system first to avoid data loss.
If it prints Logical volume lv_home successfully resized, it should be good now. You can use
lvdisplay to check the capacity of the logical volume.
Extend the ext4 file system
The resize2fs (manual) can resize an ext4 file system on-line to use all available disk capacity. We can
resize the /home mounted by:
resize2fs /dev/vg/lv_home
You can use df -hT to check the file systems available capacity and start to saving more files under
/home now.