Increase the root volume (Hard disk) of EC2 Linux running instance without restart - Step by step process
Asked Answered
S

2

17

Problem:

I have EC2 instance with Linux (Ubunty) and root volume of 10 GB. I have consumed about 96% of the size and now my application responding slow, so I wanted to increase the size to 50 GB.

The most important point is, I have data already there and many applications are running on this EC2 instance and I don't want to disturb or stop them.

To check the current space available ~$ df -hT

enter image description here

Please use ~$ lsblk command to check the partition size

Sandstorm answered 27/10, 2021 at 15:7 Comment(0)
S
38

Here is the solution:

  1. Take a snapshot of your volume which contains valuable data.

  2. Increase the EBS volume using Elastic Volumes

  3. After increasing the size, extend the volume's file system manually.

Details

1. Snapshot Process (AWS Reference)

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.

2) Increase the EBS volume using Elastic Volumes (AWS Reference)

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

  2. Choose Volumes, select the volume to modify, and then choose Actions, Modify Volume.

  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.

    enter image description here

  • 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

      enter image description here

    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

      enter image description here

    3. Use lsblk to check the partition size.

      enter image description here

Sandstorm answered 27/10, 2021 at 15:7 Comment(0)
H
0

For those who need to resize (and don't have the no restart limitation) Some images will automatically call resizefs during boot so resizing the root partition may simply require increasing the disk size and rebooting.

Highland answered 19/7 at 6:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.