✅ Tested OS's : RHEL 7+, CentOS 7+, Ubuntu 18.04+, Debian 8+
✅ Tested Gear : Cloud (AWS EC2 T2)

By following this tutorial, you will be able to increase / decrease disk volume size in any AWS EC2 instance of your choice.

  1. Log into the AWS Management Console > Services > EC2. Then, from the left navigation pane, choose INSTANCES > Instances.
  2. Make sure that the EC2 instance you wish to make the change is in stopped state (Otherwise, go to Actions > Instance State > Stop).
  3. Then, in the Description tab of your selected instance, click on the volume (say /dev/sda1) listed next to Block devices. Choose its EBS ID and you will be redirected to Volumes section of ELASTIC BLOCK STORE. Now the volume that has been selected is the one used in your EC2 instance.
  4. To modify the volume, go to Actions > Modify Volume, and then enter the Size you want in GB. Click Modify once you are done. Volume will go to optimizing state, which means you can start the instance now.
  5. Go back to the Instances page and start the EC2 instance (Actions > Instance State > Start*).
  6. Now SSH to your EC2 instance and verify the disk size upgrade by running the below commands.
// show space available on all currently mounted file systems
$ df -h
Filesystem       Size  Used Avail Use% Mounted on
/dev/xvda1        16G  1.9G  6.2G  12% /
/dev/xvdf1        30G   45M  8.0G   1% /data

// list information about all available or the specified block devices after reading the sysfs filesystem and udev db
$ lsblk
NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda    202:0    0  16G  0 disk
└─xvda1 202:1    0  16G  0 part /
xvdf    202:80   0  30G  0 disk
└─xvdf1 202:81   0  30G  0 part /data

Troubleshooting Guide

  • If the change is not visible for above commands, first verify the file system names in use for each volume on your instance.
// for file systems on a Nitro-based instance
$ sudo file -s /dev/nvme?n*
/dev/nvme0n1:     x86 boot sector ...
/dev/nvme0n1p1:   SGI XFS filesystem data ...
/dev/nvme0n1p128: data
/dev/nvme1n1:     SGI XFS filesystem data ...

// for file systems on a T2 instance
$ sudo file -s /dev/xvd*
/dev/xvda:  x86 boot sector ..
/dev/xvda1: data
/dev/xvdf:  SGI XFS filesystem data ...
  • Observe the unallocated space (= total size - allocation for partitions).
// for file systems on a Nitro-based instance
$ lsblk
NAME          MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
nvme1n1       259:0    0  30G  0 disk /data
nvme0n1       259:1    0  16G  0 disk
└─nvme0n1p1   259:2    0   8G  0 part /
└─nvme0n1p128 259:3    0   1M  0 part

// for file systems on a T2 instance
$ lsblk
NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda    202:0    0  16G  0 disk
└─xvda1 202:1    0   8G  0 part /
xvdf    202:80   0  30G  0 disk
└─xvdf1 202:81   0   8G  0 part /data
  • Extend the partition size on each root volume. Note that there is a space between the device name and the partition number.
// for file systems on a Nitro-based instance
$ sudo growpart /dev/nvme0n1 1

// for file systems on a T2 instance
$ sudo growpart /dev/xvda 1
  • Verify that the partition size is increased.
// for file systems on a Nitro-based instance
$ lsblk
NAME          MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
nvme1n1       259:0    0  30G  0 disk /data
nvme0n1       259:1    0  16G  0 disk
└─nvme0n1p1   259:2    0  16G  0 part /
└─nvme0n1p128 259:3    0   1M  0 part

// for file systems on a T2 instance
$ lsblk
NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda    202:0    0  16G  0 disk
└─xvda1 202:1    0  16G  0 part /
xvdf    202:80   0  30G  0 disk
└─xvdf1 202:81   0  30G  0 part /data
  • If changes are not visible in file system, you need to extend file system sizes too.
// for file systems (ext2, ext3, or ext4) on a Nitro-based instance

$ df -h
Filesystem       Size  Used Avail Use% Mounted on
/dev/xvda1       8.0G  1.9G  6.2G  24% /
/dev/xvdf1       8.0G   45M  8.0G   1% /data

$ sudo resize2fs /dev/xvda1
$ sudo resize2fs /dev/xvdf1

$ df -h
Filesystem       Size  Used Avail Use% Mounted on
/dev/xvda1        16G  1.9G  6.2G  12% /
/dev/xvdf1        30G   45M  8.0G   1% /data

// for file systems (XFS) on a T2 instance

$ df -h
Filesystem       Size  Used Avail Use% Mounted on
/dev/nvme0n1p1   8.0G  1.6G  6.5G  20% /
/dev/nvme1n1     8.0G   33M  8.0G   1% /data

$ sudo yum install xfsprogs
$ sudo xfs_growfs -d /
$ sudo xfs_growfs -d /data

$ df -h
Filesystem       Size  Used Avail Use% Mounted on
/dev/nvme0n1p1    16G  1.6G   15G  10% /
/dev/nvme1n1      30G   33M   30G   1% /data

Tags:

Updated:

Leave a comment