How to resize LVM logical volumes with ext4 as filesystem
Ever been in the situation where you needed to save some important
files to a server and your greeted with “Not enough space left on
device”-kind messages? No? Well, as that happened too often too me for
my liking, I decided to do it right this time when I set up my home
server and use logical volume manager (LVM) straight from the start. So
basically, all I had to do was to shrink a filesystem that had free
space in it and its partition (logical volume (LV) to be precisely)
afterwards and then to resize the logical volume/filesystem where I
needed the space.
As all the necessary tools are available normally on a system with LVM support, I could dive right in:
That was the tricky part. The rest is pretty straight forward:
As all the necessary tools are available normally on a system with LVM support, I could dive right in:
# Unmount the filesystem and check its' LV umount /mnt/foo e2fsck -f /dev/mapper/vg0-foo # Shrink ext4 and then the LV to the desired size resize2fs -p /dev/mapper/vg0-foo 40G lvreduce -L 40G /dev/mapper/vg0-foo # Before continuing, run e2fsck. If it bails because the partition # is too small, don't panic! The LV can still be extended with # lvextend until e2fsck succeeds, e.g.: # lvextend -L +1G /dev/mapper/vg0-foo e2fsck -f /dev/mapper/vg0-foo # Resize the filesystem to match the LVs size, check and mount it resize2fs -p /dev/mapper/vg0-foo e2fsck -f /dev/mapper/vg0-foo mount /mnt/foo |
- unmount the filesystem,
- extend the logical volume and
- expand the filesystem afterwards.
umount /mnt/bar # Extend the LV to use all free space lvextend -l +100%FREE /dev/mapper/vg0-bar e2fsck -f /dev/mapper/vg0-bar # Resize the partition to fill the LV resize2fs -p /dev/mapper/vg0-bar e2fsck -f /dev/mapper/vg0-bar mount /mnt/bar |
Nhận xét
Đăng nhận xét