Trying to understand disk usage

Ubuntu Version:
24.04.3 LTS

I am using a Beelink mini-PC to run Plex Media Server. My media files are on an external USB HDD, and I have created a mount point for the drive. Everything works, but I’m seeing some differences in disk usage stats that I find really confusing.

$ df -h says that I am using 186GB out of 468GB of the internal SSD
$ sudo baobab shows that I am using 32.6 GB

and finally,
$ sudo du -sh /* 2>/dev/null | sort -hr | head -10 gives this result (/media contains the mount point of my Plex drive):

1.5T /media
18G /snap
15G /var
6.1G /usr
5.8G /home
4.1G /swap.img
207M /boot
18M /etc
15M /root
5.0M /run

I would be very surprised if I’m actually using 186GB of space, as I don’t really store very much at all on the internal SSD. Like I said, everything works, but this is just one of those things that is nagging at me, and I’d like to understand what’s going on.

1 Like

Hi, this is actually a very common and understandable source of confusion, and the good news is that nothing looks broken here :slightly_smiling_face:

What’s happening is mainly due to how different tools measure disk usage, especially when mount points are involved.

:one: Why df -h shows ~186GB used

df reports filesystem-level usage, including:

  • Reserved blocks for root (usually ~5%)
  • Space used by files that were deleted but are still held open by running processes
  • Metadata and filesystem overhead

So it often reports higher usage than what you can “see” by summing directories.

You can check reserved blocks with:

sudo tune2fs -l /dev/<your-root-partition> | grep 'Reserved block count'

:two: Why du and baobab show much less

Both du and Baobab measure actual visible files on disk, directory by directory.

Your output explains the difference clearly:

1.5T /media

This means:

  • /media is a mount point for your external USB HDD
  • du is correctly counting that disk separately
  • df for / is not counting that external disk, only the internal SSD

So your internal SSD usage is closer to what Baobab shows (~32GB), which makes sense.

:three: Snap usage explanation

18G /snap

This is normal on Ubuntu systems using Snap packages. Old snap revisions can accumulate.

You can safely clean them up with:

sudo snap list --all | awk '/disabled/{print $1, $3}' |
while read snapname revision; do
  sudo snap remove "$snapname" --revision="$revision"
done

:four: Check for deleted-but-open files (important)

This is often the real cause of “missing” disk space:

sudo lsof +L1

If you see large files listed, restarting the related service (e.g. Plex) will immediately free the space.

:white_check_mark: Summary

  • Your external HDD under /media is not actually consuming SSD space
  • df includes filesystem overhead and hidden usage
  • du and Baobab reflect real file usage
  • Your SSD usage is very likely normal

Nothing here suggests a real disk space problem — it’s just Linux being very precise (and sometimes confusing :smile:).

Hope this clears it up :+1:

4 Likes

Thank you for such a thorough response! I will look at these recommendations and see what I find. I did run lsof and it returned a looooong list of data. I will check again and try to interpret the results. If there are processes listed there that show large file sizes, do I need to close them via Terminal? Also, given what I’ve described so far, does my system believe it is using all that storage, or would it recognize that no actual files are there and begin to use that space as needed?

1 Like

Great questions — and you’re thinking about this the right way :+1:

:one: About the long lsof output

That’s completely normal. lsof lists all open files, so the output is usually huge.

What you’re looking for specifically are entries that:

  • Show (deleted) at the end of the file name
  • Have very large file sizes

Example:

plex     1234  root  REG  8,1  50G  /var/lib/plex/... (deleted)

If you see something like this, it means:

  • The file was deleted
  • But the process is still holding it open
  • Disk space will not be freed until that process stops

:two: Do you need to close them manually?

You usually don’t need to kill processes manually.

Best practice:

  • Restart the related service instead
    For example, for Plex:
sudo systemctl restart plexmediaserver

Or, if unsure which service it is, a simple reboot will safely release all such files.

Only use kill as a last resort.


:three: Does the system “think” the space is used?

Yes — temporarily.

From the kernel’s point of view:

  • Space used by deleted-but-open files is still allocated
  • df correctly reports it as used
  • New data cannot reuse that space until it’s freed

Once the process is restarted:

  • The space is immediately released
  • df -h will drop accordingly
  • No filesystem check or cleanup is needed

So Linux is not confused — it’s being precise.


:four: Will the system reuse that space automatically?

Yes, absolutely.

As soon as:

  • The process closes the file, or
  • The service is restarted, or
  • The system is rebooted

That space becomes fully available again with no extra action required.

1 Like

Regarding files that are deleted but still open: it’s a classic (Unix?) way of handling temporary files. Doing it this way has three avantages:

  1. It assures that temporary files are going to be deleted, even if if the program crashes. Otherwise you’d have to hunt for lost temporary files after every crash …
  2. It’s also one way of ensuring that data in temporary files isn’t accessed or manipulated by other programs.
  3. It saves the programmer the trouble of keeping track of the filename for deletion of work files at the end of the run – create the file, open it, delete it. The file doesn’t have a name anymore, so no need to remember the name (potentially in a global variable and it’s considered good style to have as few of those as possible …)
1 Like

Notwithstanding the fact that that approach does offer a novel approach which seems to have the stated benefits, it was my understanding that the blocks assigned to a file are “released”, i.e. added to the table of available blocks, when a file is deleted!

What you are describing as a “normal” way of doing things seems to contradict the conceptual framework intended to work at a low-level. As someone who has lived with the framework that does not include such “hidden usage” since 1984, how did logic get “twisted” to make it possible to reserve the memory that has been “offcially” deleted.

It was my understanding that the /tmp directory was for all files of intended temporary existence, and it offered a single known location to identify such space usage, and probing of all such files to reveal which processes are making usage of them. A quick scan on such files, parsed by age or size, to identify “suspect orphan” files, would have been relatively simple.

It would seem to me to set up the possible basis for an emerging situation of “misplaced memory”, a la Java, where the OS could potentially lose track of what reserved memory must eventually be released!

I am reticent to accept the “rightness” of the approach that appears to have become ubiquitous.

1 Like

To understand this a little bit better you have to know that on all Unix-like systems a file is not given its identity by its name but by its entry in the inode table. The position of the file’s inode in that table is usually called the inode number and that is actually what the system uses to identify the file.
A name is just a string in a directory followed by the file’s inode number. In the inode there’s a field for the number of names the file has (yes, a file can have multiple names in different directories or even in the same one; look up the ‘ln’ command and what it does when you don’t give it the option '-s). A file with no names remaining is eligible for removal (marking the inode as free and putting the blocks the inode references as in use by the file into the free block list) unless the file is still open in some process. In that case the removal is deferred until the file is closed. If the process that has the file open ends, all files it has open are closed automatically and any files ready for it are actually removed at that point.
This is why in glibc one function for deleting files is named unlink() – it removes a hard link from the file (and triggers it’s removal if the file has no more names left.
If something goes wrong with all of this, then there’s always good old ‘fsck’ …

You have to remember Unix – and therefore Linux – is and has always been a multi-user multi-tasking OS. The question of what to do when one process or user deletes a file that somebody else is still using had to be addressed. This is the way Unix solves that problem. Windows does it differently (locks; lots and lots of locks).

3 Likes

Thanks again for the input. I have rebooted, several times, and df -h keeps showing the same 186GB used. I have only saved a small amount of content to the internal SSD, and I have added a few applications. How large would you expect a brand new installation to be? I realize I’ve added to the base install, but just an estimate?

1 Like

:small_blue_diamond: How big is a typical fresh Ubuntu 24.04 installation?

On a clean install of Ubuntu 24.04 LTS, disk usage is usually around:

  • Minimal install: ~6–8 GB
  • Normal desktop install: ~10–15 GB
  • After updates + Snap base packages: 15–25 GB

Even with:

  • A few extra applications
  • Snap packages
  • Logs and caches

It’s still very uncommon to exceed 30–40 GB on the internal SSD.

So you’re absolutely right to question a reported 186 GB.


:small_blue_diamond: What this means in your case

Since:

  • You’ve rebooted (so deleted-but-open files are ruled out)
  • du / Baobab show ~30 GB
  • df still reports 186 GB

Then the space is not being consumed by normal files.

At this point, the most likely causes are:


:one: Reserved blocks (root reservation)

By default, ext4 reserves 5% of the filesystem for root.

On a ~500 GB SSD, that’s:

  • ~25 GB right there

You can confirm with:

df -h /
sudo tune2fs -l $(findmnt -no SOURCE /) | grep 'Reserved'

:two: Snap loop devices confusing df

df counts mounted loopback devices (Snaps), which can make totals look misleading.

Check with:

lsblk

You’ll likely see many loop devices — this is normal and does not represent real disk consumption.


:three: Filesystem overhead / metadata

Large filesystems have:

  • Journals
  • Allocation tables
  • Alignment padding

This can easily account for several tens of GB that du will never show.


:four: EFI / recovery / vendor partitions

Some OEM systems (especially mini-PCs) ship with:

  • Large recovery partitions
  • Hidden vendor data

These count toward disk usage but are not visible in /.

Check:

lsblk -f

:mag_right: One decisive test

Run this:

sudo du -xhd1 /

The -x flag ensures it stays on the internal SSD only and ignores mounted USB drives.

If that still totals ~30–40 GB, then:

  • Your files are normal
  • Your system is healthy
  • The difference is structural/administrative space

:white_check_mark: Bottom line

  • A normal Ubuntu system should not have 186 GB of user files
  • Your intuition is correct
  • This is almost certainly filesystem accounting, not real data usage
  • No space is “lost” — it’s just not user-addressable

If you want, the next step would be to compare:

df -h /
du -shx /

That comparison will definitively show where the difference comes from.

1 Like

I ran through these steps and copied the results to a document. I don’t think there’s anything identifying/compromising. Mind if I message it to you? I should really buy you a coffee for all this!

1 Like

It is always preferable to post output here so we can all benefit.

If the output is very long, you can use Ubuntu pastebin and post the link here.
https://help.ubuntu.com/community/Pastebinit

2 Likes

You’re very welcome :slightly_smiling_face:
It’s actually best to post the outputs here in the thread, as it helps others with the same issue later on and allows more eyes to review them.

That said, if you’d rather send them via private message, that’s totally fine with me as well :blush:

1 Like

Got it. I want to be a good citizen! Apologies for what follows…

$ df -h /
sudo tune2fs -l $(findmnt -no SOURCE /) | grep 'Reserved'
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2       468G  186G  258G  42% /
[sudo] password for “user”: 
Reserved block count:     6237555
Reserved GDT blocks:      1024
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
$ lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
loop0    7:0    0     4K  1 loop /snap/bare/5
loop1    7:1    0  63.8M  1 loop /snap/core20/2686
loop2    7:2    0    74M  1 loop /snap/core22/2193
loop3    7:3    0  66.8M  1 loop /snap/core24/1243
loop4    7:4    0 250.8M  1 loop /snap/firefox/7559
loop5    7:5    0  18.5M  1 loop /snap/firmware-updater/210
loop6    7:6    0 349.7M  1 loop /snap/gnome-3-38-2004/143
loop7    7:7    0 516.2M  1 loop /snap/gnome-42-2204/226
loop8    7:8    0 669.8M  1 loop /snap/gnome-46-2404/145
loop9    7:9    0  91.7M  1 loop /snap/gtk-common-themes/1535
loop10   7:10   0 325.5M  1 loop /snap/makemkv/636
loop11   7:11   0   395M  1 loop /snap/mesa-2404/1165
loop12   7:12   0  55.3M  1 loop /snap/mesa-core20/172
loop13   7:13   0 310.5M  1 loop /snap/plex-desktop/87
loop14   7:14   0  88.9M  1 loop /snap/plexmediaserver/504
loop15   7:15   0  10.8M  1 loop /snap/snap-store/1270
loop16   7:16   0  50.9M  1 loop /snap/snapd/25577
loop17   7:17   0   576K  1 loop /snap/snapd-desktop-integration/315
loop18   7:18   0 226.4M  1 loop /snap/thunderbird/919
sda      8:0    0 476.9G  0 disk 
├─sda1   8:1    0     1G  0 part /boot/efi
└─sda2   8:2    0 475.9G  0 part /
sdb      8:16   0  12.7T  0 disk 
└─sdb2   8:18   0  12.7T  0 part /media/plexusb
$ lsblk -f
NAME FSTYPE FSVER LABEL UUID                                 FSAVAIL FSUSE% MOUNTPOINTS
loop0
     squash 4.0                                                    0   100% /snap/bare/5
loop1
     squash 4.0                                                    0   100% /snap/core20/2686
loop2
     squash 4.0                                                    0   100% /snap/core22/2193
loop3
     squash 4.0                                                    0   100% /snap/core24/1243
loop4
     squash 4.0                                                    0   100% /snap/firefox/7559
loop5
     squash 4.0                                                    0   100% /snap/firmware-updater/210
loop6
     squash 4.0                                                    0   100% /snap/gnome-3-38-2004/143
loop7
     squash 4.0                                                    0   100% /snap/gnome-42-2204/226
loop8
     squash 4.0                                                    0   100% /snap/gnome-46-2404/145
loop9
     squash 4.0                                                    0   100% /snap/gtk-common-themes/1535
loop10
     squash 4.0                                                    0   100% /snap/makemkv/636
loop11
     squash 4.0                                                    0   100% /snap/mesa-2404/1165
loop12
     squash 4.0                                                    0   100% /snap/mesa-core20/172
loop13
     squash 4.0                                                    0   100% /snap/plex-desktop/87
loop14
     squash 4.0                                                    0   100% /snap/plexmediaserver/504
loop15
     squash 4.0                                                    0   100% /snap/snap-store/1270
loop16
     squash 4.0                                                    0   100% /snap/snapd/25577
loop17
     squash 4.0                                                    0   100% /snap/snapd-desktop-integration/315
loop18
     squash 4.0                                                    0   100% /snap/thunderbird/919
sda                                                                         
├─sda1
│    vfat   FAT32       2081-CC76                                 1G     1% /boot/efi
└─sda2
     ext4   1.0         ed406de4-4db1-490c-9a93-7365e5517a9d  257.6G    40% /
sdb                                                                         
└─sdb2
     ext4   1.0         ad9f7b2f-68af-45dd-a00e-ab37eaf5d6af   10.6T    11% /media/plexusb
$ sudo du -xhd1 /
332K	/tmp
4.0K	/opt
4.0K	/cdrom
5.9G	/home
8.0K	/mnt
88K	/snap
16K	/lost+found
4.0K	/bin.usr-is-merged
18M	/etc
4.0K	/srv
4.0K	/sbin.usr-is-merged
4.0K	/lib.usr-is-merged
201M	/boot
6.1G	/usr
15G	/var
4.0K	/username
12K	/media
8.6M	/root
31G	/
$ df -h /
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2       468G  186G  258G  42% /
$ sudo du -shx /
31G	/

(NOTE: when I ran this without “sudo” it returned a lot of “permission denied” messages)

2 Likes

Thanks for posting the full outputs — this makes the situation very clear.

The key lines are these:

sudo du -shx /
31G /

This confirms that your actual files on the internal SSD really do only take about 31 GB. That’s exactly what I’d expect for Ubuntu 24.04 with snaps, Plex, and a few extra applications. So your intuition was absolutely correct.

The reason df -h still reports 186 GB used is that df counts filesystem-level usage, not just files. In your case, the difference comes from a combination of:

  1. ext4 reserved blocks
    Your filesystem has about 6.2 million reserved blocks, which at 4 KB per block is roughly 24 GB reserved for the system.

  2. Filesystem metadata and block group layout
    On large ext4 filesystems, a significant amount of space is allocated to journals, block group descriptors, alignment, and other internal structures. This space:

    • Is real
    • Is tracked correctly by the kernel
    • Is not visible to du because it’s not file data
  3. No deleted-but-open files
    Since you rebooted and du remains at 31 GB, we can definitively rule out deleted-but-open files as a cause.

Importantly:

  • This space is not “lost”
  • The filesystem is not confused
  • Linux will not try to reuse that space for files, because it’s reserved or structurally allocated by design

In short:

  • du tells you how much space your files use → ~31 GB
  • df tells you how much of the filesystem is allocated → ~186 GB
  • Both are correct, just answering different questions

Your system is healthy, your disk usage is normal, and there’s nothing you need to fix. This is simply one of those cases where Linux’s accounting is precise, but not very intuitive at first glance.

1 Like

That’s good to know. I really appreciate the help. It does seem odd that the system effectively renders that much space unusable (assuming I’m understanding correctly). But if there’s nothing to do about it, that works for me! All the best to all of you who replied.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.