Where did my disc space go?

January 8, 2019 596 views
Storage Ubuntu 16.04

To start, I am fairly new at linux. I bought a 1 GG Ram 25 GB droplet to host a small game server with about 5-10 friends.

I installed TightVNC and a docker program for Neverwinter Nights Enhanced edition. I know the latter is taking up about 500 mb. I do often log into a cloud drive to download new maps to play on, and promptly delete the old ones. These are about 50 mb each.

I was rather surprised today to learn I had only 30 mb of disc space left. I the following and learned that 21 gb of space was in var.

cd / && sudo du -h --max-depth=1

I see some of that I cannot even access as root. I am guessing its infrastructure on your end. Is there a way to see when all this space might have vanished? I am purchasing backups. I am not sure if they are being stored somewhere and eating up my space? Or if possible I can load a previous backup where I hadn’t consumed so much.

Any help would be appreciated.

2 Answers

If you enabled Backups from the DO control panel they are not stored on your droplet, so they are not eating up your diskspace.

The /var directory is often used to store log files and most of them can be found in /var/log which is most likely where your diskspace is being used up.

As the root user you will have access to all of the directories on your droplet. I would recommend you do the following:

user$ sudo su -
root# cd /var
root# du -hcs * | grep G

The first part sudo su - is basically going to log you in as root and take on all of the environment variables of your root user. Because you are currently logged in as a regular user and then using sudo you can get some “Permission denied” errors when traversing directories, this is because of how the sudo command routes everything along with echo. To avoid that you can just become the root user using sudo su -

Then go to your /var directory and enter the du -hcs * command, this will output the filesizes of everything in that directory. Then you send that output to grep using the pipe | command and the “G” is literally searching for a capital G, which is going to be short for GB in human readable format which is the -h flag that you sent to du.

At this point you should see something along the following:

root# du -hcs * | grep G
1.0G    db 
4.0G    vm
5.7G    total

Now you know which directories are taking up the most space so you can go through them and browse around. Note that when you find the specific files that are taking up the space do not delete them using rm. If you do that you may not free up diskspace. This is because the way files are stored on linux is through links. When all of the links to the file are gone then the file is removed. However, if the space is taken up by a log file and it is currently open and being written to when you issue the rm command you will simply remove the link inside the directory to the file, however the file will remain open by the process that is currently running and still writing data to it.

Instead, to clear out a log file without deleting it you can do the following:

root# cat /dev/null > /var/log/logfile

This will basically clear out all of the data in the file, return the diskspace back to the system, and won’t require you to delete the file either. If it’s a regular file that isn’t currently open and being written to you can delete it with rm and not worry about using /dev/null instead.

After you’ve cleaned out the log file you can find the process that was writing to it, review your configuration and setup log rotation which will reduce the diskspace used and keep it to a contained amount, or you can disable logging and then restart the process and not have to worry about it going forward.

If you run into any issues let me know and we can review further after you have more details on where the diskspace is actually being used.

Hope this helps your troubleshooting.

Thank you for your thorough reply!

May I ask what is logging exactly? Can I simply delete all the files in that folder and be done with it? And should I always use this method instead of -rm when deleting files?

I appreciate the help.

Have another answer? Share your knowledge.