LVM volume space scaling in XFS format in centos7
Originally on my CentOS 7 virtual machine, I created 2 partitions:
sda1 for /boot
sda2 with 1 volume group “centos” with 5 logical volumes:
/
/home
/var
/tmp
swap
I noticed later that I had needed more space from /home lvm. It was 15GB, it was only using 1.5GB, so I decided to reduce it down to 5GB:
# lvreduce -L 5GB /dev/mapper/centos-home
It said successful so I rebooted.
Upon reboot, I was sent to emergency mode, and noticed /home was not listed under df, so I mounted everything in fstab but received an error:
#mount -a mount: /dev/mapper/centos-home: can't read superblock
So I ran an
# xfs_repair /dev/mapper/centos-home
It gave me same issues about not being able to read the superblock.
Oddly enough, the lvdisplay /dev/mapper/centos-home works and now shows LV Size as 5.00GB down from 15.00GB with all the other information listed…
This article describes the real-time process of adjusting the LVM volume space for xfs under centos7.
Actual purpose:
1. Reduce the logical volume /dev/mapper/home from 178G to 10G
2, empty 168G divided into logical volumes /dev/mapper/root
Actual process:
1, back up important data in advance, xfs reduction will lead to data loss
Backup can use xfsdump, data can also be backed up outside the machine (slightly here)
Unmount the volume /dev/mapper/home
[root@localhost ~]# umount /home
3, reduce the volume / dev / mapper / homesize (this step will lead to data loss, see the first point)
[root@localhost ~]# lvreduce -L 5G /dev/mapper/home
WARNING: Reducing active logical volume to 10.00 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce cl/home? [y/n]:y
Size of logical volume cl/home changed from 178.25 GiB (45633 extents) to 10.00 GiB (2560 extents).
Logical volume cl/home successfully resized.
4, increase the volume /dev/mapper/root size
[root@localhost ~]# lvextend -l +100%FREE /dev/mapper/root
Size of logical volume cl/root changed from 50.00 GiB (12800 extents) to 218.26 GiB (55874 extents).
Logical volume cl/root successfully resized.
5, adjust the xfs file system size
[root@localhost ~]# xfs_growfs /dev/mapper/root
6, re-mount, restore data
If you directly mount an error message:
[root@localhost ~]# mount /dev/mapper/home/home/
Mount: /dev/mapper/home: can’t read superblock
Need to format first
[root@localhost ~]# mkfs.xfs -f /dev/mapper/home
Mount after formatting:
[root@localhost ~]# mount /dev/mapper/home/home/
Recover data after mounting
This step can be used xfsrestore, or manually copy (refer to the first point)
$lvremove -v /dev/centos/home
Which returned the remaining free space to the volume group.
I then used the $lvextend to extend the /root lv
$lvextend -L +900G /dev/centos/root
And
$xfs_growfs /dev/centos/root
Recent Comments