Using Linux:System Maintenance
-->
Previous
Table of Contents
Next
Maximizing Disk Space
Generally, its best not to allow free space on your hard drive to fall below 2530 percent of your hard drives total capacity. The following sections examine ways to keep an eye on disk space, and (more importantly) ways to reclaim parts of a shrinking hard disk pie.
Performing System Cleanups
While the kernel and other Linux processes run, they generate a number of housekeeping files. Often, Linux automatically disposes of these files but sometimes you must take matters into your own hands. For instance, if you are creating your own logs, use a redirect command like >> (append); the files used by that redirect will continue to grow until removed.
Linux provides two commands to check on disk usage, df and du, described in the following two command examples:
#df
Filesystem 1024-blocks Used Available Capacity
Mounted on
/dev/hda5 128790 61203 60936 50% /
/dev/hda7 257598 172332 71962 71%
/usr
/dev/fd0 1423 471 952 33%
/mnt/floppy
df (disk free space) reports on the total number of blocks used and free on all mounted partitions. Its good for getting an overall snapshot of the space available on the entire system. Its compatriot, du, allows you to examine individual files and directories for space usage, a little like ls with the -l option:
#du
15 ./taper_info
1 ./docs/f2
2 ./docs/x
2853 .
You can use these commands in shell scripts to automate monitoring of system space usage.
You can also use the find command with the size (-s) option to generate lists of large files that bear examining:
#find -s +1000k -print > /home/me/filemaint/bigfilelist
This command prints a list of files larger than 1 MB (1,000 KB) in the designated log file. You can also run this command using the crontab feature to receive email listing those files:
* 8 * * Mon find -s +1000k -print
This command checks for large files every Monday at 8:00 a.m. (a good way to enjoy light entertainment on Monday mornings is to see some of the gargantuan files created over the last week).
Aside from looking for files created by users, there are several places that you can check for files that need to be cleaned up. The best place to start is in the /etc/syslog.conf file. This file maintains a listing of all of the logs used by the syslogd daemon, a system logger started when you boot Linux:
#cat /etc/syslog.conf
# Log all kernel messages to the console.
# Logging much else clutters up the screen.
kern.*
/dev/console
# Log anything (except mail) of level info or higher.
# Dont log private authentication messages!
*.info;mail.none;authpriv.none /var/log/
messages
# The authpriv file has restricted access.
authpriv.*
/var/log/secure
# Log all the mail messages in one place.
mail.*
/var/log/maillog
# Everybody gets emergency messages, plus log them on another # machine.
*.emerg *
# Save mail and news errors of level err and higher in a
# special file.
uucp,news.crit
/var/log/spooler
In this file, the lines starting with # signs are comments; the other lines instruct the syslog daemon how to handle log messages. The Linux system logs a variety of messages to help with everything from lost mail to system crashes. Almost every message contains a time, machine name, and the name of the program that generated it. The syslog daemon also categorizes messages by order of importance, ranging from simple system debugging and info messages to high-priority critical and emergency (emerg) messages.
In addition to being routed by severity, messages are earmarked based on the facility (cron, mail, and so on) associated with them. So, as you can see above, mail log messages are handled differently than kernel (kern) messages. Some of these logs can be good places to look if youre having problems with a particular feature of Linux (like mail).
You can see how, if the system were left up for some time with no other housecleaning done, some of the files might get large. Almost all of these syslogd logs are stored in /var/log, so this is a good place to check for files experiencing runaway growth:
#find /var/log -s +250k -print
Its also worth becoming a little familiar with the Linux File System Standard to help identify other likely places to clean (the Red Hat documentation contains a description of how Red Hats filesystem structure conforms to the Linux File System Standard). Two candidates are the tmp directories: /tmp and /var/tmp. These directories are used as dumping grounds by various applications and utilities, and if the system isnt rebooted periodically, they too can become larger than youd like:
#ls /var/tmp
taper00291oaa
taper00291paa
taper00420caa
taper00420daa
taper01047caa
taper01047daa
The /var/tmp file contains a set of taper-related files. If youre not sure whether taper still needs these (it probably doesnt), move them to another directory and run a taper backup and/or restore. Assuming taper runs satisfactorily, it should be safe to remove these files.
SEE ALSO
For more information about the find command, see page 548.
For more information about the crontab utility, see page 435.
For more information about Linux kernel management, see page 569.
For more information about using the Linux mail utility, see page 179.
For information about Linux system daemons, see page 467.
Previous
Table of Contents
Next
Wyszukiwarka
Podobne podstrony:
2014kwykład3część1Redox stud dpkid(567567 572564,6,artykul561 564demo cgi 567Antyk kultura starożytnej Grecji i Rzymu (oraz innych d~567565 567README (564)01 (564)567,8,artykul567 francuskikrokdalej1567 (2)01 (567)więcej podobnych podstron