Menu
Amazon Elastic Compute Cloud
User Guide for Linux Instances

Modifying the Size, IOPS, or Type of an EBS Volume on Linux

If your Amazon EBS volume is attached to a current generation EC2 instance type, you can increase its size, change its volume type, or (for an io1 volume) adjust its IOPS performance, all without detaching it. You can apply these changes to detached volumes as well. For more information about the current generation instance types, see Current Generation Instances.

If you are using a previous generation instance type, or if you encounter an error while attempting a volume modification, follow the procedures in Appendix: Starting and Stopping an Instance to Modify an EBS Volume.

In general, the following steps are involved in modifying a volume:

  1. Issue the modification command. For more information, see Modifying an EBS Volume from the Console and Modifying an EBS Volume from the Command Line.

  2. Monitor the progress of the modification. For more information, see Monitoring the Progress of Volume Modifications.

  3. If the size of the volume was modified, extend the volume's file system to take advantage of the increased storage capacity. For more information, see Extending a Linux File System after Resizing the Volume .

Additionally, you can use Amazon CloudWatch Events and AWS CloudFormation to automate the actions associated with volume modification.

There is no charge to modify the configuration of a volume. You are charged at the new volume configuration price after a modification starts. For more information, see the Amazon Elastic Block Store section on the Amazon EC2 Pricing page.

For more information, see Considerations for Modifying EBS Volumes.

Important

Before modifying a volume that contains valuable data, it is a best practice to create a snapshot of the volume in case you need to roll back your changes. For information about EBS snapshots, see Creating an Amazon EBS Snapshot.

Modifying an EBS Volume from the Console

The following procedure shows how to apply available volume modifications from the Amazon EC2 console.

  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, and IOPS. You can change any or all of these settings in a single action. Set new configuration values as follows:

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

    • To modify the size, enter an allowed integer value for Size.

    • If you chose Provisioned IOPS (IO1) as your volume type, enter an allowed integer value for IOPS.

  4. After you have specified all of the modifications to apply, choose Modify, Yes.

Note

Modifying volume size has no practical effect until you also extend the volume's file system to make use of the new storage capacity. For more information, see Extending a Linux File System after Resizing the Volume.

Modifying an EBS Volume from the Command Line

The following example demonstrates how an EBS volume can be modified from the command line using the AWS CLI. Depending on your default configuration, you may need to specify information such as region and availability zone. The ID of the source volume being modified is required, and you must have appropriate permissions to carry out the action. When an io1 volume is the modification target, you must specify its level of provisioned IOPS. Multiple modification actions (to change capacity, IOPS, or type) may be performed in a single command.

For example, an EBS volume is configured as follows:

  • Volume ID: vol-11111111111111111

  • Volume size: 100 GiB

  • Volume type: gp2

You can change the volume configuration to the following:

  • Volume size: 200 GiB

  • Volume type: io1

  • Provisioning level: 10,000 IOPS

Apply the above modifications with the following command:

Copy
aws ec2 modify-volume --region us-east-1 --volume-id vol-11111111111111111 --size 200 --volume-type io1 --iops 10000

The command yields output similar to the following:

Copy
{ "VolumeModification": { "TargetSize": 200, "TargetVolumeType": "io1", "ModificationState": "modifying", "VolumeId": "vol-11111111111111111", "TargetIops": 10000, "StartTime": "2017-01-19T22:21:02.959Z", "Progress": 0, "OriginalVolumeType": "gp2", "OriginalIops": 300, "OriginalSize": 100 } }

Note

Modifying volume size has no practical effect until you also extend the volume's file system to make use of the new storage capacity. For more information, see Extending a Linux File System after Resizing the Volume.

Monitoring the Progress of Volume Modifications

An EBS volume being modified goes through a sequence of states. After you issue a ModifyVolume directive, whether from the console, CLI, API, or SDK, the volume enters first the Modifying state, then the Optimizing state, and finally the Complete state. At this point, the volume is ready to be further modified. Rarely, a transient AWS fault can result in the Failed state. If this occurs, retry the modification.

