linux系统中缩小逻辑卷

相较于扩容逻辑卷,在对逻辑卷进行缩容操作时,其丢失数据的风险更大。所以在生产环境中执行相应操作时,一定要提前备份好数据。另外linux系统规定,在对

LVM逻辑卷进行缩容操作之前,要先检查文件系统的完整性(为了数据安全)。在执行缩容之前先把文件系统卸载。

1、卸载逻辑卷设备的挂载

[root@linuxprobe 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   80K  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/vgtest1-lvtest1  287M  2.1M  266M   1% /linuxprobe
[root@linuxprobe dev]# umount /linuxprobe/  ## 卸载
[root@linuxprobe 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   80K  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

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

[root@linuxprobe dev]# e2fsck -f /dev/vgtest1/lvtest1
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/vgtest1/lvtest1: 11/76000 files (0.0% non-contiguous), 15759/307200 blocks

3、把逻辑卷lvtest1的容量缩小到100MB

[root@linuxprobe dev]# lvdisplay  ## 查看当前逻辑卷大小
  --- Logical volume ---
  LV Path                /dev/vgtest1/lvtest1
  LV Name                lvtest1
  VG Name                vgtest1
  LV UUID                oTCZoZ-CymC-Ce3k-JFGo-95ne-6lho-Y6a0Ll
  LV Write Access        read/write
  LV Creation host, time linuxprobe.com, 2020-10-29 16:30:51 +0800
  LV Status              available
  # open                 0
  LV Size                300.00 MiB
  Current LE             75
  Segments               1
  Allocation             inherit
………………
[root@linuxprobe dev]# resize2fs /dev/vgtest1/lvtest1 100M  ## 重置大小
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vgtest1/lvtest1 to 102400 (1k) blocks.
The filesystem on /dev/vgtest1/lvtest1 is now 102400 blocks long.

[root@linuxprobe dev]# lvreduce -L 100M /dev/vgtest1/lvtest1  ## 重置逻辑卷大小
  WARNING: Reducing active logical volume to 100.00 MiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lvtest1? [y/n]: y
  Reducing logical volume lvtest1 to 100.00 MiB

4、重新挂载

[root@linuxprobe 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   80K  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
[root@linuxprobe dev]# mount -a  ## 挂载
[root@linuxprobe 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   80K  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/vgtest1-lvtest1   93M  1.6M   85M   2% /linuxprobe
[root@linuxprobe dev]# lvdisplay ## 查看详细信息
  --- Logical volume ---
  LV Path                /dev/vgtest1/lvtest1
  LV Name                lvtest1
  VG Name                vgtest1
  LV UUID                oTCZoZ-CymC-Ce3k-JFGo-95ne-6lho-Y6a0Ll
  LV Write Access        read/write
  LV Creation host, time linuxprobe.com, 2020-10-29 16:30:51 +0800
  LV Status              available
  # open                 1
  LV Size                100.00 MiB
  Current LE             25
……………………
原文地址:https://www.cnblogs.com/liujiaxin2018/p/13897927.html