AWS Cloud9 - No space left on device

Posted by ryansouthgate on 18 Dec 2022

In this post I’m going to show you how I recently cleaned up loads of space on my AWS Cloud9 instance, when I got the annoying “No space left on device” message.

I use this AWS Cloud9 instance weekly to generate a bunch of files and download them to my local PC. The generated files don’t usually exceed 50mb and I’m good at cleaning up old ones. I was surprised to see the message when logging in recently and as any developer, immediately thought “this can’t be my fault!”

Finding the culprits

Docker is installed on this Cloud9 instance, so let’s check if there’s any images on the instance you’re not using, by running the command

docker images

If there’s any images you’re no longer using in there, you can remove them and free up some space.

Next, I wanted to check the file system, to see exactly how much free space we’ve got. So ran the following command and got the output

df -h

# Output
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        475M     0  475M   0% /dev
tmpfs           492M     0  492M   0% /dev/shm
tmpfs           492M  536K  491M   1% /run
tmpfs           492M     0  492M   0% /sys/fs/cgroup
/dev/xvda1       10G  9.9G  0.1G  99% /
tmpfs            99M     0   99M   0% /run/user/1000

OK, so we’re at 99% disk usage (the /dev/xvda1 filesystem) on our AWS Cloud9 Instance.

The above command doesn’t give us specific files though, so lets try the following command to see any files 100mb or above

find / -xdev -type f -size +100M

# Output

That output tells us that there’s some large yum package files hanging around. It seems that these grow over time. So one “fix” could be to nuke your AWS Cloud9 instance and then re-create it. But if you’ve got it setup just how you want, that’s not an ideal solution.

Cleaning up

There’s a few things we can tackle here, to give ourselves some more free space. I’ve listed the commands below and a brief indication of what they’ll do

Remove any docker images which don’t have containers

docker image prune -a

Clear the yum package cache - this cleans most of the package cache, but didn’t clean up that much free space for me

yum clean all

Force clean everything - go renegade and remove all files ourself

rm -rf /var/cache/yum/*

After running the commands above, I had managed to reclaim 2.6GB of space from my AWS Cloud9 Instance. See the output of dh -h below

Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        475M     0  475M   0% /dev
tmpfs           492M     0  492M   0% /dev/shm
tmpfs           492M  528K  491M   1% /run
tmpfs           492M     0  492M   0% /sys/fs/cgroup
/dev/xvda1       10G  7.6G  2.5G  76% /
tmpfs            99M     0   99M   0% /run/user/1000
tmpfs            99M     0   99M   0% /run/user/0

I much prefer cleaning the filesystem, rather than the suggested solution found on a lot of Google results, which is just blindly increasing the disk space for that Cloud9 instance.

comments powered by Disqus