linux系统中逻辑卷缩容步骤

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

[root@iyoume03 ~]# lvscan
  ACTIVE            '/dev/rootvg/u01' [6.00 GiB] inherit
  ACTIVE            '/dev/rootvg/root' [<9.79 GiB] inherit
  ACTIVE            '/dev/datavg/U02' [2.00 GiB] inherit

2、查看挂载

[root@iyoume03 ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/rootvg-root  9.8G  8.5G  1.4G  87% /
devtmpfs                 2.0G     0  2.0G   0% /dev
tmpfs                    2.0G     0  2.0G   0% /dev/shm
tmpfs                    2.0G  9.5M  2.0G   1% /run
tmpfs                    2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/sda1                201M  143M   59M  71% /boot
/dev/mapper/rootvg-u01   6.0G  4.5G  1.6G  75% /u01
tmpfs                    396M  4.0K  396M   1% /run/user/42
tmpfs                    396M   20K  396M   1% /run/user/0
/dev/mapper/datavg-U02   4.0G  1.7G  2.4G  42% /U02

 

计划对LV  /dev/mapper/datavg-U02  缩容2G

3、解除挂载

[root@iyoume03 ~]# umount /U02

 

4、确认现在的mount情况

[root@iyoume03 ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/rootvg-root  9.8G  8.5G  1.4G  87% /
devtmpfs                 2.0G     0  2.0G   0% /dev
tmpfs                    2.0G     0  2.0G   0% /dev/shm
tmpfs                    2.0G  9.5M  2.0G   1% /run
tmpfs                    2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/sda1                201M  143M   59M  71% /boot
/dev/mapper/rootvg-u01   6.0G  4.5G  1.6G  75% /u01
tmpfs                    396M  4.0K  396M   1% /run/user/42
tmpfs                    396M   24K  396M   1% /run/user/0

 

lv /dev/mapper/datavg-U02 已不在

 

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

[root@iyoume03 ~]# e2fsck -f /dev/datavg/U02 
e2fsck 1.42.9 (28-Dec-2013)
ext2fs_open2: Bad magic number in super-block
e2fsck: Superblock invalid, trying backup blocks...
e2fsck: Bad magic number in super-block while trying to open /dev/datavg/U02

The superblock could not be read or does not describe a correct ext2
filesystem.  If the device is valid and it really contains an ext2
filesystem (and not swap or ufs or something else), then the superblock
is corrupt, and you might try running e2fsck with an alternate superblock:
    e2fsck -b 8193 <device>

 

6、重置逻辑卷lv2大小

[root@iyoume03 ~]# resize2fs /dev/datavg/U02 2G
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/datavg/U02
Couldn't find valid filesystem superblock.

 

7、将逻辑卷/dev/datavg/U02 缩容2G

[root@iyoume03 ~]# lvreduce -L 2G /dev/datavg/U02 
  WARNING: Reducing active logical volume to 2.00 GiB.
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce datavg/U02? [y/n]: y
  Size of logical volume datavg/U02 changed from 4.00 GiB (1024 extents) to 2.00 GiB (512 extents).
  Logical volume datavg/U02 successfully resized.

 

8、重新挂载 /dev/datavg/U02

[root@iyoume03 ~]# mount /dev/datavg/U02 /U02

 

扩容2G

[root@iyoume03 ~]# lvextend -L +2G /dev/datavg/U02
  Size of logical volume datavg/U02 changed from 2.00 GiB (512 extents) to 4.00 GiB (1024 extents).
  Logical volume datavg/U02 successfully resized.

 

总结:逻辑卷缩容步骤

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

 

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

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

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

 

创建时间:2023-05-17 21:56
浏览量:0