无需重启即可增加 EC2 Linux 运行实例的根卷(硬盘) - 分步过程

Tar*_*han 13 linux amazon-ec2 hard-drive

问题:

我有使用 Linux (Ubunty) 的 EC2 实例和 10 GB 的根卷。我已经消耗了大约 96% 的大小,现在我的应用程序响应速度很慢,因此我想将大小增加到 50 GB。

最重要的一点是,我已经有数据了,并且许多应用程序正在这个 EC2 实例上运行,我不想打扰或停止它们。

检查当前可用空间 ~$ df -hT

在此输入图像描述

请使用~$ lsblk命令检查分区大小

Tar*_*han 32

这是解决方案:

  1. 拍摄包含有价值数据的卷的快照。

  2. 使用弹性卷增加 EBS 卷

  3. 增加大小后,手动扩展卷的文件系统。

细节

1. 快照流程(AWS参考

1) Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.   

2) Choose Snapshots under Elastic Block Store in the navigation pane.    

3) Choose Create Snapshot.   

4) For Select resource type, choose Volume.   

5) For Volume, select the volume.

6) (Optional) Enter a description for the snapshot.    

7) (Optional) Choose Add Tag to add tags to your snapshot. For each tag, provide a tag key and a tag value.    

8) Choose Create Snapshot.
Run Code Online (Sandbox Code Playgroud)

2)使用弹性卷增加EBS卷(AWS参考

  1. 打开 Amazon EC2 控制台https://console.aws.amazon.com/ec2/

  2. 选择卷,选择要修改的卷,然后选择操作、修改卷。

  3. The Modify Volume window displays the volume ID and the volume's current configuration, including type, size, IOPS, and throughput. Set new configuration values as follows:

    • To modify the type, choose a value for Volume Type.

    • To modify the size, enter a new value for Size.

    • To modify the IOPS, if the volume type is gp3, io1, or io2, enter a new value for IOPS.

    • To modify the throughput, if the volume type is gp3, enter a new value for Throughput.

  4. After you have finished changing the volume settings, choose Modify. When prompted for confirmation, choose Yes.

  5. Modifying volume size has no practical effect until you also extend the volume's file system to make use of the new storage capacity.

3) Extend the volume's file system manually (AWS Reference)

  1. To check whether the volume has a partition that must be extended, use the lsblk command to display information block devices attached to your instance.

    在此输入图像描述

  • The root volume, /dev/nvme0n1, has a partition, /dev/nvme0n1p1. While the size of the root volume reflects the new size, 50 GB, the size of the partition reflects the original size, 10 GB, and must be extended before you can extend the file system.

  • The volume /dev/nvme1n1 has no partitions. The size of the volume reflects the new size, 40 GB.

    1. For volumes that have a partition, such as the root volume shown in the previous step, use the growpart command to extend the partition. Notice that there is a space between the device name and the partition number.

      ~$ sudo growpart /dev/nvme0n1 1

      在此输入图像描述

    2. To extend the file system on each volume, use the correct command for your file system. In my case, I have ext4 filesystem, I will use the resize2fs command.

      ~$ sudo resize2fs /dev/nvme0n1p1

      在此输入图像描述

    3. Use lsblk to check the partition size.

      在此输入图像描述