Tech Tips with Gnull and Voyd

 in
New tech tips column.

—Brad Hall

Finding Disk Space and inode Hogs

I knowed somebody was gonna get to this problem sooner or later. You get too many inodes on your system, and you're asking for another heap of trouble. This tells you how to find out and fix it. —Chester

One of the most common tasks of a system administrator is storage management. When you're faced with a full or almost full filesystem, it's good to have a few tools at your disposal to help figure out “where” the hog is.

Searching for space hogs is very easy. With one simple command you can total up the contents of every directory in a tree (/usr in this case) and see which are the largest:

du -k /usr/ |sort -n |tail -30

167156  /usr/include
168960  /usr/share/icons
173972  /usr/share/texmf
244332  /usr/bin
263144  /usr/lib/openoffice.org2.0
265492  /usr/share/doc
344536  /usr/share/locale
1223992 /usr/lib
1959412 /usr/share
4159996 /usr/

As you can see, /usr/share/ and /usr/lib/ are pretty big, and you can drill down further by going up the list.

A somewhat rarer situation is running out of inodes in a filesystem. In this case, you will see available space, but the system will be unable to write new files because it has run out of inodes. To find inode hogs, use this quick Perl script named inodu:

#!/usr/bin/perl -w

my $start=$ARGV[0];

foreach $object (`find '$start'`){
        my @parts=split(/\//,$object);
        while(pop(@parts)  ){
                my $object = join('/',@parts);
                $object =~ s/\/+/\//g;
                $object2qty{$object}++;
        }
}

foreach $object (sort { $object2qty{$a} <=> $object2qty{$b} }
                         keys %object2qty){
        print $object2qty{$object} . "\t${object}\n";

}

This will total up the number of filesystem objects in each directory and supply an output much like the previous example. Use it like this:

cd /usr

./inodu .

10420   ./include
10973   ./share/texmf
12012   ./share/man
13207   ./share/doc
14953   ./share/icons
16481   ./src/kernels
17201   ./src
22982   ./lib
105527  ./share
174270  .
174271

As you can see, again share and lib are the inode hogs using more than 100,000 inodes!

If you find yourself in any of these situations, there are a number of ways to create more free space or inodes. First, look for log files that can be purged, moved or compressed. Ask users to clean up their home directories. Remove any unnecessary software. If you are using Linux LVM and ext3fs, you can expand the filesystem using lvresize and resize2fs to grow a filesystem. This creates more free space and inodes, but only if you have free space in your volume group. If you have free disk space, you can create a new partition (for, say, your /var tree), move the files to that partition and mount it as /var. As a last resort, you can move files and directories and use symlinks so the old path still works. I say “last resort” because this method can get out of hand very quickly and can make things very confusing.

—Matthew Hoskins

Credits
  • Nicholas Petreley is Editor in Chief of Linux Journal.

  • Brad Hall lives in Jacksonville, Florida, with his pet chickens and life-size cardboard cutout of Star Trek: DS9's Dr. Bashir.

  • Matthew Hoskins is Senior Information Systems Analyst at the New Jersey Institute of Technology.

Linux Journal pays $100 US for any tech tips we publish. Send your tips with your contact information to techtips@linuxjournal.com.

______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

I find the attempt at humor offensive

Anita Lewis's picture

I will publish my opinion that this is not where I would choose to get information on anything. My first and last trip here unless I hear about some big changes.

Excuse me?

rottie's picture

".. I don't know nothing about Linux. Chester, he's the smart one, .. "

What planet do you live on? I've been on linux for 10 years now. Not once have I had a boyfriend that could fix his own computer without coming to me.

I concur, this is a magazine I wont be buying again.

Wow

Babs's picture

I sure wish I wasn't a girl confused by all this Linus stuff. Gosh. Computers sure are hard.

Oh, no, wait, that's right. My husband comes to me when he needs help with Linux or any open source technology.

I first saw this article in

Anonymous's picture

I first saw this article in the printed version of the magazine. It directly contributed to my not renewing my subscription. LJ: stop dumbing everything down. Surely not all your readers are teenage misogynists.

Ugh. I guess you've decided

Anonymous's picture

Ugh. I guess you've decided that you can do without female subscribers, eh? I know I'm not going to be renewing.

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState