How to Increase Disk Space on an Amazon EC2 Instance

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

  1. Log into the AWS Management Console
  2. Navigate to Elastic Block Store > Volumes
  3. Check the box next to the Volume that needs more space
  4. Click the Action drop down list and select Modify Volume
  5. 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
  6. After you have specified all of the modifications to apply, choose Modify, Yes

Important: modifying volume size has no practical effect until you also extend the volume's file system to make use of the new storage capacity

Extending a Linux File System after Resizing the Volume

  1. Use the df -h command to report the existing disk space usage on the file system
    [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

    Warning: if you can't see /dev/xvdf here and /dev/xvda1 still show old storage capacity, skip step 2 for resize file system on step 3

  2. Expand the modified partition using growpart (and note the unusual syntax of separating the device name from the partition number)
    $sudo growpart /dev/xvdf 1
    CHANGED: disk=/dev/xvdf partition=1: start=4096 old: size=16773086,end=16777182 new: size=73396190,end=73400286

    Using lsblk output confirms that the partition /dev/xvdf1 now fills the available space on the volume /dev/xvdf:

    [ec2-user ~]$ lsblk
    xvdf    202:80   0  35G  0 disk
    └─xvdf1 202:81   0  35G  0 part
  3. Use a file system-specific command to resize each file system to the new volume capacity
    [ec2-user ~]$ sudo resize2fs /dev/xvdf1
    resize2fs 1.42.3 (14-May-2012)
    old_desc_blocks = 1, new_desc_blocks = 3
    The filesystem on /dev/xvdf1 is now 9174523 blocks long.


Popular posts from this blog