Linux LVM系列(二)lv缩容

简介:

声明:xfs文件系统不支持lv缩容,这里是ext4文件系统

首先看下现在的文件系统挂载和使用情况

[root@aiker01 ~]# df -hT               
Filesystem          Type      Size  Used Avail Use% Mounted on
/dev/mapper/cl-root xfs       8.6G  5.3G  3.4G  62% /
devtmpfs            devtmpfs  2.4G     0  2.4G   0% /dev
tmpfs               tmpfs     2.4G     0  2.4G   0% /dev/shm
tmpfs               tmpfs     2.4G  8.7M  2.4G   1% /run
tmpfs               tmpfs     2.4G     0  2.4G   0% /sys/fs/cgroup
/dev/mapper/cl-home xfs       4.0G   33M  4.0G   1% /home
/dev/mapper/cl-var  xfs       3.0G  159M  2.8G   6% /var
/dev/sda2           xfs       497M  132M  366M  27% /boot
/dev/mapper/vg1-lv1 ext4      5.9G   16M  5.6G   1% /mnt
tmpfs               tmpfs     479M     0  479M   0% /run/user/0
/dev/mapper/vg2-lv2 ext4      3.9G   16M  3.7G   1% /data
[root@aiker01 ~]# ll /mnt/
total 36
-rw-r--r-- 1 root root     9 Dec  7 02:26 1.txt
-rw-r--r-- 1 root root     9 Dec  7 02:26 2.txt
drwxr-xr-x 2 root root  4096 Dec  7 02:34 6
drwxr-xr-x 2 root root  4096 Dec  7 02:34 7
drwxr-xr-x 2 root root  4096 Dec  7 02:34 8
drwx------ 2 root root 16384 Dec  6 03:02 lost+found
[root@aiker01 ~]# cat /mnt/1.txt 
12345678

卸载掉lv1卷

[root@aiker01 ~]# umount /mnt/

设置lv卷大小
下面的做法经过试验是会报错的:

[root@aiker01 ~]# lvresize -L 2G /dev/vg1/lv1 
  WARNING: Reducing active logical volume to 2.00 GiB.
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vg1/lv1? [y/n]: 
  WARNING: Invalid input ''.
Do you really want to reduce vg1/lv1? [y/n]: y
  Size of logical volume vg1/lv1 changed from <5.99 GiB (1533 extents) to 2.00 GiB (512 extents).
  Logical volume vg1/lv1 successfully resized.
[root@aiker01 ~]# e2fsck -f !$
e2fsck -f /dev/vg1/lv1
e2fsck 1.42.9 (28-Dec-2013)
The filesystem size (according to the superblock) is 1569792 blocks
The physical size of the device is 524288 blocks
Either the superblock or the partition table is likely to be corrupt!
Abort<y>? y
[root@aiker01 ~]# e2fsck -f /dev/vg1/lv1
e2fsck 1.42.9 (28-Dec-2013)
The filesystem size (according to the superblock) is 1569792 blocks
The physical size of the device is 524288 blocks
Either the superblock or the partition table is likely to be corrupt!
Abort<y>? yes

正确的做法
刚才的错误可以修正回之前的大小:

[root@aiker01 ~]# lvresize -l 1533 /dev/vg1/lv1  
  Size of logical volume vg1/lv1 changed from <2.00 GiB (511 extents) to <5.99 GiB (1533 extents).
  Logical volume vg1/lv1 successfully resized.
[root@aiker01 ~]# resize2fs /dev/vg1/lv1 5.99G
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Invalid new size: 5.99G

[root@aiker01 ~]# e2fsck -f /dev/vg1/lv1         
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/lv1: 16/392448 files (0.0% non-contiguous), 45115/1569792 blocks
[root@aiker01 ~]# resize2fs /dev/vg1/lv1 4G 
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vg1/lv1 to 1048576 (4k) blocks.
The filesystem on /dev/vg1/lv1 is now 1048576 blocks long.

[root@aiker01 ~]# lvresize -L 4G /dev/vg1/lv1  #设置lv大小为4G
  WARNING: Reducing active logical volume to 4.00 GiB.
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vg1/lv1? [y/n]: y
  Size of logical volume vg1/lv1 changed from <5.99 GiB (1533 extents) to 4.00 GiB (1024 extents).
  Logical volume vg1/lv1 successfully resized.

[root@aiker01 ~]# !e2  #检查是lv有错误
e2fsck -f /dev/vg1/lv1 
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/lv1: 16/261632 files (0.0% non-contiguous), 36907/1048576 blocks
[root@aiker01 ~]# lvdisplay  /dev/vg1/lv1

