2

I have a Raspberry Pi that is running a bunch of scripts 24/7. Recently it has been giving me errors because the Disk is full. I checked /var/log and there were no gratuitously large files there. I used NCDU and it is saying that the total Disk Usage is 22.2 mb. Are there hidden files or directories that have filled up? Any help is greatly appreciated :). Thank you in advance

Filesystem      Size  Used Avail Use% Mounted on
/dev/root       4.9G  4.8G     0 100% /
devtmpfs        428M     0  428M   0% /dev
tmpfs           432M     0  432M   0% /dev/shm
tmpfs           432M  5.9M  426M   2% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           432M     0  432M   0% /sys/fs/cgroup
/dev/mmcblk0p5   60M   20M   41M  33% /boot
tmpfs            87M     0   87M   0% /run/user/1000

after running this command: sudo find /var -type f -a -printf '%s %p\n'| sort -nr | head -10
I found this:

104857600 /var/swap
46641296 /var/lib/apt/lists/mirrordirector.raspbian.org_raspbian_dists_jessie_main_binary-armhf_Packages
22031232 /var/cache/apt/pkgcache.bin
22010693 /var/cache/apt/srcpkgcache.bin
2808989 /var/cache/debconf/templates.dat-old
2808989 /var/cache/debconf/templates.dat
2334288 /var/lib/aspell/en-common.rws
1803157 /var/lib/dpkg/info/keyboard-configuration.config
1182618 /var/lib/dpkg/info/ri1.9.1.md5sums
1114891 /var/lib/dpkg/info/sonic-pi.md5sums
Yllier123
  • 155
  • 1
  • 8
  • 2
    please edit your question and add the output of df -h what is the size of the SD card? Did you expand the root file system? – Steve Robillard Dec 31 '15 at 16:00
  • 2
    I would suggest `du -h / | sort -h` to find the storage hogs (disk usage of every file in human readable {uses letters for K/M/G/T multipliers} then sorted into largest of those human readable number forms last) but that uses a pipe and that might need temporary storage for the intermediate data so may not be able to run... – SlySven Dec 31 '15 at 20:09
  • @SteveRobillard I have expanded the file system to occupy the entirety of the card – Yllier123 Jan 01 '16 at 15:22
  • What is the size of SD card you are using? – Steve Robillard Jan 01 '16 at 15:23
  • @SteveRobillard 8 Gigs. When expanding the filesystem from rapsi-config it says that the filesystem is already at maximum because I am running raspbian – Yllier123 Jan 01 '16 at 15:28
  • Do you have more than 1 OS on this card? or another partition? The numbers above just don't add up? I would try running @SlySven suggestion to see what is using that much space on the / partition – Steve Robillard Jan 01 '16 at 15:30
  • @SteveRobillard I have only 1 operating system on this card. The top 4 directories output by SlySven's command are: `836M /usr/share 1.2G /usr/lib 1.7G /root 2.2G /usr` – Yllier123 Jan 03 '16 at 15:01
  • I am suspecting that you have a hidden partition because the size of the partitions is only about 6Gb. I would suggest using gparted or the low level fdisk method to research further what is going on. This question may help http://raspberrypi.stackexchange.com/questions/499/how-can-i-resize-my-root-partition/501#501 – Steve Robillard Jan 03 '16 at 19:55
  • I have been writing to the SD a lot, is it possible that I destroyed the card? @SteveRobillard – Yllier123 Jan 04 '16 at 15:39
  • That is not likely. You can use the command suggested by @SlySven above and change the directory from / to on eof the subdirectories that will show the biggest directory/files. If it were me I would pickup a bigger SD Card, they tend t be on sale right now. – Steve Robillard Jan 04 '16 at 15:45
  • Ah, that command I gave looks as though it actually gives the usage by (all the files in a) directory... but it is still good to find where space is being eaten! 8-) – SlySven Jan 05 '16 at 11:26

1 Answers1

1

ncdu should show you where your available space has gone inclusive standard hidden files (starting with a dot). ncdu starts reading from your current location, so make sure to change the current directory to the root of the directories (/) before you invoke ncdu.

shy@raspi ~ $ cd /
shy@raspi / $ ncdu

You should get a screen with something like this (note the --- / ------ in the second line on top of the screen):

ncdu 1.8 ~ Use the arrow keys to navigate, press ? for help
--- / --------------------------------------------------------------------------
    1.6GiB [##########] /usr
  572.0MiB [###       ] /opt
. 380.1MiB [##        ] /var
  116.2MiB [          ] /lib
   19.5MiB [          ] /boot
    6.6MiB [          ] /sbin
.   5.2MiB [          ] /etc
    5.2MiB [          ] /bin
.   4.3MiB [          ] /home
. 556.0KiB [          ] /run
!  16.0KiB [          ] /lost+found
   12.0KiB [          ] /tmp
.  12.0KiB [          ] /media
e   4.0KiB [          ] /srv
e   4.0KiB [          ] /selinux
!   4.0KiB [          ] /root
e   4.0KiB [          ] /mnt
.   0.0  B [          ] /sys
    0.0  B [          ] /dev
.   0.0  B [          ] /proc

 Total disk usage:   2.7GiB  Apparent size:   2.5GiB  Items: 124118

You can dig into the directories where the most space got used. In my example I would start at /usr of course.

However, this doesn't explain why less than 7 GB of your 8 GB disk are used. The print all command within parted might shed some light on this:

shy@raspi ~ $ sudo parted
GNU Parted 2.3
Using /dev/mmcblk0
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print all
Model: SD SD16G (sd/mmc)
Disk /dev/mmcblk0: 15.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type      File system  Flags
 1      4194kB  863MB   859MB   primary   fat32        lba
 2      864MB   15.7GB  14.8GB  extended
 5      868MB   1405MB  537MB   logical   ext4
 6      1409MB  1472MB  62.9MB  logical   fat16        lba
 7      1476MB  15.7GB  14.2GB  logical   ext4
 3      15.7GB  15.7GB  33.6MB  primary   ext4

(parted) q
shy@raspi ~ $

You can also use fdisk -l to display your partition layout:

shy@raspi ~ $ sudo fdisk -l

Disk /dev/mmcblk0: 15.7 GB, 15720251392 bytes
4 heads, 16 sectors/track, 479744 cylinders, total 30703616 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 identifier: 0x0009c1a7

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            8192     1685546      838677+   e  W95 FAT16 (LBA)
/dev/mmcblk0p2         1687552    30638079    14475264   85  Linux extended
/dev/mmcblk0p3        30638080    30703615       32768   83  Linux
/dev/mmcblk0p5         1695744     2744319      524288   83  Linux
/dev/mmcblk0p6         2752512     2875391       61440    c  W95 FAT32 (LBA)
/dev/mmcblk0p7         2883584    30638079    13877248   83  Linux

Your results may vary. I'm using a 16 GB SD card with Raspian Debian Wheezy.