5

We had our samba server (ubuntu 8.04 ltr) share fill up the other day but when I went to look at it I cant see any of the shares have to much on them

we have 5 group shares and then each users has an individual share

one users has 22gigs of stuff a few others have 10-20mb of stuff and everyone else is empty

so maybe like 26gigs total

I deleted a few files yesterday and freed up about 250mb of space today when i checked it it was completely full again and i deleted some older files and freed up about 170mb of stuff but i can watch it slowly creep down in free space.

I keep running a df -h

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda1            241690180 229340500    169200 100% /
varrun                  257632       260    257372   1% /var/run
varlock                 257632         0    257632   0% /var/lock
udev                    257632        72    257560   1% /dev
devshm                  257632        52    257580   1% /dev/shm
lrm                     257632     40000    217632  16% /lib/modules/2.6.24-28-generic

/volatile

what can I do to try to hunt down whats taking up so much of my hdd? (im fairly new to unix in general so i apologize if this is not well explained)

7 Answers 7

5

(This is a Linux focused answer. Other UNIX variants may be different.)

There are two pieces of information relevant to your problem: (1) which files are filling up your file system, and (2) which processes are writing to those files.

Notes

Below, when I put the $ character in commands, that's probably a place holder where you need to substitute a real value. Hopefully, it's obvious where to do that and where not to.

Which Files?

Be aware that there are really two resources in most file system types that can be used up by individual files: meta-data (e.g. inodes), and real data. You can see the number of inodes (search Google for a definition, but they're "pointers" to the structures that make up your files) with a command like:

df -i

... and as you already know, something like this will show the space being used by real data:

df -h

Also, be aware that file system space can be taken up by files that don't exist on disk. These files are still in the open state by some process, but have been removed (we'll cover that below).

Once you've identified the full file system(s), then you need to start looking for lots of little files, a few big files, or both. Running out of meta-data resources is usually caused by having lots of little files, whereas running out of real data resources is usually caused by a few big files. I like to use this command to help find the big files:

sudo find $file_system -mount -ls | awk '{print $7, $11}' | sort -rn > $output

... and this command to help find directories with lots of little files (Update:: added null termination to improve file name handling):

sudo find . -mount -print0 | xargs -0n 1 dirname | sort | uniq -c | sort -rn > $output

... be aware that these commands may take a while to run, and do a lot of I/O, depending. Once run, you can read through $output to find the offending files or directories. The name and location of each may give you a hint about where the data's coming from, but requires some Linux experience.

Once you've identified the offenders, you can rm $file to get rid of the problem.

Which Processes?

The most straight forward way to find the processes potentially filling up your file system is to run a command like:

fuser -c $file_system 2>/dev/null

