linux在线缩小块命令,Linux 逻辑卷缩小

注意:

做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缩小到此结束。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值