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
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 /var/cache/yum/x86_64/2/amzn2-core/gen/primary_db.sqlite /var/cache/yum/x86_64/2/amzn2-core/packages/golang-bin-1.18.6-1.amzn2.x86_64.rpm /var/cache/yum/x86_64/2/amzn2-core/packages/java-11-amazon-corretto-headless-11.0.17+8-1.amzn2.x86_64.rpm /var/swapfile /usr/lib/locale/locale-archive /usr/lib/jvm/java-11-amazon-corretto.x86_64/lib/modules
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.
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.
Goodbye Ghost, Hello Hugo
Back up DVDs with MakeMKV (makemkvcon) and disable auto updates on Linux