linux系统中逻辑卷缩容步骤

linux系统逻辑卷缩容的目的是压缩特定存储单元的大小,将磁盘空间腾出给卷组,其他逻辑卷可以从卷组中获取更多的存储资源

 

1、查看系统中当前的逻辑卷

[root@PC1linuxprobe dev]# lvscan
  ACTIVE            '/dev/rhel/swap' [2.00 GiB] inherit
  ACTIVE            '/dev/rhel/root' [17.51 GiB] inherit
  ACTIVE            '/dev/vg1/lv1' [100.00 MiB] inherit
  ACTIVE            '/dev/vg1/lv2' [500.00 MiB] inherit

 

2、查看挂载

[root@PC1linuxprobe dev]# df -h
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root   18G  2.9G   15G  17% /
devtmpfs               985M     0  985M   0% /dev
tmpfs                  994M  140K  994M   1% /dev/shm
tmpfs                  994M  8.9M  986M   1% /run
tmpfs                  994M     0  994M   0% /sys/fs/cgroup
/dev/sda1              497M  119M  379M  24% /boot
/dev/sr0               3.5G  3.5G     0 100% /run/media/root/RHEL-7.0 Server.x86_64
/dev/mapper/vg1-lv2    477M  2.3M  445M   1% /lvmounttest

 

将逻辑卷lv2缩容至300Mb

 

3、解除挂载

[root@PC1linuxprobe dev]# umount /lvmounttest/
[root@PC1linuxprobe dev]# df -h
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root   18G  2.9G   15G  17% /
devtmpfs               985M     0  985M   0% /dev
tmpfs                  994M  140K  994M   1% /dev/shm
tmpfs                  994M  8.9M  986M   1% /run
tmpfs                  994M     0  994M   0% /sys/fs/cgroup
/dev/sda1              497M  119M  379M  24% /boot
/dev/sr0               3.5G  3.5G     0 100% /run/media/root/RHEL-7.0 Server.x86_64

 

4、检查文件系统的完整性

[root@PC1linuxprobe dev]# e2fsck -f /dev/vg1/lv2
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vg1/lv2: 11/128016 files (0.0% non-contiguous), 26684/512000 blocks

 

5、重置逻辑卷lv2大小

[root@PC1linuxprobe dev]# resize2fs /dev/vg1/lv2 300M
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vg1/lv2 to 307200 (1k) blocks.
The filesystem on /dev/vg1/lv2 is now 307200 blocks long.

 

6、将逻辑卷lv2缩容至300Mb

[root@PC1linuxprobe dev]# lvreduce -L 300M /dev/vg1/lv2
  WARNING: Reducing active logical volume to 300.00 MiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv2? [y/n]: y
  Reducing logical volume lv2 to 300.00 MiB
  Logical volume lv2 successfully resized

 

7、挂载

[root@PC1linuxprobe dev]# mount /dev/vg1/lv2 /lvmounttest/
[root@PC1linuxprobe dev]# df -h
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root   18G  2.9G   15G  17% /
devtmpfs               985M     0  985M   0% /dev
tmpfs                  994M  140K  994M   1% /dev/shm
tmpfs                  994M  8.9M  986M   1% /run
tmpfs                  994M     0  994M   0% /sys/fs/cgroup
/dev/sda1              497M  119M  379M  24% /boot
/dev/sr0               3.5G  3.5G     0 100% /run/media/root/RHEL-7.0 Server.x86_64
/dev/mapper/vg1-lv2    283M  2.1M  262M   1% /lvmounttest

 

总结:逻辑卷缩容步骤

  • 解除逻辑卷挂载,示例:umount /mountpoint
  • 检查文件系统的完整性,示例:e2fsck -f /dev/vg1/lv2
  • 重置逻辑卷的大小,示例:resize2fs /dev/vg1/lv2 xxxM
  • 缩容逻辑卷,示例:lvreduce -L xxxM /dev/vg1/lv2
  • 挂载使用

 

注:逻辑卷缩容需要先检查文件系统的完整性,重置大小之后,才进行缩容  

逻辑卷扩容:卸载→扩容→检查完整性→重置大小→挂载使用

逻辑卷缩容:卸载→检查完整性→重置大小→缩容→挂载使用

 

posted @ 2020-11-08 18:32  小鲨鱼2018  阅读(1645)  评论(0编辑  收藏  举报