Size changes usually take a few seconds to complete and take effect after a volume is in the Optimizing state.

Performance (IOPS) changes can take from a few minutes to a few hours to complete and are dependent on the configuration change being made.

It may take up to 24 hours for a new configuration to take effect. Typically, a fully used 1 TiB volume takes about 6 hours to migrate to a new performance configuration.

While the volume is in the optimizing state, your volume performance will be in between the source and target configuration specifications. Transitional volume performance will be no less than the source volume performance. If you are downgrading IOPS, transitional volume performance will be no less than the target volume performance.

You can monitor the progress of a modification by inspecting the AWS Management Console, by querying the volume's state with the AWS EC2 API/CLI, or by accessing metrics sent to Amazon CloudWatch Events. The following procedures demonstrate these approaches.

To monitor progress of a modification from the console

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

  2. Choose Volumes, and select the volume to inspect. The volume's status is displayed in the State column. In the example below, the modification state is completed. This state information is also displayed in the State field of the details pane.

  3. Open the information icon next to the State field to display complete before and after information about the most recent modification action, as illustrated below.

To monitor progress of a modification from the command line

  • Use describe-volumes-modifications to view the progress of the modifications. In this example, volume vol-11111111111111111 from above and another volume, vol-22222222222222222, are called.

    Copy
    aws ec2 describe-volumes-modifications --region us-east-1 --volume-id vol-11111111111111111 vol-22222222222222222

    This command yields output similar to the following:

    Copy
    { "VolumesModifications": [ { "TargetSize": 200, "TargetVolumeType": "io1", "ModificationState": "modifying", "VolumeId": "vol-11111111111111111", "TargetIops": 10000, "StartTime": "2017-01-19T22:21:02.959Z", "Progress": 0, "OriginalVolumeType": "gp2", "OriginalIops": 300, "OriginalSize": 100 }, { "TargetSize": 2000, "TargetVolumeType": "sc1", "ModificationState": "modifying", "VolumeId": "vol-22222222222222222", "StartTime": "2017-01-19T22:23:22.158Z", "Progress": 0, "OriginalVolumeType": "gp2", "OriginalIops": 300, "OriginalSize": 1000 } ] }

The describe-volumes-modifications command returns one or more VolumesModification objects. The first of the two in this example is nearly identical to the original modify-volume command output shown above. No additional modifications have been applied, however.

The next example queries for all volumes in a region with a modification state of either optimizing or completed, and then filters and formats the results to show only modifications that were initiated on or after February 1, 2017:

Copy
aws ec2 describe-volumes-modifications --filters Name=modification-state,Values="optimizing","completed" --region us-east-1 --query "VolumesModifications[?StartTime>='2017-02-01'].{ID:VolumeId,STATE:ModificationState}"

In this case the query returns information about two volumes:

Copy
[ { "STATE": "optimizing", "ID": "vol-06397e7a0eEXAMPLE" }, { "STATE": "completed", "ID": "vol-bEXAMPLE" } ]

To monitor progress of a modification with CloudWatch Events

With CloudWatch Events, you can create a notification rule for volume modification events to send a text message or execute a Lambda function.

  1. Open the CloudWatch console at https://console.aws.amazon.com/cloudwatch/.

  2. Choose Events, Create rule.

  3. For Build event pattern to match events by service, choose Custom event pattern.

  4. For Build custom event pattern , replace the contents with the following code:

    Copy
    { "source": [ "aws.ec2" ], "detail-type": [ "EBS Volume Notification" ], "detail": { "event": [ "modifyVolume" ] } }

    Choose Save when done.

    Typical event output should look like the following:

    Copy
    Body: { "version": "0", "id": "1ea2ace2-7790-46ed-99ab-d07a8bd68685", "detail-type": "EBS Volume Notification", "source": "aws.ec2", "account": "065441870323", "time": "2017-01-12T21:09:07Z", "region": "us-east-1", "resources": [ "arn:aws:ec2:us-east-1:065441870323:volume/vol-03a55cf56513fa1b6" ], "detail": { "result": "optimizing", "cause": "", "event": "modifyVolume", "request-id": "auto-58c08bad-d90b-11e6-a309-b51ed35473f8" } }

