Running out of disk space EC2
Asked Answered
C

4

25

I ran into some issues with my EC2 micro instance and had to terminate it and create a new one in its place. But it seems even though the old instance is no longer visible in the list, it is still using up some space on my disk. My df -h is listed below:

Filesystem    Size    Used    Avail    Use%

/dev/xvda1    7.8G    7.0G    719M     91% /

When I go to the EC22 console I see there are 3 volumes each 8gb in the list. One of them is attached (/dev/xvda) and this one is showing as "in-use". The other 2 are simply showing as "Available"

Is the terminated instance really using up my disk space? If yes, how to free it up?

Containment answered 2/10, 2015 at 11:19 Comment(0)
P
22

Amazon Elastic Block Storage (EBS) is a service that provides virtual disks for use with Amazon EC2. It is network-attached storage that persists even when an EC2 instance is stopped or terminated.

When launching an Amazon EC2 instance, a boot volume is automatically attached to the instance. The contents of the boot volume is copied from an Amazon Machine Image (AMI), which can be chosen from a pre-populated list (including the ability to create your own AMI).

When an Amazon EC2 instance is Stopped, all EBS volumes remain attached to the instance. This allows the instance to be Started with the same configuration as when it was stopped.

When an Amazon EC2 instance is Terminated, EBS volumes might or might not be deleted, based upon the Delete on Termination setting of each volume:

Selecting volume deletion when launching an EC2 instance

By default, boot volumes are deleted when an instance is terminated. This is because the volume was originally just a copy of an AMI, so there is unlikely to be any important data on the volume. (Hint: Don't store data on a boot volume.)

Additional volumes default to "do not delete on termination", on the assumption that they contain data that should be retained. When the instance is terminated, these volumes will remain in an Available state, ready to be attached to another instance.

So, if you do not require any content on your remaining EBS volumes, simply delete them. In future, when launching instances, keep an eye on the Delete on Termination setting to make the clean-up process simpler.

Please note that the df -h command is only showing currently-attached volumes. It is not showing the volumes in Available state, since they are not visible to that instance. The concept of "Disk Space" typical refers to the space within an EBS volume, while "EBS Storage" refers to the volumes themselves. So, the 7GB of the volume that is used is related to that specific (boot) volume.

If you are running out of space on an EBS volume, see: Expanding the Storage Space of an EBS Volume on Linux. Expanding the volume involves:

  • Creating a snapshot
  • Creating a new (bigger) volume from the snapshot
  • Swapping the disks (requiring a Stop/Start if you are swapping a boot volume)
Protanopia answered 2/10, 2015 at 20:56 Comment(0)
C
25

I have just solved my problem by running this command:

sudo apt autoremove

and a lot of old packages are going to be removed, for instance many files like this linux-aws-headers-4.4.0-1028

Counselor answered 27/12, 2018 at 22:46 Comment(5)
thanks a lot! I knew my application is of hardly 1GB and the volume is consumed else where... this saved my time and set the right direction.Windbag
yup headers they took 2GB spaceLinolinocut
Thanks buddy freed 2.5GB was all headersTowpath
Thanks for the insight. Does this command take a long time? My cursor went to the next line and it is still bliking there after 10 minutes... There is no log or anything... @WindbagHypoacidity
eh... that was like 2 years back, don't remember exactly now but it definitely took less than 10 mins in my case.Windbag
P
22

Amazon Elastic Block Storage (EBS) is a service that provides virtual disks for use with Amazon EC2. It is network-attached storage that persists even when an EC2 instance is stopped or terminated.

When launching an Amazon EC2 instance, a boot volume is automatically attached to the instance. The contents of the boot volume is copied from an Amazon Machine Image (AMI), which can be chosen from a pre-populated list (including the ability to create your own AMI).

When an Amazon EC2 instance is Stopped, all EBS volumes remain attached to the instance. This allows the instance to be Started with the same configuration as when it was stopped.

When an Amazon EC2 instance is Terminated, EBS volumes might or might not be deleted, based upon the Delete on Termination setting of each volume:

Selecting volume deletion when launching an EC2 instance

By default, boot volumes are deleted when an instance is terminated. This is because the volume was originally just a copy of an AMI, so there is unlikely to be any important data on the volume. (Hint: Don't store data on a boot volume.)

Additional volumes default to "do not delete on termination", on the assumption that they contain data that should be retained. When the instance is terminated, these volumes will remain in an Available state, ready to be attached to another instance.

So, if you do not require any content on your remaining EBS volumes, simply delete them. In future, when launching instances, keep an eye on the Delete on Termination setting to make the clean-up process simpler.

Please note that the df -h command is only showing currently-attached volumes. It is not showing the volumes in Available state, since they are not visible to that instance. The concept of "Disk Space" typical refers to the space within an EBS volume, while "EBS Storage" refers to the volumes themselves. So, the 7GB of the volume that is used is related to that specific (boot) volume.

If you are running out of space on an EBS volume, see: Expanding the Storage Space of an EBS Volume on Linux. Expanding the volume involves:

  • Creating a snapshot
  • Creating a new (bigger) volume from the snapshot
  • Swapping the disks (requiring a Stop/Start if you are swapping a boot volume)
Protanopia answered 2/10, 2015 at 20:56 Comment(0)
V
2

These 2 steps add an extra hard drive to your EC2 and format it for use:

  1. Attach an extra hard drive (EBS: Elastic Block Storage) to an EC2
  2. Format an EBS drive attached to an EC2

Here's pricing info. Free Tier includes 30GB. Afterward it's $1.25/month for 10GB on a General Purpose SSD (gp2).

To see how much space you are using/need:

  • Check your current disk use/available in Linux with df -h.
  • Check the size of a directory in Linux with du -sh [path].
Vallievalliere answered 5/2, 2022 at 23:49 Comment(1)
I wonder. Does the space includes the OS' installation space?. Do they charge for the space it takes?Stabler
L
0

I had no space at all, so that the answers above were not working (sudo apt autoremove has first to write data in EC2).

I solved the problem by running:

sudo apt clean

As explained here:

The apt-get clean command helps to clean out the cache once you have installed the packages using apt-get install command in your system. It removes the files that are no longer required but are still residing on your system and keeping the system space.

Just what I needed as I had just tried to update and upgrade Ubuntu.

Lindbergh answered 4/9, 2023 at 21:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.