Expanding the Storage Space of an EBS Volume on Linux
This guide applies to increase the root volume size of an EBS EC2 Linux instance on AWS. By default, most Linux instances come with an 8GB root volume unless you changed it at first launch. If you are one of the people that forgot to do this or you just simply need to extend the volume take a look at this guide.
I started out with an Amazon Linux instance and an 8GB volume.
1. First, you want to navigate to your EC2 console at https://console.aws.amazon.com/ec2/
2. In the navigation pane, choose Instances and then locate the instance with the volume that you want to expand.
3. Make a note of the instance ID and Availability Zone. You will specify this information when you attach a new volume to the instance later in this topic.
4. Verify that the instance Shutdown Behavior is set to Stop and not Terminate.
Choose the instance.
- From the context-menu (right-click) choose Instance Settings, and then choose Change Shutdown Behavior.
- If the Shutdown behavior is set to Terminate, choose Stop, and then choose Apply.
- If the Shutdown behavior is already set to Stop, then choose Cancel.
5. Stop the instance
6. Create a snapshot of the volume to expand.
Click EC2 and then Volumes on the left panel. Find the volume that your instance is attached to and right click and create a snapshot.
7. Create a new volume from the snapshot.
Once your snapshot is started creating, navigate over to the snapshot section of the EC2 Console on the left side panel. You will then look for the snapshot you just created with the same name you gave it. This may take a while to for the snapshot process to complete.
Once the snapshot is complete, right click on the snapshot and select ‘Create Volume’. Now pay attention here because this is where you specify the new volume size which is larger than previously, for this example I chose 100GB. Please also note that you need to make the volume in the same Availability Zone as your instance, mine happens to be in us-west-2a. You must also choose either a standard volume or Provisioned IOPS. Once done, press ‘Yes, Create’.
8. Detach the old volume.
Once the volume is created, navigate over to your EC2 Instances section and go ahead and stop your instance. Once stopped, go ahead and detach the original root volume from the Volumes section of the EC2 Console. To do this you simply find the volume attached to your instance and right-click, and select detach.
Once the volume is detached, go ahead and attach the volume you created to the instance by selecting the 100GB volume, right-click, and attach the volume to your instance specifying the mount point as /dev/sda1.
9. Attach the newly expanded volume
10. Restart the instance.
- In the navigation pane, choose Instances and then choose the instance you want to restart.
- From the context-menu (right-click) choose Instance State, and then choose Start.
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.
[root@ip-52-254-59-52 ec2-user]# df -h Filesystem Size Used Avail Use% Mounted on /dev/xvda1 7.9G 943M 6.9G 12% / tmpfs 829M 0 829M 0% /dev/shm [root@ip-10-254-59-62 ec2-user]# resize2fs /dev/xvda1 resize2fs 1.42.3 (04-Apr-2016) Filesystem at /dev/xvda1 is mounted on /; on-line resizing required old_desc_blocks = 1, new_desc_blocks = 7 The filesystem on /dev/xvda1 is now 26214400 blocks long. [root@ip-52-254-59-52 ec2-user]# df -h Filesystem Size Used Avail Use% Mounted on /dev/xvda1 99G 969M 98G 1% / tmpfs 829M 0 829M 0% /dev/shm