You can use your rule to generate a notification message with Amazon SNS or to invoke an AWS Lambda function in response to matching events.

Extending a Linux File System after Resizing the Volume

Use a file system–specific command to resize the file system to the larger size of the new volume. These commands work even if the volume to extend is the root volume. For ext2, ext3, and ext4 file systems, this command is resize2fs. For XFS file systems, this command is xfs_growfs. For other file systems, refer to the specific documentation for those file systems for instructions on extending them.

If you are unsure of which file system you are using, you can use the file -s command to list the file system data for a device. The following example shows a Linux ext4 file system and an SGI XFS file system.

Copy
[ec2-user ~]$ sudo file -s /dev/xvd* /dev/xvda1: Linux rev 1.0 ext4 filesystem data ... /dev/xvdf: SGI XFS filesystem data ...

Note

If the volume you are extending has been partitioned, you need to increase the size of the partition before you can resize the file system. You can also allocate additional partitions at this time. For more information, see Expanding a Linux Partition.

You can begin resizing the file system as soon as the volume enters the Optimizing state.

Important

Before extending a file system that contains valuable data, it is a best practice to create a snapshot of the volume that contains it in case you need to roll back your changes. For information about EBS snapshots, see Creating an Amazon EBS Snapshot.

To check if your volume partition needs resizing

  • Use the lsblk command to list the block devices attached to your instance. The example below shows three volumes: /dev/xvda, /dev/xvdb, and /dev/xvdf.

    Copy
    [ec2-user ~]$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT xvda 202:0 0 30G 0 disk └─xvda1 202:1 0 30G 0 part / xvdb 202:16 0 30G 0 disk /mnt xvdf 202:80 0 35G 0 disk └─xvdf1 202:81 0 8G 0 part
    The root volume, /dev/xvda1, is a partition on /dev/xvda. Notice that they are both 30 GiB in size. In this case, the partition occupies all of the room on the device, so it does not need resizing.

    The volume /dev/xvdb is not partitioned at all, so it does not need resizing.

    However, /dev/xvdf1 is an 8 GiB partition on a 35 GiB device and there are no other partitions on the volume. In this case, the partition must be resized in order to use the remaining space on the volume. For more information, see Expanding a Linux Partition. After you resize the partition, you can follow the next procedure to extend the file system to occupy all of the space on the partition.

To extend a Linux file system

  1. Log in to your Linux instance using an SSH client. For more information about connecting to a Linux instance, see Connecting to Your Linux Instance Using SSH.

  2. Use the df -h command to report the existing file system disk space usage. In this example, /dev/xvda1 device has already been expanded to 70 GiB, but the operating system still sees only the original 7.9 GiB ext4 file system. Similarly, the /dev/xvdf device has been expanded to 100 GiB, but the operating system still only sees the original 1.0 GiB XFS file system.

    Copy
    [ec2-user ~]$ df -h Filesystem Size Used Avail Use% Mounted on /dev/xvda1 8.0G 943M 6.9G 12% / tmpfs 1.9G 0 1.9G 0% /dev/shm /dev/xvdf 1014M 33M 982M 4% /mnt
  3. Use a file system-specific command to resize each file system to the new volume capacity.

    For a Linux ext2, ext3, or ext4 file system, use the following command, substituting the device name to extend:

    Copy
    [ec2-user ~]$ sudo resize2fs /dev/xvda1 resize2fs 1.42.3 (14-May-2012) Filesystem at /dev/xvda1 is mounted on /; on-line resizing required old_desc_blocks = 1, new_desc_blocks = 5 Performing an on-line resize of /dev/xvda1 to 18350080 (4k) blocks. The filesystem on /dev/xvda1 is now 18350080 blocks long.

    For an XFS file system, first install the XFS userspace tools:

    Copy
    [ec2-user ~]$ sudo yum install xfsprogs

    Then use the following command, substituting the mount point of the file system (XFS file systems must be mounted to resize them):

    Copy
    [ec2-user ~]$ sudo xfs_growfs -d /mnt meta-data=/dev/xvdf isize=256 agcount=4, agsize=65536 blks = sectsz=512 attr=2 data = bsize=4096 blocks=262144, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 log =internal bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 262144 to 26214400

    Note

    If you receive an xfsctl failed: Cannot allocate memory error, you may need to update the Linux kernel on your instance. For more information, refer to your specific operating system documentation.

    If you receive a The filesystem is already nnnnnnn blocks long. Nothing to do! error, see Expanding a Linux Partition.

  4. Use the df -h command to report the existing file system disk space usage, which should now show the full 70 GiB on the ext4 file system and 100 GiB on the XFS file system:

    Copy
    # df -h Filesystem Size Used Avail Use% Mounted on /dev/xvda1 70G 951M 69G 2% / tmpfs 1.9G 0 1.9G 0% /dev/shm /dev/xvdf 100G 45M 100G 1% /mnt

