How do I increase the EBS volume size of a running instance? [closed]
Asked Answered
C

7

74

I have a server running the recent Ubuntu AMIs from Canonical. The size of the EBS boot volume is 8GB. I know that I can resize EBS volumes by taking a snapshot, creating a new volume and expanding the partition on it. How can I increase the size of the volume while the machine is running? If this is not possible, what is the preferred method for increasing the boot volume size with minimal downtime?

Campy answered 7/3, 2012 at 15:31 Comment(4)
I know this has been answered, but I found this fantastic simple tutorial the other day. And its what I am going to follow/use at the weekend. tekgoblin.com/2012/08/27/…Hackler
And the linux version, which worked for me and was easy to follow: cloud.tekgoblin.com/2013/04/29/…Savanna
Here's a link to a more recent (2015) description of the process.Slipway
If someone has came here after 2019, there is was to do this with zero downtime: hackernoon.com/…Toplevel
L
40

Unfortunately it is not possible to increase the size of an Amazon EBS root device storage volume while the Amazon EC2 instance is running - Eric Hammond has written a detailed (I'm inclined to say the 'canonical' ;) article about Resizing the Root Disk on a Running EBS Boot EC2 Instance:

As long as you are ok with a little down time on the EC2 instance (few minutes), it is possible to change out the root EBS volume with a larger copy, without needing to start a new instance.

If you properly prepare the steps he describes (I highly recommend to test them with a throw away EC2 instance first to get acquainted with the procedure), you should be able to finish the process with a few minutes downtime only indeed.

Good luck!

Loudspeaker answered 7/3, 2012 at 15:50 Comment(2)
Even better, you could write a script to perform the action. Test it with a test instance and then run the test on the production server to reduce the risk of forgetting a step.Unintentional
THIS ANSWER IS NOT TRUE ANY MORE. docs.aws.amazon.com/AWSEC2/latest/UserGuide/…Functionalism
S
80

We can increase the volume size with the new EBS Feature Elastic volumes, post that we need to follow the following steps to use the increase the size.

Assume your volume was 16G and you increased it to 32GB.

$lsblk
NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda    202:0    0  32G  0 disk
└─xvda1 202:1    0  16G  0 part /

To extend xvda1 from 16GB to 32GB, we need growpart. growpart is available as part of cloudutils.

sudo apt install cloud-utils

Post installation of cloud-utils, execute the growpart command:

sudo growpart /dev/xvda 1
 

Now lsblk, will show:

$ lsblk
NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda    202:0    0  32G  0 disk
└─xvda1 202:1    0  32G  0 part /

but df -h will show only 16GB.


Final command for extending xvda1 to 32GB is:

  • In the case of an ext4 file system:

    sudo resize2fs /dev/xvda1
    
  • In the case of an XFS file system:

    apt-get install xfsprogs
    sudo xfs_growfs /dev/xvda1
    
Selfsown answered 6/4, 2017 at 10:2 Comment(7)
its working.Thank you.Iodometry
This is really amazing, works like a charme - many thanks :-)Hispanicize
worked great to apply allocated space from aws consoleSprage
this one should be accepted answer!Eurasian
If you're using an XFS file system, the final command should be sudo xfs_growfs /dev/xvdal instead of resize2fs.Lipread
This is correct answer ! Saved me lot of time. We need to first goto Volume > Modify Volume and increase sizeQuarta
Amazing, after trying a lot and wasting around 2 day finally found the right answer, big thanks from my side :)Conformance
L
40

Unfortunately it is not possible to increase the size of an Amazon EBS root device storage volume while the Amazon EC2 instance is running - Eric Hammond has written a detailed (I'm inclined to say the 'canonical' ;) article about Resizing the Root Disk on a Running EBS Boot EC2 Instance:

As long as you are ok with a little down time on the EC2 instance (few minutes), it is possible to change out the root EBS volume with a larger copy, without needing to start a new instance.

If you properly prepare the steps he describes (I highly recommend to test them with a throw away EC2 instance first to get acquainted with the procedure), you should be able to finish the process with a few minutes downtime only indeed.

Good luck!

Loudspeaker answered 7/3, 2012 at 15:50 Comment(2)
Even better, you could write a script to perform the action. Test it with a test instance and then run the test on the production server to reduce the risk of forgetting a step.Unintentional
THIS ANSWER IS NOT TRUE ANY MORE. docs.aws.amazon.com/AWSEC2/latest/UserGuide/…Functionalism
Z
22

A late answer to this 5-year-old question

AWS has just announced a new EBS feature called Elastic Volumes, which allows you to increase volume size, adjust performance, or change the volume type while the volume is in use.

You can read more about it on AWS Blog here.

Zibet answered 19/2, 2017 at 19:6 Comment(2)
This is fantastic but note that some legacy volumes may not be supported. I ran aws ec2 modify-volume --region us-west-2 --volume-id vol-0123456789 --size 20 and got this error: An error occurred (InvalidParameterValue) when calling the ModifyVolume operation: Volume type EBS Magnetic is not supported.Abandoned
@runamok: That's right. As stated here, previous-generation Magnetic volume types are not supported by the method described above. Restoring a snapshot to a differently configured EBS volume would be the solution in this case.Zibet
A
8

You just need to create its snapshot first and from that snapshot need to create another volume and once new volume ready, detach the old volume from the instance and attach the new volume. Make sure to stop the instance before start this process and restart the instance once its done.

Refer http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-expand-volume.html

Abatement answered 30/4, 2014 at 18:52 Comment(0)
E
-1

This will work for xfs file system just run this command xfs_growfs /

Eric answered 4/2, 2013 at 7:59 Comment(1)
its working for AWS unubtu 12.X. and its possible during run time no need to restart ..Eric
M
-1

I found that when trying to increase the root partition /dev/sda1 which was being reported as /dev/xvda1 on centos6 i couldn't unmount the volume in order to expand the partition.

I got around this by mounting my original volume as /dev/sda1 and my snapshot as /dev/sdb. I then restarted the image and resized the /dev/sdb1 partition using parted.

Once the partition /dev/sdb1 was resized i detached both volumes and reattached the new volume to /dev/sda1 and ran resize2fs /dev/xvda1.

Magnetize answered 7/9, 2015 at 21:4 Comment(0)
A
-2

You cannot do this. But if your more focused on downtime then cost, you maybe able to clone your main instance, mount a larger EBS storage device to your system, copy the data over and then redirect traffic to your new instance.

If you want, a method I use lately use S3 has a medium of backups and deployment to other systems. So for example, you have your existing system running..set a script to upload your data to s3 every N minutes/hours/days..then write a script to use when launching new instances to download that data. If your data isn't something like constantly updated then this should work fine(for me, I use this to distribute updated version of my codebase while the data itself is managed on a ec2 database server).

Hope that helps.

Alroy answered 8/3, 2012 at 17:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.