By default most Linux instances comes with an 8GB root EBS volume unless you changed it during launch wizard. If you have forgot to increase root volume during launch or you just need to extend because root volume has reached critical level, follow this tutorial.
Note: The size of a volume can only be increased, not decreased.
Current root volume usage
We have 8G root volume disk, which is now 92% used and has just 640M free space remaining. We need to extend this volume by 22G , Total size will become 30G.
Before resizing the volume, you need to remember below points
- Power off the VM (This will ensure data integrity)
- Take a snapshot of volume (You can revert to old state in case something goes wrong )
Find the Volume
When you have multiple EC2 instances running and their Volumes are not tagged, you may find it difficult to identify the right root Volume. First, let us find the volume ID that needs to be resized.
Login to Ec2 console and select the EC2 instance for which root volume needs to increased. Under “Description” tab, you will see root device name “/dev/xvda”, click it. It will now open a small pop up box containing this volume information. Click on EBS Volume Id, it will now redirect you to “Volume” management page where you can take snapshot and modify its size.
Take a Volume Snapshot
On “Volume” management page, select the volume to be resized and click “Create Snapshot” under “Actions” menu
Now provide a Name and Description for our Root volume device
Once the Snapshot is created, note down the its ID for future reference.
Resizing (Extending Volume size)
There are two ways to resize the partition,
- Warm resize [Easy]
- Using snapshot
1. Warm resize method
This method is easy and simple to folow, you just have to select the volume and modify its size. Remember, you can only extend its size.
Click “Modify Volume” under “Actions” menu
Now enter the size for your root volume. Before clicking “Modify” button, make sure that you have “STOPPED” the instance. Modifying the Volume on running server may end up with partition corruption.
Once you ensured instance is in stooped state and you have entered correct volume size to resize root volume, Click “Yes”.
Now SSH into your instance and notice that root volume has extended from 8G to 30G successfully.
In some scenarios it may show same volume size, simply execute below command to update the root volume file system. It should now show the correct filesystem size.
2. Resize Using snapshot
Now select the snapshot that you have taken before. Create volume out of this Snapshot by clicking “Create Volume” under “Actions” menu.
Now enter the volume size, say 30G and choose “Availability zone” where EC2 was launched. In our case we did launch Ec2 in “us-east-1b” zone, select it from the dropdown menu and click “Create Volume”.
Now new Volume will be created with size 30G. Note down its ID for future reference.
Now STOP the instance and detach the root volume.
Click “Yes, detach”, it should now detach this volume from EC2 instance. You will notice the state of this volume changing from “In use” to “Available”
Now Copy instance ID of our stooped instance. Identify our newly created volume off snapshot (30G size), select it and attach to our instance.
Important thing to note here is “Device” name. You must replace the existing entry with “/dev/xvda“, otherwise it won’t be detected by Operating System as root volume.
Once it is attached to our instance, Power it on and ssh into it. Execute df -h / and notice root volume size.
[root@ip-10-0-1-159 ~]# df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 30G 7.1G 23G 24% /
As you can see from above output, root device /dev/xvda1 has been successfully extended to 30G.
In some scenarios it may not show increased volume size, simply execute below command to update the root volume file system. It should now show correct filesystem size.
If you’re facing any difficulty in extending root volume, please leave a comment, we will help you out!