5

My SD card is full, but I don't know how to find the files/folders to blame.

Here is my df -h output:

pi@raspberrypi1 ~ $ df -h
Filesystem                   Size  Used Avail Use% Mounted on
/dev/root                    6.3G  5.7G  256M  96% /
devtmpfs                     459M     0  459M   0% /dev
tmpfs                         93M  272K   93M   1% /run
tmpfs                        5.0M     0  5.0M   0% /run/lock
tmpfs                        186M     0  186M   0% /run/shm
/dev/mmcblk0p5                60M   20M   41M  33% /boot
192.168.2.50:/volume1/video   17T   13T  3.9T  77% /mnt/video
1
  • Try installing "wajig" and running "wajig large". It will display all of the installed packages greater than 10MB. By default, Raspbian comes with 640MB dedicated to Wolfram's math package. If you don't need it, remove it (sudo apt-get remove xxx).
    – BitBank
    Mar 27, 2016 at 22:06

2 Answers 2

4

df does a decent job of giving you an overview of the entire filesystem, but it isn't very helpful for finding folders that are becoming space hogs. du would be much more helpful in this case.

sudo du -h / | sort -h -r | head -n 10

You may need to toggle the number in the head portion of the command, but the above string of commands will give you the top 10 largest directories.

2
  • Just do this BEFORE a file-system becomes completely full - I think those pipes (the |) character in or out of sort may in some situations use space somewhere {/tmp perhaps?} and it can get problematic when you do not have any free space to store the data passing between commands in a pipeline...! {root does have 5% extra space reserved on ext2/3/4 file-systems by default} - but you really do not want to go into the territory of root getting 0 Free blocks on what are supposed to be active, writeable, file-systems - I've been there and it isn't good! 8-(
    – SlySven
    Mar 27, 2016 at 21:45
  • @SlySven: I've never had that happen; that sounds horrible. But unless the user has some odd kernel configurations, that shouldn't happen in this case, at least to the best of my knowledge.
    – Jacobm001
    Mar 28, 2016 at 0:45
4

I've worked it out now, partially due to @Jacobm001's answer - thanks!

I have /mnt/video mounted to an NFS share on my NAS. I have a cron job which automatically downloads (large) videos and places them in this share.

When I ran the sudo du -h / | sort -h -r | head -n 10 command, it listed folders on the NAS (subfolders of /mnt/video, as far as the Pi is concerned), so I did sudo umount /mnt/video before I ran du again... Second time around, there was still a huge folder within /mnt/video.

It seems that at some point, the share wasn't mounted when the cron job ran, and it filled the local disk (i.e. the SD card) at /mnt/video until it ran out of space. When the share was subsequently mounted, the contents of the NAS were shown (as expected), which was why I couldn't work out where the space had gone.

With the share unmounted, I was to copy the files from the Pi to the NAS (using scp) then delete them from the Pi, so now I've got my free space back:

 pi@raspberrypi1 ~ $ df -h
 Filesystem                   Size  Used Avail Use% Mounted on
 /dev/root                    6.3G  2.5G  3.4G  43% /
 devtmpfs                     459M     0  459M   0% /dev
 tmpfs                         93M  272K   93M   1% /run
 tmpfs                        5.0M     0  5.0M   0% /run/lock
 tmpfs                        186M     0  186M   0% /run/shm
 /dev/mmcblk0p5                60M   20M   41M  33% /boot
 192.168.2.50:/volume1/video   17T   13T  3.9T  77% /mnt/video
2
  • might want to add logic to cron job to verify /mnt/video is mounted....
    – lornix
    Mar 27, 2016 at 23:04
  • Yeah, that is a sneaky gotcha! The space is being consumed by something that isn't currently VISIBLE in the filesystem because it is under a directory that something else has been mounted over! Of course if, as a temporary workaround, you are using the --bind, --rbind or --move(?) options of mount to "patch" in extra space from another partition you can really get confused...!
    – SlySven
    Mar 28, 2016 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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