2

I recently got a "device full" warning for a 2 Tb external ext4 drive. I deleted a bunch of files, about 90-100 Gb of old system backups, and since I did not want to empty all trash, I deleted the trash folders from the drive. No disk space was freed however, and I am still showing only about 5 Gb free after deleting 90-100Gb.

I first tried rebooting to make sure it was not files being held open for some reason. I tried running sudo e2fsck -fp /dev/sde1 and sudo e2fsck -f -D -C0 -E discard /dev/sde1 but neither of these turned up any disk space. I checked inode usage, and am using something like 0.3% of the total. When I run sudo xdiskusage, it says that inodes are using up 93 Gb. man says this is the overhead used by the file system. 93 gb seems like a lot of overhead, and the fact that deleting about the same amount of files resulted in no freed disk space, I am guessing I fouled something up when I deleted the trah folders. Is there any way I can reclaim the space that I thought I would get from deleting the files?

6
  • 1
    You checking the free space as root or as a normal user? Often systems will reserve some space for root, so you may have deleted a lot of that space that is just freeing up the space the report reserves for root and that's why you didn't seem to get as much back as you expected. – Eric Renouf Apr 22 '15 at 1:00
  • 1
    Might those backups have had hard links that you didn't delete? – Gilles 'SO- stop being evil' Apr 22 '15 at 1:09
  • Just following up on my previous comment, ext3 apparently reserved 5% that way, which would be ~100GB on a 2TB drive. I don't know if ext4 reserves less – Eric Renouf Apr 22 '15 at 1:23
  • @eric-renouf, I ran xdiskusage as root. I saw a command to change the amount reserved for root in my googlings, but now I can't find it. – Richard Rath Apr 22 '15 at 2:26
  • 1
    @EricRenouf ext2/3/4 all reserve the same 5%, by default. You can override the default via -m , either initially when running mke2fs or later with tune2fs. – derobert Apr 22 '15 at 3:09
3

There seem to be two possibilities here:

  1. You're being confused by the (admittedly confusing) behavior of df and root-reserved space
  2. You deleted (unlinked) one hardlink to the files, there are more.

Personally, I suspect you're seeing #1. Details below, along with some concluding remarks.

Confusing df behavior

If you fill up a filesystem fully, as a non-root user, this is what it looks like:

Filesystem      Size  Used Avail Use% Mounted on
/dev/md10       248M  236M  1.0K 100% /boot

but there is space reserved for root, typically 5%. If root fills it up, this is what df looks like (in the case of this tiny filesystem, it's another 13 MB):

Filesystem      Size  Used Avail Use% Mounted on
/dev/md10       248M  248M     0 100% /boot

Note it went from 100% used to... 100% used. Despite actually being another 5% used. The Used field went up as expected, but the avail field just changed from 1K to 0.

And what happens when you remove the first 13MB of data? Well, you get back to the first output—you've freed 5%, but still at 100% in use and almost none available.

Conclusion: when you want to look at how much space you're actually freeing, look at the Used column—not Avail, not Use%.

Wasn't the last hardlink

rm doesn't actually delete files. It unlinks them—that is, removes hardlinks to them. Each hardlink gives the file one name, basically. When a file has no links left (and isn't open, etc.) then, only then, is the file actually deleted.

A file is actually uniquely identified on a filesystem, regardless of the number of names it has, by its inode number. If you knew the inode numbers for these files, you could use find -inum to find all the hardlinks to them—but you probably don't. If you have some related files to clean up, you can get the inode numbers from those using stat. You can then use find /path/to/mount -inum NUMBER to find all the hardlinks to that file (including the name you just stat'd). Also, inode numbers can be re-used once a file is actually deleted.

Remember: inode numbers are per filesystem. So two different files can be inode 42 on two different filesystems. Only on the same filesystem is inode 42 guaranteed to always be the same file. Also, inode numbers do not always work right with network filesystems or non-Unix filesystems. But you're using ext4, where the definitely do.

Other than that, you'll just have to find any other names to remove the normal ways (e.g., by looking for large things with xdiskusage as you're already doing)

General remarks

Trash folders are just directories. If they were full of junk that you didn't manage to delete, they'd show in xdiskusage.

You should consider a backup system which can better handle deleting old backups for you—doing it by hand is error-prone. Worse, it can also be forgotten, leading to backup failures—and restores are generally of recent data (e.g, accidental deletion, corrupted file, disk failure), not old data ("oh yeah, I did need that thing I deleted last year..."), so "disk full backup failed" means you're actually discarding the most valuable data (the new backup) to preserve the least valuable data (that backup from two years ago).

7
  • THanks for this detailed explanation. df returned the following as regular user and the exact same thing as root /dev/sde1 1.8T 1.7T 5.2G 100% – Richard Rath Apr 22 '15 at 3:49
  • @Rich that's consistent with either, you'd need the df output from before deleting them to compare. I'm guessing #1, though. – derobert Apr 22 '15 at 3:56
  • I have full backups (1 of the system, 1 from crashplan with my data, + data in dropbox mirrored to about 4 computers. The backup I deleted was to a borked system backed up as root. I reinstalled OS, restored my data & made a new root system backup in a new folder & deleted the bad backup. From what you are saying, there must be hardlinks somewhere but I have no idea where they could be. I am still not seeing how I can delete a 100 gig root-owned folder, remove trash, and still have only 5 gigs left as both root or user. I hope I am not missing something in your explanation. – Richard Rath Apr 22 '15 at 4:06
  • @Rich df always displays the amount available to a user, even if run as root. You have more than that free, look at the difference between Size and Used. Avail is confusing due to the reserved space. – derobert Apr 22 '15 at 4:12
  • hmm, ok, I see that 1.8T-1.7T=100G. I saw a command to change the amount reserved for root somewhere (it was a switch to something). I really don't think I need to reserve any for root, since nothing is actually run on the disk. It is all backups basically. Do you happen to know that command/switch. I can find it again, but have not been able to so far. Thanks for your help on this. – Richard Rath Apr 22 '15 at 4:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.