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
……………………
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律