linux lvm 扩展_在Linux中的LVM上扩展已安装的Ext4文件系统

linux lvm 扩展

LVM is a great tool to manage hard disks on Linux—you can abstract the hard drives away and manage logical volumes from volume groups, you can dynamically add or remove hard drives while the file systems on the logical volumes need not to backed up and recovered, and you may create many snapshots of the logical volumes as you like. In this post, I will introduce how to extend a mounted ext4 file system on a LVM logical volume on Linux.

LVM是在Linux上管理硬盘的绝佳工具-您可以将硬盘驱动器抽象出来并从卷组管理逻辑卷,可以动态添加或删除硬盘驱动器,而无需备份和恢复逻辑卷上的文件系统 ,并且您可以根据需要创建逻辑卷的许多快照。 在本文中,我将介绍如何在Linux的LVM逻辑卷上扩展已安装的ext4文件系统。

This is a common situation that we may face: the file system such as the ext4 file system mounted to /home on a logical volume we allocated is almost used up and we may want to add a new hard drive to make it larger. LVM allows us achieve this easier.

这是我们可能遇到的一种常见情况:诸如ext4文件系统之类的文件系统安装在分配给您的逻辑卷上的/ home上几乎用完了,我们可能想添加一个新的硬盘驱动器以使其更大。 LVM使我们更轻松地实现这一目标。

Please note that the methods here only works with a mounted filesystem if the resize_inode option active. The following command gives a line of output containing the resize_inode if it is enabled using /dev/vg/lv_home as an example (replace it with the path to you logical volume):

请注意,如果激活resize_inode选项,则此处的方法仅适用于已挂载的文件系统。 如果使用/dev/vg/lv_home作为示例,以下命令给出了包含resize_inode的输出行(将其替换为逻辑卷的路径):

# tune2fs -l /dev/vg/lv_home | grep resize_inode

If your filesystem does not have the resize_inode option active (a bit unusual, but possible), the filesystem needs to be unmounted first to be resized. (Thanks to Edward Kroeze for this note.)

如果您的文件系统没有激活resize_inode选项(这有点不寻常,但是可能),则需要先卸载该文件系统以进行大小调整。 (感谢爱德华·克罗兹的这份笔记。)

In this post, I will use this example: we have a volume group vg from which a logical volume lv_home is mounted to /home as an ext4 file system. Now, we have bought a new 1TB hard drive and installed it (assume /dev/sdb) to the computer, and are to extend the capacity of the /home. The steps are followed. All commands are executed as root or by sudo.

在本文中,我将使用此示例:我们有一个卷组vg ,逻辑卷lv_home从该卷组挂载到/home作为ext4文件系统。 现在,我们购买了一个新的1TB硬盘驱动器并将其安装(假定为/ dev / sdb)到计算机上,以扩展/home的容量。 遵循步骤。 所有命令均以root或sudo身份执行。

Before you move on following the steps, make sure you know what you are doing and back up all you data.

在继续执行以下步骤之前,请确保您知道自己在做什么并备份所有数据

用sdb扩展vg (Extend vg with sdb)

This section follows the tutorial from .

本节遵循以下教程

First, create a new partition sdb1 to have all the capacity from sdb by using specific commands in cfdisk:

首先,通过使用cfdisk中的特定命令,创建一个新分区sdb1以具有sdb的所有容量:

cfdisk /dev/sdb

Then, create a physical volume from /dev/sdb1 and extend the volume group vg by vgextend (vgextend manual):

然后,从/ dev / sdb1创建一个物理卷,并通过vgextendvgextend manual )扩展卷组vg

pvcreate /dev/sdb1
vgextend vg /dev/sdb1

You can check the volume groups by vgdisplay and see that vg is extended with the addition capacity of around 931GB if everything goes well.

您可以通过vgdisplay检查卷组,如果一切顺利的话,可以看到vg扩展了大约931GB的附加容量。

扩展LV和文件系统:快速自动的方法 (Extend the LV and filesystem: the quick and automatic way)

You can extend the logical volume and let the LVM tool automatically resize the file system by lvresize (lvresize manual):

您可以扩展逻辑卷,并让LVM工具通过lvresizelvresize manual )自动调整文件系统的大小:

lvresize --resizefs --size +931GB /dev/vg/lv_home

Note that this method also works for shrink the LV and file system size (bug with caution since it is a more danger operation than extending the size). But for shrinking a LV, it is better to umount the file system first to avoid data loss.

请注意,此方法也可用于缩小LV和文件系统的大小(请谨慎操作,因为它比扩展大小更危险,因此请谨慎操作)。 但是对于缩小LV,最好先挂载文件系统以避免数据丢失。

扩展LV和文件系统:手动方式 (Extend the LV and filesystem: the manual way)

In this manual way, we do it step by step.

通过这种手动方式,我们将逐步进行操作。

扩展逻辑卷 (Extend the logical volume)

Now, let’s extend the logical volume lv_home with the capacity from the new hard drive by lvextend (lvextend manual):

现在,让我们通过lvextendlvextend manual )使用新硬盘驱动器的容量扩展逻辑卷lv_home:

lvextend -L+931GB /dev/vg/lv_home

If it prints "Logical volume lv_home successfully resized", it should be good now. You can use lvdisplay to check the capacity of the logical volume.

如果打印“逻辑卷lv_home成功调整大小”,则现在应该很好。 您可以使用lvdisplay来检查逻辑卷的容量。

扩展ext4文件系统 (Extend the ext4 file system)

The resize2fs (resize2fs manual) can resize an ext4 file system on-line to use all available disk capacity. We can resize the /home mounted by:

的resize2fs( resize2fs手册 )可以联机调整ext4文件系统使用所有可用磁盘容量。 我们可以通过以下方式调整/home挂载的大小:

resize2fs /dev/vg/lv_home

It will prints output like follows if it executes successfully

如果执行成功,它将打印如下输出

resize2fs 1.42.9 (4-Feb-2014)
Filesystem at /dev/vg/lv_home is mounted on /home; on-line resizing required
old_desc_blocks = 18, new_desc_blocks = 77
The filesystem on /dev/vg/lv_home is now 319283200 blocks long.

You can use df -hT to check the file system’s available capacity and start to saving more files under /home now.

您可以使用df -hT检查文件系统的可用容量,并立即开始在/home下保存更多文件。

翻译自: https://www.systutorials.com/extending-a-mounted-ext4-file-system-on-lvm-in-linux/

linux lvm 扩展

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值