关于rhel:RHEL-CentOS-系统减小-LVM-分区大小

8次阅读

共计 2133 个字符,预计需要花费 6 分钟才能阅读完成。

有时,当咱们在 linux 零碎中耗尽磁盘空间时,如果分区是在 LVM 上创立的,那么咱们能够通过应用 lvreduce 命令放大 LVM 在卷组中腾出一些闲暇空间。

在本指南中,咱们将学习如何在 RHEL 和 CentOS 零碎中缩小或放大 LVM 分区大小。

留神: 这些步骤仅实用于应用基于 LVM 的分区并格式化为 ext4 或 ext3 的状况。

假如咱们想缩小 /home 2GB(LVM 分区,EXT4 格局)

[root@cloud ~]# df -h /home/
 Filesystem            Size  Used Avail Use% Mounted on
 /dev/mapper/vg_cloud-LogVol00
                       12G   9.2G  1.9G  84%  /home

(1) 卸载文件系统

应用上面的 umount 命令卸载文件系统

[root@cloud ~]# umount /home/

(2) 查看文件系统是否有谬误

执行 e2fsck 命令查看文件系统是否存在谬误。当应用 -f 标记时,即便文件系统曾经被清理,它也会强制查看或扫描文件系统。

[root@cloud ~]# e2fsck -f /dev/mapper/vg_cloud-LogVol00
 e2fsck 1.41.12 (17-May-2010)
 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/mapper/vg_cloud-LogVol00: 12/770640 files (0.0% non-contiguous), 2446686/3084288 blocks

(3) 放大 /home 到指定尺寸

As shown in the above scenario, size of /home is 12 GB , so by reducing it by 2GB , then the size will become 10GB. Run the following resize2fs command followed by the file system and size.

/home 大小为 12GB,通过将其缩小 2GB,而后大小将变为 10GB。运行以下 resize2fs 命令

[root@cloud ~]# resize2fs /dev/mapper/vg_cloud-LogVol00 10G
 resize2fs 1.41.12 (17-May-2010)
 Resizing the filesystem on /dev/mapper/vg_cloud-LogVol00 to 2621440 (4k) blocks.
 The filesystem on /dev/mapper/vg_cloud-LogVol00 is now 2621440 blocks long.

(4) 应用 lvreduce 命令升高 LVM 尺寸

执行以下 lvreduce 命令

[root@cloud ~]# lvreduce -L 10G /dev/mapper/vg_cloud-LogVol00
 WARNING: Reducing active logical volume to 10.00 GiB
 THIS MAY DESTROY YOUR DATA (filesystem etc.)
 Do you really want to reduce LogVol00? [y/n]: y
 Reducing logical volume LogVol00 to 10.00 GiB
 Logical volume LogVol00 successfully resized

(5) 查看文件系统中的谬误 (可选)

再次运行 e2fsck 命令,查看文件系统在减小大小后是否有谬误。

[root@cloud ~]# e2fsck -f /dev/mapper/vg_cloud-LogVol00
 e2fsck 1.41.12 (17-May-2010)
 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/mapper/vg_cloud-LogVol00: 12/648960 files (0.0% non-contiguous), 2438425/2621440 blocks

(6) 挂载文件系统并验证其大小

[root@cloud ~]# mount /home/
 [root@cloud ~]# df -h /home/
 Filesystem            Size  Used Avail Use% Mounted on
 /dev/mapper/vg_cloud-LogVol00
                       9.9G  9.2G  208M  98% /home

完满,下面的命令输入证实 /home 尺寸放大 2GB,当初新的文件系统大小为 10GB。

我的开源我的项目

  • course-tencent-cloud(酷瓜云课堂 – gitee 仓库)
  • course-tencent-cloud(酷瓜云课堂 – github 仓库)
正文完
 0