Voiced by Amazon Polly
An Amazon EBS volume is a block-level storage device that can be attached to your instances. You can use it as you would use a physical hard drive. Moreover, EBS volumes are flexible, and you can dynamically increase size, modify the provisioned input/output operations per second (IOPS) capacity and change volume type on live production volumes.
This blog illustrates how to increase and decrease the size of EBS volume with a step-by-step instruction.
Increase the Size of EBS Volume
If you are familiar with Amazon EC2 and EBS volume, you might have experience modifying the size of EBS volume. AWS provides an easy way to increase the size of your EBS volume. In fact, we could increase it without detaching the volume or restarting the instance. That’s quite nice work done there because we would not need to have downtime for our instance.
Step 1: Go to the EC2 service in the AWS console and click on the server-specific volume by selecting the EC2 server > Storage > volume ID
Step 2: Select the Volume > Actions > Modify volume
Step 3: Modify the volume size by changing the Size value > click Modify.
Extending OS file system
After you finish modifying the volume, you need to extend the OS file system to see your increased volume size. The example below is the command I used for Ubuntu OS.
Step 4: SSH into the server and check whether the storage disk space is allocated by using “lsblk” command. Your increased volume will be shown just above your current volume, e.g., xvda1 is your current volume with 10GB size and xvda with 15GB size.
Step 5: Extend the partition by typing: sudo growpart /dev/xvda 1.
Note: Here dev/xvda denotes the partition name and 1 denotes the partition number.
Further, extend the volume by typing: sudo resize2fs /dev/xvda1
Now let us check the EBS size allocated to our server by using the “lsblk” command.
Hence, we have increased the EBS volume from 10GB to 15GB.
Helping organizations transform their IT infrastructure with top-notch Cloud Computing services
- Cloud Migration
- AIML & IoT
Decrease the Size of EBS Volume
In the previous task we have learned about increasing our EBS volume size. You might be wondering, can we decrease EBS volume size? The answer is NO. It is impossible to decrease EBS volume size. When you have 100GB EBS and you decide to modify it into 30GB you will get error: The size of a volume can only be increased, not decreased. That’s terrible …
But don’t worry. We could also do the trick to decrease EBS volume size. However, it is not easy task as it is not straightforward.
Here is the trick:
- Snapshot the volume
- Create a new smaller EBS volume
- Attach the new volume
- Format the new volume
- Mount the new volume
- Copy data from old volume to the new volume
- Prepare the new volume
- Detach and unmount old volume
Assume we have:
- Instance named “my-instance” in “ap-south-1a” zone
- 30GB EBS volume size named “old-volume”
- We wish to decrease into 10GB and name it “new-volume.”
We would need to stop the instance to prevent inconsistencies.
Step 1: Stop the EC2 Instance and create a new EBS volume with desired storage (In our case it is 10GB) in the same availability zone. Name it as “new-volume.”
Step 2: Attach the new EBS volume to the Instance, start the Instance and SSH into the instance.
Step 3: Mount the new volume
- Create filesystem for new EBS volume by using the command: sudo mkfs -t ext4 /dev/xvdf
- Create a directory to mount using the command: sudo mkdir /mnt/new-volume
- Mount new volume into the directory using the command: sudo mount /dev/xvdf /mnt/new-volume
- Check volume with the command: “df -h”
- The new volume should be successfully mounted now.
Step 4: Copy data from the old volume to the new volume.
Use rysnc to copy from the old volume to the new volume “sudo rsync -axv / /mnt/new-volume/”
Relax and wait until it is finished. Get a coffee!
Step 5: Prepare the new volume.
- Install grub on new-volume using the command: sudo grub-install –root-directory=/mnt/new-volume/ –force /dev/xvdf
- Unmount new-volume with the following command sudo umount /mnt/new-volume
- Check UUID using command: blkid
- Copy UUID from /dev/xvda1 (paste anywhere to backup this UUID); This is your old UUID.
- Use tune2fs to replace UUID “sudo tune2fs -U COPIED_UUID /dev/xvdf” COPIED_UUID is the string value from point 4.
- Check the system label from old-volume using command “sudo e2label /dev/xvda1” It will display string like cloudimg-rootfs
- Replace new-volume label with old-volume label using command “sudo e2label /dev/xvdf cloudimg-rootfs”
- We can logout SSH now.
Step 6: Detach old volume
- Stop instance my-instance
- Detach old-volume
- Detach new-volume
- Attach new-volume to /dev/sda1
- Start instance my-instance
After we finish all steps above, we could check our instance by login into SSH.
We could delete old-volume and snapshot-old-volume if our system works correctly. I prefer to keep snapshot for a week / month before deleting it.
AWS provide a straightforward method to increase the volume size of EBS. We need to extend the OS file system to see the changes. We cannot straightforward decrease the size of EBS volume. All we can do is to create a new smaller volume and transfer all the data from old volume to new volume and make new volume as root volume.
Hope it’s help!
Get your new hires billable within 1-60 days. Experience our Capability Development Framework today.
- Cloud Training
- Customized Training
- Experiential Learning
CloudThat is also the official AWS (Amazon Web Services) Advanced Consulting Partner and Training partner and Microsoft gold partner, helping people develop knowledge of the cloud and help their businesses aim for higher goals using best in industry cloud computing practices and expertise. We are on a mission to build a robust cloud computing ecosystem by disseminating knowledge on technological intricacies within the cloud space. Our blogs, webinars, case studies, and white papers enable all the stakeholders in the cloud computing sphere.
Drop a query if you have any questions regarding EBS Volume in EC2 and I will get back to you quickly.
To get started, go through our Consultancy page and Managed Services Package that is CloudThat’s offerings.
1. What is EBS volume in AWS?
ANS: – An Amazon EBS volume is a durable, block-level storage device that you can attach to your instances.
2. Which EBS volume is best?
ANS: – AWS Elastic Block Store (EBS) is Amazon’s block-level storage solution used with the EC2 cloud service to store persistent data. That means the data is stored on the AWS EBS servers even if the EC2 instances are shut down.
Click to Comment