注意:
做lvm缩小很危险,做之前最好备份下重要数据。
一、现状
逻辑卷test及使用状况如下
[root@node4 ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
test test -wi-ao---- 10.00g
lv_root vg_centos -wi-ao---- 17.57g
lv_swap vg_centos -wi-ao---- 1.94g
[root@node4 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_centos-lv_root
18G 1.1G 16G 7% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/sda1 477M 48M 404M 11% /boot
/dev/mapper/test-test
9.8G 37M 9.2G 1% /mnt
[root@node4 mnt]# ll
总用量 20
drwx------. 2 root root 16384 12月 1 02:50 lost+found
drwxr-xr-x. 2 root root 4096 12月 1 02:52 ssh
二、目的
将 test 缩小为5G 首先确保test 卷组使用情况没有超过5G
三、操作
接下来开始进行缩小
首先 ext4 不支持在线缩小 所以要先卸载卷组
[root@node4 ~]# umount /dev/test/test
若无法正常卸载 可以使用强制卸载
[root@node4 ~]# umount -l /dev/test/test
接下来检查磁盘
[root@node4 ~]# e2fsck -f /dev/mapper/test-test
e2fsck 1.41.12 (17-May-2010)
第一步: 检查inode,块,和大小
第二步: 检查目录结构
第3步: 检查目录连接性
Pass 4: Checking reference counts
第5步: 检查簇概要信息
/dev/mapper/test-test: 21/655360 files (0.0% non-contiguous), 83159/2621440 blocks
缩小分区
[root@node4 ~]# resize2fs /dev/mapper/test-test 5G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/test-test to 1310720 (4k) blocks.
The filesystem on /dev/mapper/test-test is now 1310720 blocks long.
重新设置lv大小
[root@node4 ~]# lvresize -L 5G /dev/mapper/test-test
WARNING: Reducing active logical volume to 5.00 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce test? [y/n]: y
Size of logical volume test/test changed from 10.00 GiB (2560 extents) to 5.00 GiB (1280 extents).
Logical volume test successfully resized
四、验证
[root@node4 mnt]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
test test -wi-ao---- 5.00g
lv_root vg_centos -wi-ao---- 17.57g
lv_swap vg_centos -wi-ao---- 1.94g
挂载lv 并查看数据
[root@node4 ~]# mount /dev/mapper/test-test /mnt
[root@node4 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_centos-lv_root
18G 1.1G 16G 7% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/sda1 477M 48M 404M 11% /boot
/dev/mapper/test-test
4.8G 21M 4.6G 1% /mnt
[root@node4 mnt]# ll
总用量 20
drwx------. 2 root root 16384 12月 1 03:31 lost+found
drwxr-xr-x. 2 root root 4096 12月 1 03:32 ssh
至此 lvm缩小到此结束。