I have worked with Linux (and other UNIXes) for some 20+ years, and this is a scenario I come across often enough.
Firstly, there is no need to reinstall - I have never had to, and I can't really imagine why it would be necessary. A full root filesystem just means you can't store any more data, but what is already there is OK; there may be some data that got corrupted - eg in a database - but I haven't seen that often enough to remember it. In your case, you can't log in because your shell or desktop manager needs to store some data and can't; you just need to free up some space.
The thing to do is, get to a command line - if you can boot up from a live distribution, like the others say, do that, open a terminal and mount the filesystems you need to work on, if hasn't already happened. First find the disk devices (use df
to list what is already mounted):
# df
Filesystem 1K-blocks Used Available Use% Mounted on
tmpfs 26379228 3284 26375944 1% /run
/dev/nvme1n1p4 863630096 744645468 75040948 91% /
tmpfs 131896140 4 131896136 1% /dev/shm
...
fdisk -l
...
Disk /dev/loop7: 55.52 MiB, 58212352 bytes, 113696 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/nvme1n1: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: Samsung SSD 970 EVO Plus 1TB
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 2217FDA8-ADEA-49F9-B6A0-A7A26460B6FA
Device Start End Sectors Size Type
/dev/nvme1n1p1 34 32767 32734 16M Microsoft reserved
/dev/nvme1n1p2 32768 195381657 195348890 93.1G Microsoft basic data
/dev/nvme1n1p3 195383296 196431871 1048576 512M EFI System
/dev/nvme1n1p4 196431872 1953523711 1757091840 837.8G Linux filesystem
...
Ignore the /dev/loop
ones, they are the manifestations of the idiotic snap
thing that plagues Ubuntu. For each of the ones marked Linux filesystem
, create a mount point somewhere and mount it:
# mkdir /myroot
# mount /dev/nvme1n1p4 /myroot
I suspect you have everything on just one partition, apart from the EFI partition, if you're using that. So, what often happens is that either /tmp or /var fills up, and since everything is on the same partition, you root filesystem runs out of space. Here's what I usually do:
Find out where all the space has gone; for that use du
(in the following I run as root, 'cause I'm hardcore (aka stupid), but you can use sudo
in front of all the commands instead, except for the cd
commands):
# cd /
# du -sk etc home lib* mnt opt root snap tmp usr var | sort -n
Why shouldn't you put sudo
in font of cd
? Because sudo cd /some/directory
executes in a sub-shell, and when the command is done, you will be back where you started.
du
shows how much space is used, and -sk
says to sum up in KB; normally you would use is like du -sk *
, but I find it often hangs in certain sub-directories in the root, so I tend to avoid those. The | sort -n
part takes the output and sorts it numerically, so you will see the biggest sinners at the bottom. Say you've found out it is /var
:
# cd /var
# du -sk * | sort -n
- and so on. In this case you'll probably find that it is
/var/log
that has grown too large, and you can generally delete some of the files in there without problems. Another place you can delete from is /tmp
, BTW.
Then to delete, use rm
:
# # In /var/log:
# ls
alternatives.log btmp lastlog
alternatives.log.1 btmp.1 openvpn
alternatives.log.2.gz cups private
alternatives.log.3.gz dist-upgrade speech-dispatcher
alternatives.log.4.gz dmesg syslog
alternatives.log.5.gz dmesg.0 syslog.1
alternatives.log.6.gz dmesg.1.gz syslog.2.gz
...
The files that end in .gz
are older, compressed log files that can normally be discarded - but be careful, try first with ls to see what you will be removing:
# ls *gz
# rm *gz
Always use ls
when you think of deleting things with any sort of wildcard or regular expression!
Once you've finished this exercise, you should have freed up plenty of space, and next time you install a Linux system, remember to place things like /var
, /opt
and /tmp
(as well as the ones you found were too large) on separate partitions. You may still run out of space, but at least it is likely to be less hassle.