Running a company’s technical infrastructure often necessitates making changes in response to the shifting requirements of the industry. Thankfully, with the introduction of cloud computing, adapting your infrastructure has never been easier. These days, you can quickly add or remove resources as conditions dictate.
Historically, businesses’ storage capacity needs have fluctuated, and responding to these ever-changing needs has required regular attention. In the past, altering storage capacity typically meant expanding it—a tedious and time-consuming process. Recently, however, the use of EBS Volumes and its Elastic Volumes feature has made increasing capacity much easier.
This article will first examine AWS EBS volumes in general before looking at the processes involved with how to resize EBS volumes them for both Linux and Windows use cases.
Fortify your data backup strategy across every critical dimension—from security to disaster recovery to cost savings.
- Efficiency + Optimization
- Security + Control
- Orchestration + Visibility
AWS EBS Volumes: The Backbone of EC2
Amazon Elastic Block Store (EBS) provides a block storage solution designed for the EC2 instance. EBS is built for high durability as well as high availability (HA), which is ensured by the replication of data in various Availability Zones (AZs). EBS offers multiple volume types in order to fulfill various workload needs, from log processing to high-performance applications.
EBS can be easily backed up using Snapshots, which can later be used to restore data if needed. With encryption protecting your data in transit and at rest, EBS is a secure storage option for your cloud environment.
Resizing EBS: How to Grow a Volume
In the past, growing EBS volumes was a complex task that required multiple steps within Amazon, such as creating snapshots of your volumes and recreating new, larger volumes based on them. Alternatively, you could provision new volumes, along with creating partitions and file systems and copying data to them. This process was not a true volume resizing so much as a workaround that offloaded your data to larger capacity volumes. Thankfully, this process was replaced by a much more efficient one with the introduction of Elastic Volumes on AWS.
AWS EBS Elastic Volumes
EBS’ Elastic Volumes feature allows you to increase volume size while the volume is still in use, making the resizing process a lot easier and faster. Elastic Volumes also provides the option to completely change the volume type and adjust its performance—also without downtime.
Now, instead of provisioning new volumes to respond to a spike in demand or to adjust to a new workload need, you can simply modify the existing AWS EBS volume from the web console or the API. This means that you can go from general purpose (gp2) volumes to iops optimized (io1) volumes or throughput optimized (st1) volumes with just a few clicks, making storage management issues a thing of the past.
Before expanding the size of your EBS volume, it is a good idea to back up your data with an EBS snapshot. This way, if anything goes wrong, you can always restore the volume.
Resize EBS Volumes with Linux EC2 Instances
Say your company is running a production environment on an EC2 instance—perhaps a small application that doesn’t require many resources.
Since this application uses little storage, a small, 20GB general purpose AWS EBS volume has been employed.
As your business needs grow, you will likely need to add more AWS resources, making it necessary to grow your EBS volume to support more data. Needless to say, you would prefer to do this without any downtime. Let’s take a look at the steps you need to take to do this.
First, go to your volume and choose “Modify Volume” under “Actions.”
You are then given the option to change both the disk size and the volume type.
You can also switch to Provisioned IOPS SSD (io1), increase the size to 100GB, and have the IOPS set to 5000 if your requirements necessitate this step.
Remember that if you are resizing your root volume, you won’t be offered the option to change to Throughput Optimized HDD (st1) or Cold HDD (sc1).
Starting the EBS resizing process
In this example, we’ll extend the volume to 30GB and retain the volume type. To do this, adjust the values and start the resizing process by clicking on “Modify.” The volume will now begin the optimization process, which you can follow on the console.
The time it takes to optimize the volume depends on the volume’s size. In this case, the process took 7-8 minutes. After it was over, the volume state color turned green again, showing that the resizing was finalized.
After the volume has been extended, the EC2 instance and the system both need to be adjusted to adapt to the new size. Note that you can do this adjustment either as a root or a user with sudo privileges.
The first step in this process is checking the partition size with the code:
lsblk
The screenshot above shows that the volume has been extended; however, the primary partition is still at the volume’s original size. To expand the partition, use the command shown below. After you do so, you will see that the partition has grown to match the volume size.
growpart /dev/xvda 1
Note that, in the example screenshot above, there is a space between “/dev/xvda” and “1.” “1” refers to the partition number.
Checking the file system size
Use the code below to check the file system size.
df -h
In the screenshot below, you will notice that it is still only registering 20GB, even though both the volume and partition have been resized.
Before you start this process, make sure you know which file system you are working with. If you don’t already know, you can find out using the following command:
file -s /dev/xvd*
If you were using an ext4 (or even older ext2 or ext3) file system, you could extend it using the command.
resize2fs /dev/xvda1
In our case, since the file system is XFS, we have to rely on the “xfs_growfs” tool, which should already be in the system. If not, you can install it yourself as part of the “xfsprogs” package.
Using this, we can proceed to extend the file system to match the volume and the partition size of 30GB. We will target the “/”, since that is where “/dev/xvda1” has been mounted.
xfs_growf -d /
The volume is now fully resized and ready to be used. No downtime resulted from this process.
You can also extend the partition and file system size after you have already grown the volume on the AWS side by simply rebooting your instance. When the operating system comes back up, it will modify everything itself.
This will, of course, cause a small amount of downtime, but for smaller companies who don’t have dedicated DevOps engineers (or other people with Linux experience) on hand, this might be a good option.
EBS volume sizes and configurations still have some constraints (for example, their maximum volume size is 16TiB), due to the physics and arithmetic of block data storage. Additionally, AWS imposes their own limits. Make sure you visit the AWS documentation page for full details.
- Test volume resizing during low traffic periods: Even though Elastic Volumes allows resizing without downtime, it's best practice to test resizing operations during off-peak hours to minimize the impact of any unforeseen performance issues.
- Combine with Auto Scaling groups: When scaling EC2 instances dynamically, consider resizing EBS volumes tied to Auto Scaling groups. Use lifecycle hooks to attach resized volumes, ensuring all instances have the necessary storage capacity.
- Implement scheduled resizing: Use AWS Systems Manager to schedule EBS volume resizing based on predictable workload patterns (e.g., batch processing at night). This allows you to optimize performance during high-demand periods without manual intervention.
- Monitor IOPS limits to avoid throttling: Ensure that you understand and monitor IOPS limits, especially for high-performance applications. If needed, use provisioned IOPS to avoid performance degradation caused by throttling.
- Leverage volume performance tuning: If you’re resizing to accommodate higher performance needs, don't just increase size—adjust volume type (e.g., from gp2 to io1) to boost IOPS and throughput, improving application performance under heavy load.
Resize EBS Volumes with Windows EC2 Instances
To increase the size of volumes for Windows instances, start by modifying the volumes’ sizes and allowing the optimization process to occur, just as you would for Linux instances. After the optimization process, the volume will have increased from 30GB to 40GB, so additional steps are required.
First, log into your Windows instance, and open Disk Management. You can do this by typing in:
diskmgmt
When Disk Management opens, you will notice the volume is sized at 30GB, as it was originally.
If you open “Action,” and then “Rescan Disks,” you will see an additional 10GB of unallocated space which was just added by expanding the EBS Volume.
To use the newly added space, right click on the existing volume and choose the “Extend Volume” option.
This will bring up the Wizard which will help you make changes quickly.
Select the desired amount of space to be added (you most likely want to add all of it, as was done here), and finish the process. When you look at the usable size now, you will see that you have successfully expanded it to 40GB.
Resizing Your EBS: How to Shrink a Volume
Unfortunately, EBS Elastic Volumes does not support volume size reduction. Shrinking a volume within Amazon will require creating a new volume, attaching it to the running instance, and copying all the data to it—tedious work. You can find a detailed description of the entire process in this article.
Resize your EBS volumes easily and quickly
EBS volumes are the AWS block storage offering you can’t live without. While working with them is simple, until recently, resizing them resulted in unnecessarily complex tasks. The introduction of Elastic Volumes has changed this completely—at least when you need to grow your volumes.
Shrinking volumes in AWS is tedious and time-consuming. Luckily, you can use N2WS to easily recover a snapshot of the volume and, in the process, change the size or even move to storage with a better throughput, for example from go2 to go3.
N2WS Backup & Disaster Recovery is an enterprise-class backup/recovery and disaster recovery solution for EC2, EBS, DynamoDB, EFS, Aurora, Redshift and RDS. It is launched as an AMI on the AWS Marketplace and uses EBS volumes and RDS databases to automatically take snapshots at regular intervals.
You can set up policies and schedule backups for various targets. Try N2WS Backup & Recovery for free for 30 days (which automatically converts to our Forever Free edition).
Click here to read the original post →
How to Increase the Size of an EBS Volume Attached to a Linux Machine. Amazon Elastic Block Store (Amazon EBS) offers persistent storage for Amazon EC2 instances by means of block-level storage volumes. These volumes provide a scalable plug and play storage service, that persists independently of an instance’s life cycle. An EBS volume is cost-effective, scalable, and comes with three options:
- General Purpose (SSD)
- Provisioned IOPS (SSD)
- Magnetic (the old standard)
An EBS volume can be attached as a root partition to an EBS-backed AMI instance or as a detachable device to any AWS EC2 instance. When a user creates an EBS volume, AWS provisions an appropriate amount of space to the user’s AWS account according to the size of the requested EBS volume. In the future, the user may need to increase the size of the EBS volume in order to accommodate a larger amount of data.
Step by Step
This article demonstrates how one of our users increased a root EBS volume from 8GB to 30GB. In order to accomplish this, we will show you how once you launch a Linux-based EC2 instance, you can increase the size of your EBS volume using snapshots. All you need to do is launch an instance, create a snapshot from the volume that is attached to the launched instance, then create a new, bigger volume. Below is a step by step guide that will clarify how to perform this task:
- First, you need to successfully launch an EC2 instance with EBS as its root device. The root EBS volume is used as a reference, so you can follow the same step for all of the volumes.
- Next, connect the instance via PuTTY (in Windows machines) or an SSH client (in Linux machines). We are using PuTTY for our exercise.
- Run the command “df –h”. It will display the drive’s details before resizing.
- To increase the size of the root volume, since this is an EBS-backed instance, first stop the instance temporarily.Using CLI: ec2-stop-instances i-bc781c50 (assuming that the AWS CLI has already been set up on your machine.)
- Detach the existing volume from the instance.Using CLI: ec2-detach-volume vol-47b0d203
- Create a snapshot from the previously detached volume.Using CLI: ec2-create-snapshot vol-47b0d203 –description “Daily Backup”
- Provide an appropriate name for the snapshot.
- Details of the recently created snapshot can be found under the description tab in the snapshot area.
- Create a volume from the recently generated snapshot.Using CLI: ec2-create-volume –size 30 –region us-east-1 –availability-zone us-east-1a –type gp2 Note: In this case, the us-west-2 region is selected in the CLI instead of us-east-1 because the instance is running in US West.
- Now, you can resize the volume. Here, the user resized it from 8GB to 30GB. All you have to do is specify the AZs and select the type of volume you need. (Note: The volume must be created in the AZ where the present instance is in a stopped state. Otherwise, if the volume and the instance are in different zones they cannot be attached.)
- Attach the new volume to the running instance.Using CLI: ec2-attach-volume vol-7bea883f -i i-bc781c50 -d /dev/xvda
- Identify the stopped instance from the list and attach it as the root device. (It is very important to identify the root device drive and only attach the new volume as the root device.)
- Start the instance after the new root volume is attached.Using CLI: ec2-start-instances i-bc781c50
- Log into the instance console using PuTTY or an SSH client. (Note: This time, the public DNS will be different since the instance was first stopped and then started. If you want to keep the same public DNS, use an elastic IP.) If this is not your root volume and you are attaching the volume as an additional volume to a Linux instance, you should run the command “resize2fs ” to increase the size of the new volume. As for the root volume, AWS will automatically increase the file system according to the updated size.
- Run the command “df –h” again to check the size of the root device.
The above-mentioned command displays that the size of the root device is now 30GB.Note: In the steps above, the root volume size was increased from 8GB to 30GB. However, you can follow the same steps to increase the size of any additional attached volume to a running instance. As you can see, snapshots provide a very handy option to back up data at a specific point in time while achieving HA and DR, as well. With this ability, we were able to change the size of the EBS volume shown above.
You might also like