Tip

If the increased available space on your volume remains invisible to the system, try re-initializing the volume as described in Initializing Amazon EBS Volumes.

Appendix: Starting and Stopping an Instance to Modify an EBS Volume

If you are using a previous generation Amazon EC2 instance and you need to modify the root (boot) volume, you must stop the instance, apply the modifications, and then restart the instance. The procedure described here can be used to modify any EBS volume on any instance type.

When you stop and start an instance, be aware of the following:

  • If your instance is running in a VPC and has a public IPv4 address, we release the address and give it a new public IPv4 address. The instance retains its private IPv4 addresses and any Elastic IP addresses.

  • If your instance is running in EC2-Classic, we give it new public and private IPv4 addresses, and disassociate any Elastic IP address that's associated with the instance. You must re-associate any Elastic IP address after you restart your instance.

  • If your instance is in an Auto Scaling group, Auto Scaling marks the stopped instance as unhealthy, and may terminate it and launch a replacement instance. To prevent this, you can temporarily suspend the Auto Scaling processes for the group. For more information, see Suspend and Resume Auto Scaling Processes in the Auto Scaling User Guide.

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

  2. In the navigation pane, choose Instances and select the instance with the volume to expand.

  3. Verify that Shutdown Behavior is set to Stop and not Terminate.

    1. Select the instance.

    2. From the context (right-click) menu, choose Instance Settings, Change Shutdown Behavior.

    3. If Shutdown behavior is set to Terminate, choose Stop, Apply.

      If Shutdown behavior is already set to Stop, choose Cancel.

  4. Stop the instance. For more information, see Stopping and Starting Your Instances.

    Warning

    When you stop an instance, the data on any instance store volumes is erased. Therefore, if you have any data on instance store volumes that you want to keep, be sure to back it up to persistent storage.

  5. Modify your EBS volume as described in Modifying an EBS Volume from the Console or Modifying an EBS Volume from the Command Line.

  6. Restart the instance.

    1. In the navigation pane, choose Instances and then select the instance to restart.

    2. From the context (right-click) menu, choose Instance State, Start.

    3. In the Start Instances dialog box, choose Yes, Start. If the instance fails to start, and the volume being expanded is a root volume, verify that you attached the expanded volume using the same device name as the original volume, for example /dev/sda1.

After the instance has started, you can check the file system size to see if your instance recognizes the larger volume space. On Linux, use the df -h command to check the file system size.

Copy
[ec2-user ~]$ df -h Filesystem Size Used Avail Use% Mounted on /dev/xvda1 7.9G 943M 6.9G 12% / tmpfs 1.9G 0 1.9G 0% /dev/shm

If the size does not reflect your newly expanded volume, you must extend the file system of your device so that your instance can use the new space. For more information, see Extending a Linux File System after Resizing the Volume.