--- Logical volume ---
  LV Path                /dev/vg1/lv1
  LV Name                lv1
  VG Name                vg1
  LV UUID                q6dAzJ-1dbC-2EoY-Fzcp-QqEE-enuU-FS5BLT
  LV Write Access        read/write
  LV Creation host, time aiker01, 2017-12-06 03:02:40 +0800
  LV Status              available
  # open                 0
  LV Size                4.00 GiB
  Current LE             1024
  Segments               3
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:4

    [root@aiker01 ~]# vgdisplay  /dev/vg1
    --- Volume group ---
  VG Name               vg1
  System ID             
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  23
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               0
  Max PV                0
  Cur PV                3
  Act PV                3
  VG Size               <5.99 GiB
  PE Size               4.00 MiB
  Total PE              1533
  Alloc PE / Size       1024 / 4.00 GiB
  Free  PE / Size       509 / <1.99 GiB
  VG UUID               dx3XD9-rQBV-QtBu-EebN-wgjI-CQcn-36iIbm

     [root@aiker01 ~]# mount /dev/vg1/lv1 /mnt/
[root@aiker01 ~]# ll /mnt/
total 36
-rw-r--r-- 1 root root     9 Dec  7 02:26 1.txt
-rw-r--r-- 1 root root     9 Dec  7 02:26 2.txt
drwxr-xr-x 2 root root  4096 Dec  7 02:34 6
drwxr-xr-x 2 root root  4096 Dec  7 02:34 7
drwxr-xr-x 2 root root  4096 Dec  7 02:34 8
drwx------ 2 root root 16384 Dec  6 03:02 lost+found
[root@aiker01 ~]# cat /mnt/1.txt 
12345678
[root@aiker01 ~]# df -hT
Filesystem          Type      Size  Used Avail Use% Mounted on
/dev/mapper/cl-root xfs       8.6G  5.3G  3.4G  62% /
devtmpfs            devtmpfs  2.4G     0  2.4G   0% /dev
tmpfs               tmpfs     2.4G     0  2.4G   0% /dev/shm
tmpfs               tmpfs     2.4G  8.7M  2.4G   1% /run
tmpfs               tmpfs     2.4G     0  2.4G   0% /sys/fs/cgroup
/dev/mapper/cl-home xfs       4.0G   33M  4.0G   1% /home
/dev/mapper/cl-var  xfs       3.0G  159M  2.8G   6% /var
/dev/sda2           xfs       497M  132M  366M  27% /boot
tmpfs               tmpfs     479M     0  479M   0% /run/user/0
/dev/mapper/vg2-lv2 ext4      3.9G   16M  3.7G   1% /data
/dev/mapper/vg1-lv1 ext4      3.9G   16M  3.7G   1% /mnt    

可以清楚的查看后lv1缩容后的大小,里面的文件并没有损坏。



本文转自 喵来个鱼 51CTO博客,原文链接:http://blog.51cto.com/m51cto/2048555,如需转载请自行联系原作者

相关文章
|
1天前
|
存储 Linux 5G
Linux 基于 LVM 逻辑卷的磁盘管理【简明教程】
这篇文章介绍了LVM(逻辑卷管理)如何提供灵活的磁盘管理方式,允许动态调整逻辑卷的大小而不会丢失数据。
Linux 基于 LVM 逻辑卷的磁盘管理【简明教程】
|
1月前
|
存储 监控 Linux
|
1月前
|
存储 Linux
在Linux中,LVM是什么?
在Linux中,LVM是什么?
|
1月前
|
存储 监控 Linux
在Linux中,如何使用LVM管理逻辑卷?
在Linux中,如何使用LVM管理逻辑卷?
|
2月前
|
存储 运维 Linux
Linux磁盘精准缩容:操作详解与技巧
在Linux系统管理中,有效的磁盘空间优化对于维护系统性能至关重要。本文将深入探讨如何在Linux环境下安全地进行磁盘缩容,帮助你合理调整存储资源,确保系统高效运行。跟随本篇的步骤,一起优化你的Linux系统磁盘空间!
Linux磁盘精准缩容:操作详解与技巧
|
1月前
|
存储 数据挖掘 Linux
在Linux中,LVM(逻辑卷管理)的主要优势是什么?如何扩展LVM卷?
在Linux中,LVM(逻辑卷管理)的主要优势是什么?如何扩展LVM卷?
|
1月前
|
Linux
【Linux逻辑卷全解】带你玩转linux LVM 逻辑卷
【Linux逻辑卷全解】带你玩转linux LVM 逻辑卷
|
4月前
|
运维 Linux 虚拟化
linux|磁盘管理工作|lvm逻辑管理卷的创建和使用总结(包括扩容,根目录扩容演示)
linux|磁盘管理工作|lvm逻辑管理卷的创建和使用总结(包括扩容,根目录扩容演示)
475 0
|
3月前
|
存储 Linux 存储虚拟化
46. 【Linux教程】逻辑卷与 LVM 介绍
46. 【Linux教程】逻辑卷与 LVM 介绍
37 0
|
4月前
|
存储 Linux 数据库
Linux中LVM逻辑盘卷管理
LVM (Logical Volume Manager) 是Linux系统中的一种存储管理工具,它将物理硬盘组织成物理卷(PV),然后将物理卷组合成卷组(VG),最后从卷组中创建逻辑卷(LV)。逻辑卷可以按需调整大小,跨越多个物理卷,提供更高的灵活性和可扩展性。LVM的主要优点包括: