Amazon EC2 instance is out of space because "root" file is gigantic

cn flag

I've been working lately on an AWS EC2 instance with ubuntu. This is my first experience working with servers, so I'm really new to this.

Lately I've noticed my free space has completely filled up for some reason. When I run

df -h

it gives me

Filesystem      Size  Used Avail Use% Mounted on
/dev/root       7.7G  7.7G   65M 100% /
devtmpfs        479M     0  479M   0% /dev
tmpfs           485M     0  485M   0% /dev/shm
tmpfs            97M   11M   87M  11% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           485M     0  485M   0% /sys/fs/cgroup
/dev/loop1       26M   26M     0 100% /snap/amazon-ssm-agent/4898
/dev/loop0       25M   25M     0 100% /snap/amazon-ssm-agent/4046
/dev/loop2       56M   56M     0 100% /snap/core18/2128
/dev/loop3       56M   56M     0 100% /snap/core18/2246
/dev/loop4       62M   62M     0 100% /snap/core20/1081
/dev/loop5       62M   62M     0 100% /snap/core20/1169
/dev/loop6       68M   68M     0 100% /snap/lxd/21803
/dev/loop7       68M   68M     0 100% /snap/lxd/21835
/dev/loop8       33M   33M     0 100% /snap/snapd/13640
/dev/loop9       43M   43M     0 100% /snap/snapd/13831

Showing dev/root is taking up the vast majority of free space for some reason.

I'm new to linux so I don't really know what /dev/root is. Linux says it's not a directory. I suspect it may have been building up and up with data over time as I've been running my server.

Does anyone know why this may be happening or how to find out? What can I do to make space without doing anything I'll regret? Thanks in advance

gp flag

That is saying that you have 7.7GB available in your main file system, and you've filled it. It's not AWS / EC2 who've filled it, it's files on your instance.

BEFORE you do anything go into the AWS console and take a snapshot (aka backup) of your EBS instance. You can do this while the instance is running and it should be ok, but for a 100% consistent backup you can stop the instance first. DO NOT terminate the instance or you will lose your disk.

You have a couple of options:

Here's how to install and run ncdu

sudo su
apt update
apt install ncdu
cd /
ncdu .
SSC Fan avatar
cn flag
Thanks for your response. I've been getting "Temporary failure resolving" messages when trying to install the ncdu utility unfortunately. However, I think I found (a) huge source of the bloat. Mail! Deleting all my mail (which was recording printed messages from my scripts) freed up a ton of space. I'll hope to get ncdu working for future reference though!
Tim avatar
gp flag
ncdu is a tiny utility that should install with zero hassle. Check if you can do apt update / apt upgrade, you may have connectivity not quite right. Try standard things like ping / curl a random website over http and https as well
SSC Fan avatar
cn flag
something is definitely wrong with my connectivity. When I try to run my python scripts with the requests module (which were working before) I'm getting the error: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'). and apt upgrade is giving me the same Temporary failure resolving issue
Tim avatar
gp flag
Start a new question for that. Including some diagnostics like creating a new Amazon Linux 2 instance in the same subnet and seeing if it can ping / curl places. If so it's your instance, if not it's usually internet gateway, routing, NACL, or SG.

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.