vm扩展linux分区大小_如何在运行时扩大云Linux VM的根分区和文件系统大小而不重启Linux

vm扩展linux分区大小

It is common that the root disk space is not enough when running a Virtual Machine in the cloud such as Amazon Web Service (AWS). The cloud storage usually provides tools or facilities to enlarge a virtual disk size. However, to make the Linux recognize and and use the enlarged disks without rebooting the OS, some actions are needed. In this post, we will use Ubuntu 18.04 as one example, to show how to enlarge Linux root partition and filesystem sizes at runtime without rebooting Linux.

通常在云中运行虚拟机(例如Amazon Web Service(AWS))时,根磁盘空间不足。 云存储通常提供扩大虚拟磁盘大小的工具或设施。 但是,要使Linux在不重新引导OS的情况下识别并使用扩大的磁盘,则需要采取一些措施。 在本文中,我们将以Ubuntu 18.04为例,展示如何在运行时扩大Linux根分区和文件系统大小而无需重启Linux。

hard drive photo

Please note that filesystem and partitions resizing are dangerous operations and may lead to data lost. Please backup you data first before doing so by using snapshoting mechanism in the cloud service or using common backup tools.

请注意,文件系统和分区的大小调整是危险的操作,可能会导致数据丢失。 请先使用云服务中的快照机制或常用的备份工具备份数据,然后再备份。

Here is one example on a AWS EC2 node, named n8, which has 20GB root storage while it is almost used up as shown by df -hT:

这是一个名为n8的AWS EC2节点上的示例,该节点具有20GB的根存储,而df -hT所示该节点几乎用完了:

root@n8:/var/log# df -hT
Filesystem     Type      Size  Used Avail Use% Mounted on
udev           devtmpfs   16G     0   16G   0% /dev
tmpfs          tmpfs     3.1G  8.8M  3.1G   1% /run
/dev/nvme0n1p1 ext4       20G   20G  1.5M 100% /
tmpfs          tmpfs      16G     0   16G   0% /dev/shm
tmpfs          tmpfs     5.0M     0  5.0M   0% /run/lock
tmpfs          tmpfs      16G     0   16G   0% /sys/fs/cgroup
/dev/loop0     squashfs   88M   88M     0 100% /snap/core/5328
/dev/loop2     squashfs   17M   17M     0 100% /snap/amazon-ssm-agent/734
/dev/loop1     squashfs   88M   88M     0 100% /snap/core/5548
/dev/loop3     squashfs   13M   13M     0 100% /snap/amazon-ssm-agent/295
/dev/loop4     squashfs   13M   13M     0 100% /snap/amazon-ssm-agent/495
/dev/loop5     squashfs   87M   87M     0 100% /snap/core/5145
tmpfs          tmpfs     3.1G     0  3.1G   0% /run/user/1000

In the AWS Volume management console, we increased the size of the root partition disk to 100GB. Now, let’s look at the steps to add the storage to the root filesystem (/).

在AWS Volume Management控制台中,我们将根分区磁盘的大小增加到100GB。 现在,让我们看一下将存储添加到根文件系统( / )的步骤。

First, use growpart to grow the partition size. Here, the root partition is the partition number 1 of disk /dev/nvme0n1, we run the command:

首先,使用growpart增大分区大小。 在这里,根分区是磁盘/dev/nvme0n1的分区号1,我们运行以下命令:

root@n8:/var/log# growpart /dev/nvme0n1 1
CHANGED: partition=1 start=2048 old: size=41940959 end=41943007 new: size=209713119,end=209715167

From the STDOUT, the size has been changed.

在STDOUT中,尺寸已更改。

However, the filesystem size is still the same although the partition size changed. We need to update the filesystem to use the more storage capacity available.

但是,尽管分区大小已更改,但文件系统大小仍然相同。 我们需要更新文件系统以使用更多可用的存储容量。

We can sue the resizee2fs command as follows.

我们可以按如下方式起诉resizee2fs命令。

root@n8:/var/log# resize2fs /dev/nvme0n1p1
resize2fs 1.44.1 (24-Mar-2018)
Filesystem at /dev/nvme0n1p1 is mounted on /; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 13
The filesystem on /dev/nvme0n1p1 is now 26214139 (4k) blocks long.

After it executed successfully, we can check the filesystem size by df -hTgain.

成功执行之后,我们可以通过df -hT gain检查文件系统大小。

root@n8:/var/log# df -hT
Filesystem     Type      Size  Used Avail Use% Mounted on
udev           devtmpfs   16G     0   16G   0% /dev
tmpfs          tmpfs     3.1G  724K  3.1G   1% /run
/dev/nvme0n1p1 ext4       97G   20G   78G  20% /
tmpfs          tmpfs      16G     0   16G   0% /dev/shm
tmpfs          tmpfs     5.0M     0  5.0M   0% /run/lock
tmpfs          tmpfs      16G     0   16G   0% /sys/fs/cgroup
/dev/loop0     squashfs   88M   88M     0 100% /snap/core/5328
/dev/loop2     squashfs   17M   17M     0 100% /snap/amazon-ssm-agent/734
/dev/loop1     squashfs   88M   88M     0 100% /snap/core/5548
/dev/loop3     squashfs   13M   13M     0 100% /snap/amazon-ssm-agent/295
/dev/loop4     squashfs   13M   13M     0 100% /snap/amazon-ssm-agent/495
/dev/loop5     squashfs   87M   87M     0 100% /snap/core/5145
tmpfs          tmpfs     3.1G     0  3.1G   0% /run/user/1000

Now you can see the new root partition size is around 100GB now. Cheers.

现在您可以看到新的根分区大小现在约为100GB。 干杯。

翻译自: https://www.systutorials.com/how-to-enlarge-root-partition-and-filesystem-size-of-cloud-linux-vm-at-runtime-without-rebooting-linux/

vm扩展linux分区大小

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值