... which will tell you the PID of processes that have open file descriptors (files and network sockets) for the given file system (the 2>/dev/null part gets rid of some information you don't need). You might be able to deduce just from these PIDs which process is filling up your file system. Search for the processes with:

ps -ef | grep $pid

You can also try running this command which will give you even more detail (and help identify open files with no corresponding file name on the disk -- I mentioned this above):

sudo lsof $file_system | grep $directory_filling_up

... and if you've identified a suspect PID from the fuser command, you can do this:

sudo lsof -p $pid

The problem with fuser and lsof is that they only give you a snapshot of the system at the time your run the command. If the offending process doesn't happen to be writing when you run them, you're out of luck. You can counter this by repeatedly running them over time and saving the output. This will require reading through the output to find patterns, or writing a program to do it for you. An alternative is to use a tool like SystemTap. SystemTap allows you to trap all kinds of useful information, and is "programmable." It even comes with some sample source files that would allow you see what processes are writing to what files over some span of time. It would be perfect, but it's an advanced tool and requires a lot of Linux knowledge.

Once you've identified the offending process(es), you can kill (and maybe restart them). If the process is associated with the operating system or some well packaged software, there will probably be a mechanism for restarting them, but it will depend on your Linux distro (I think Ubuntu will allow you to run something like /etc/init.d/$init_script restart, but you'll have to check your distro's documentation). Otherwise, you can kill it with kill $pid or kill -9 $pid if it's not behaving. Be careful to note how the process was running (e.g. what were it's arguments shown in ps -ef) in case you need to restart it (you may need to refer to that software's documentation).

5

Use du to track down the directory that contains the file(s) that are filling the disk.

cd /
du -h --max-depth 1

will show you which directory in / uses the most space. Traverse the filesystem running the du command to find the culprit.

e.g.

cd /
du -h --max-depth 1

shows /usr is usong 2.3G of the 3.5G used on the system.

cd /usr
du -h --max-depth 1

shows /usr/lib uses 1.1G of the 2.3 in /usr ...


This may also be caused by an open file that has been deleted.

You can use lsof to find files that are open but unlinked (deleted)

lsof +L1

should do the trick. As the man page states:

A specification of the form +L1 will select open files that have been unlinked. A specification of the form +L1 <file_system> will select unlinked open files on the specified file system.

1
  • 2
    sudo du -xb / --max-depth 3 |sort -n ?
    – Tobu
    Jun 16, 2010 at 20:26
3

Something is filling up the / partition. It is probably something in /var/log , or in /home . This depends on your setup. Also look in places where your users have access.

Run the following command in each of the directories in question. This will show you the sub-directories which are the largest consumers of space.

cd /directory
du -cks -x * .* |sort -n

This idea is borrowed from the ducks script (du -cks) from Linux Server Hacks from O'Reilly. I run this command often.

In my experience, this is almost always due to large, growing logfiles. In this case, use Logrotate, and be sure to use compression. Using gzip compression with the default compression ratio, your logfiles will be made smaller by 80-95% (A 1GB /var/log/messages can be easily compressed down to 200MB or less). This puts a moderate amount of load on the CPU, but I have rarely seen this impact the real performance of a server. Some people prefer to use Bzip2 compression, or use gzip --best but in my experience this causes alot of CPU overhead with little added benefit. gzip with the default ratio is usually good enough.

And obviously, this problem is sometimes due to a user doing bad things. Use the du command above to find the culprit.

5
  • 484 auth.log 948 installer 108528 samba
    – Crash893
    Jun 16, 2010 at 19:06
  • Is that in /var/log ? You should have many more files in there, like /var/log/messages . Jun 16, 2010 at 19:19
  • I ran that under / here is what i dont understand under samba there is a user matt that shows up as 209g but when i run the same command under his smbhome folder it shows only 23g
    – Crash893
    Jun 16, 2010 at 19:57
  • That sounds like a possible culprit. Are you talking about one directory, or two? Within each suspect directory, run the command du -cks * .* |sort -n. The largest files will be listed on the bottom of the list. Do you see anything huge? Jun 16, 2010 at 20:47
  • Also, sometimes these disk hogs are not caused by large files, but rather by directories which contain millions of little files. A command like this will show you any directories which contain too-many files -- for DIR in $(find . -maxdepth 1 -type d); do echo "$DIR" ; find $DIR |wc -l; done |sort -n Jun 16, 2010 at 21:16
1

I would use the du command to see which directories are taking up more space, which should suggest which programs are using that space. If you can run graphical apps, there are some nice ones which will help to summarize du's output, such as KDirStat.

1

The likely culprit is the logs, but here is a command that will sort recently modified (or created) files by size:

D=$(date --rfc-3339 date);
sudo sh -c 'find / -xdev -mtime -1 -type f -print0 |xargs -0 du -0sbc' \
  |tee ~/recent-files.$D |sort -zn |tee ~/recent-by-size.$D |xargs -0n1

You could run this command daily; there's probably a way to do something SQL-ish to sort these files by daily growth.


(edit) To monitor growth, use gt5

sudo aptitude install gt5
cd /
gt5

One day later; look for ± signs

gt5
0

Log files may be filling up your hard drive. Use logrotate to stop that.

1
  • how do i do that? (see the above im new to unix statement)
    – Crash893
    Jun 16, 2010 at 18:59
0

Thanks everyone for your help

It turns out that the culprit was a hidden .recycler folder in each of the shared director that was hidden.

If you do a ls -a you can see them.

1
  • You might want to consider disabling the recycle bin functionality and switching to nightly backups, or warn your users that large files in the recycle bin will be deleted after X days.
    – Andrew
    Jun 17, 2010 at 23:10

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.