|
|
14.5. Maintaining the File SystemSeveral regular activities are required to assure the proper functioning of the file systems on your system. In addition to this, there may be instances where you need to add new file systems to the system. 14.5.1. File System IntegrityWhen the system first boots, all run level's boot scripts run a utility called fsck to check the integrity of the file system (Figure 14-3).
Fortunately, fsck is very good at correcting errors. This means that you'll probably never have the joy of patching disk errors by hand as was done in "the good old days." 14.5.2. Disk SpaceAs I just mentioned, disk errors are uncommon and are generally corrected automatically. Disk usage problems, on the other hand, are very common. Many users treat the file system as if it were infinitely large, and create huge numbers of files without much thought. When I taught UNIX at UT Dallas, the disks would invariably fill up on the last day of the semester, just as everyone was trying to complete his project. Students would try to save their work from vi, and vi would respond with a "disk full" message. When they quit from vi, they would find that their file had been deleted. To avoid running out of disk space, it's wise to run a shell script from cron that periodically runs the df utility to check the available disk space (Figure 14-4).
The exact format varies a bit between Linux distributions, partly because of the way file systems are mounted and named. Here's an example of df in action from Mandrake Linux: $ df ...list information about all file systems. Filesystem Size Used Avail Use% Mounted on /dev/ide/host0/bus0/target0/lun0/part7 2.4G 1.5G 795M 66% / /dev/ide/host0/bus0/target0/lun0/part5 198M 7.6M 180M 5% /boot /dev/ide/host0/bus0/target0/lun0/part1 16G 2.7G 14G 17% /mnt/windows $ _ Here's output from df on a SuSE Linux system: $ df Filesystem 1K-blocks Used Available Use% Mounted on /dev/hda6 3635216 1759508 1691044 51% / tmpfs 95744 16 95728 1% /dev/shm $ _ You can find out how much disk space is left on the device where your home directory resides just as easily: $ df . Filesystem 1K-blocks Used Available Use% Mounted on /dev/hda6 3635216 1759508 1691044 51% / $ _ If df reports that a disk is greater than 95% full, your script could detect this and send you some e-mail. Even better, your script could then run the du utility to determine which users are using the most disk space, and then automatically send them mail suggesting that they remove some files (Figure 14-5).
In the following example, I used du to find out how many kilobytes my current directory and all its files were using up. I then obtained a file-by-file breakdown of the disk usage: $ du -s -h ...obtain grand total of current directory. 9M . $ du . ...obtain file-by-file listing. 91 ./proj/fall.89 158 ./proj/summer.89/proj4 159 ./proj/summer.89 181 ./proj/spring.90/proj2 21 ./proj/spring.90/proj1 204 ./proj/spring.90 455 ./proj ... ...other files were listed here. 38 ./sys5 859 ./sys6 9291 . $ _ 14.5.3. Creating New File SystemsIf you add a new disk drive to your system, you must do a few things before your system can use it as part of the file system:
Create a file system on the medium using mkfs (Figure 14-6).
Once the file system is created, it may be connected to the root file system by using the mount utility described on page 157 in Chapter 4, "GNU Utilities for Power Users." 14.5.4. Backing up File SystemsMaking a backup copy of file system information is the most important and most frequently overlooked task a system administrator should perform. It's frustrating to spend time at it, since you believe you'll never need the backup. But just like buying insurance on your car, you should do it, because if you ever do need it, not having it will be a big problem. The procedure and utilities for backing up the file system are described in Chapter 4, "GNU Utilities for Power Users." Some distributions install dump and restore (they may be called e2fsdump and e2fsrestore), which are backup and restore utilities based on the Berkeley dump and restore utilities. dump (or e2fsdump) will work only on an ext2 or ext3 file system, as it is specific to those file systems, so these utilities are not generally useful if you might ever use other types of file systems. |
|
|