Expand Amazon EBS Volume on EC2 Instance without Downtime

Need more storage for your EC2 instance but worried it might stop working during the upgrade? The good news is that increasing your storage won’t cause any downtime!

The only catch here is that you can’t accomplish this purely through the AWS console; it calls for a few extra steps. However, rest assured, these additional steps shouldn’t be too complicated.

Take a snapshot of EBS Volume (Optional)

While this step is optional, it is always recommended to take a backup if the volume upgrade doesn’t go as planned. Feel free to skip this step if you deem it unnecessary.

On AWS console, go to volumes page and select your volume. In my case, I have an 8 GiB EBS storage volume. Click on ‘Actions,’ and from the dropdown menu, select ‘Create snapshot.

Provide a description for your snapshot, and then click the ‘Create snapshot’ button.

You should now be able to view your newly created snapshot.

Expanding an EBS Volume Using the AWS Console

In the AWS console, go to the ‘Volumes’ section and choose the volume you wish to adjust. Next, click on ‘Modify volume’ from the ‘Actions’ dropdown menu.

Adjust the Size (GiB) to your desired value – for instance, let’s set it to 16 in this case. Once you’ve made the adjustment, go ahead and click ‘Modify.’

Note:

  • Downgrading your volume is not possible.
  • The minimum volume size allowed is 8 GiB.

 

There will be a pop-up notification prompting you to extend the file system, which is the next step we’ll be covering. Feel free to read through the information and then click ‘Modify’ to proceed.

The volume modification process will take some time. Importantly, there will be no downtime throughout this process, meaning your EC2 instance will remain running.

Once your volume state is “In-use” or have been completely modified, go ahead and proceed to the next steps.

Expanding a Linux File System After Resizing a Volume

Access your instance via SSH or use EC2 Instance Connect to run the following commands.

First lets’s check our current file system situation.

We have increased the volume size to 16 GiB but it still displaying as 8 GiB.

 

Next, let’s verify whether the volume has a partition.

We currently have a single 16 GiB disk with one partition of 8 GiB instead of 16 GiB, which isn’t the output we wanted. To resolve this, we’ll need to extend partition number 1.

Pay attention to the partition naming since they required different commands to be executed. In this case, we have xvda  which is Xen-based. If yours looks something like nvme0n1 , use the Nitro-based command.

Now, execute the following command to extend the partition.

For Xen-based:

For Nitro-based:

The output should look like the following.

 

Next, let’s check our partition again

Great, the partition 1 size has been upgraded to 16 GiB.

 

Now, let’s check our volume again.

Despite extending the partition, the size still displays as 8 GiB. Not to worry, let’s take note of our file system type, which in this case is xfs , and proceed to the next step.

After checking whether your file system type is xfs or ext4 , run the following command according to your file system type to extend the file system mounted on /.

For XFS file system:

For Ext4 file system Xen-based:

For Ext4 file system Nitro-based:

The output should looks like this.

 

Lastly, let’s verify our extended file system.

Now the file system of EBS Volume has been extended correctly.

If you encounter unexpected issues or the process doesn’t go as planned, you can refer to AWS documentation on extending Linux file system for troubleshooting guidance.

AWS Documentation : Extend a Linux file system after resizing a volume

Conclusion

Although expanding an EBS volume on EC2 instances can’t be done entirely through the AWS console, extending the file system is straightforward, and there’s no downtime. If you’re unsure, you can always refer to the easy-to-follow AWS documentation.

この記事が気に入ったら
いいね ! しよう

Twitter で
The following two tabs change content below.
アバター
Esar Suwandi
Software engineer based in Tokyo focused on Web Development. 4x AWS Certified: CLF, SAA, SAP, DOP. Let's build something awesome! ― Web開発に特化したソフトウェアエンジニアです。 4x AWS認定者です。素晴らしいものを作りましょう!

【採用情報】一緒に働く仲間を募集しています

採用情報
ページトップへ