Certification Objective 4.03Managing File System Inconsistencies and Disk Space


Certification Objective 4.03—Managing File System Inconsistencies and Disk Space

Exam Objective 2.6: Given a scenario, check and resolve Solaris 10 OS file system inconsistencies using fsck, and monitor file system usage using the command line (df, du, and quot commands).

File system data consistency is important to ensure that the content of the file system is always available. To ensure consistency, file systems must be checked periodically. When you boot a system, a consistency check on the file systems is automatically performed. However, you can also perform the file system consistency check, when needed, after the system has been booted. In order to facilitate the consistency check, Solaris offers the fsck utility. In this section, we explore where the inconsistencies come from, how to detect them, and how to repair them using the fsck command.

On the Job 

If the fsck command finds the files and directories that are allocated but unreferenced (that is, some inodes are allocated to files but not attached to any directory), it names them by their inode numbers and places them in the lost+found directory. If the lost+found directory did not exist, the fsck command would create it.

Understanding File System Inconsistencies

The information about files is stored in inodes, and the data is stored in blocks. The UFS file system uses a set of tables to keep track of used inodes and available blocks. Inconsistencies will arise, for example, if these tables are not properly synchronized with the data on disk. This condition can arise as a result of an abrupt termination of the operating system. The reasons for inconsistencies are listed here:

  • A software error in the kernel

  • Turning off the system without the proper shutdown procedure (e.g., accidentally unplugging the system), or through a power failure

  • Defective hardware, such as problems with the disk

Solaris offers the fsck command, which can be used to find the inconsistencies and repair them. How does fsck know that a file system needs to be checked for inconsistencies? It uses a flag, called the state flag, to make this determination. The state flag for a file system is recorded in the superblock (discussed in the next chapter). The possible values of the state flag are described in Table 4-4.

Table 4-4: Possible values of a file system state flag

State Flag Value

Description

FSACTIVE

Mounted file system has modified data in memory. Data would be lost if power to the system were interrupted.

FSBAD

The file system contains inconsistent data.

FSCLEAN

The file system was unmounted cleanly and doesn't need to be checked for consistency.

FSLOG

Logging is enabled for this file system.

FSSTABLE

The file system contains consistent data (i.e,, no data would be lost if the power to the system were interrupted). There's no need to run fsck before mounting.

The fsck utility makes multiple passes on a file system as listed here:

  • Phase 1. Checks blocks and sizes.

  • Phase 2. Checks path names.

  • Phase 3. Checks connectivity.

  • Phase 4. Checks reference counts.

  • Phase 5. Checks cylinder groups.

A file system must be inactive when you use fsck to repair it. Otherwise, the file system changes that were waiting to be written to the system and the changes that occur during the repair might cause the file system to be corrupted.

image from book
Exam Watch

Unmount a file system before you run the fsck command on it. This way you will ensure that you don't add any inconsistencies during the fsck repair.

image from book

Now that you know about the inconsistencies, let's see how to use the fsck command to detect and fix them.

Using the fsck Command

The syntax for the fsck command is presented here:

    fsck [<options>] [<rawDevice>] 

The <rawDevice> is the device interface in /dev/rdsk. If no <rawDevice> is specified, fsck looks into the /etc/vfstab file, which lists the file systems. The file systems represented by the entries in the /etc/vfstab with the following two properties will be checked:

  • The value of the fsckdev field is a character-special device.

  • The value of the fsckpass field is a non-zero numeral.

The /etc/vfstab file is discussed in detail in Chapter 12.

The options for the fsck command are as follows:

  • -F <FSType>. Limit the check to the file systems specified by <FSType>.

  • -m. Check but do not repair—useful for checking whether the file system is suitable for mounting.

  • -n | -N. Assume a "no" response to all questions that will be asked during the fsck run.

  • -y | - Y. Assume a "yes" response to all questions that will be asked during the fsck run.

Exercise 4-2: Checking a File System Manually

image from book
  1. Become superuser (e.g., login as root).

  2. Unmount a local file system, say /export/home.

  3. Use the fsck command by specifying the mount point directory or the /dev/dsk/<deviceName as an argument to the command. If you provide no argument, all the file systems with fsck pass field greater than 0 in the /etc/vfstab file will be checked.

  4. Messages about the inconsistencies will be displayed.

  5. The fsck command may not be able to fix all errors in one run. If necessary, you can run the fsck command again—for example, if you see a message that looks like the following:

        FILE SYSTEM STATE NOT SET TO OKAY or FILE SYSTEM MODIFIED 

  6. Mount the repaired file system.

  7. Move the files in the lost+found directories to where they belong with their proper names (you will rename them to their original names). The files and directories that you cannot identify should eventually be removed to save space.

image from book

After you create the file systems, make sure the data on them stays consistent. You need to monitor how these file systems are using the disks on which they reside. We explore this system administration task next.

Monitoring Disk Space Usage

Monitoring disk space usage is an important administrative task, not only to ensure proper usage of disk space but also to ensure correct functioning of the system. For example, think of the situation when the disk is full and, as a result, the running programs have no space to store their data. The Solaris system allows you to get reports on disk space usage at different levels. You can use commands to determine disk usage by file systems, files, and users.

Using the df Command

Solaris offers the df command to monitor disk space usage at file system level. To be specific, the df command can be used to determine the following:

  • The amount of disk space occupied by currently mounted or unmounted file systems

  • The total amount of used and available space

  • The fraction of the file system's total capacity that has been used

The file system is specified by referring to the device, or a file, or a directory on the file system. The following is the syntax for the df command:

    df [-F <FSType>] [<options>] [<fileSystem>] 

The options are described here:

  • -a. Report on all file systems.

  • -b. Print the total number of kilobytes free.

  • -F <FSType>. Display disk usage information on the file systems with the specified file system type.

  • <fileSystem>. Display disk usage information on the file system specified by referring to a device, file, or directory.

  • -k. Display disk usage information in kilobytes.

  • -t <type>. Display the total number of blocks along with blocks used for each mounted file systems.

The output for the df command looks like the following:

    Filesystem kbytes used avail capacity Mounted on    senate:/ 7450 4715 1985 70% /    senate:/usr 42280 35295 2756 93% /usr 

The headings in the output are self-explanatory. The column after the output represents total space size allocated to the file system, while the second and third columns specify used and available space.

On the Job 

Note in the example that the amount of space in the file system (kbytes) is greater than the sum of the used and available space, because the system reserves a fraction of the space to ensure that its file system allocation routines work well. You can adjust the reserved amount, which is typically about 10 percent, by using the tunefs command.

Suppose that with the df command you determine disk usage at the file system level. Further suppose that you want to go into more detail and determine disk usage by directories. In that case, you will need the du command, which we explore next.

Using the du Command

The du command is used to get the report on disk usage at the directory and file level. You can use the du command to determine the following:

  • Total space allocated to a directory

  • Total space allocated to a directory subtree

  • Total space allocated to a non-directory file—that is, a file that is not a directory

The syntax for the du command is presented here:

    du [<options>] [<file>] 

The operand <file> can be a directory or a non-directory file. If <file> is not specified, the command is run on the current directory. The reported disk space size allocated to a directory is the sum total of space allocated to the whole subtree of files and directories with the specified directory as the root. The options are listed here:

  • -a. In addition to the default output, display the size of each non-directory file in the subtree of the specified directory.

  • -h. Display the output in a human-readable format. All the subdirectories in the target subtree with the full path name and disk usage information are listed.

  • -k. Display the file sizes in kilobytes rather than blocks (512 bytes), which is the default. All the subdirectories in the target subtree with the full path name and disk usage information are listed.

  • -s. Display only the total sum for the specified file/directory.

Now that you know how to get reports on disk usage at file system level and to go down to the directories and files level, you can become more ambitious and ask: how can I find out disk usage by user? Well, Solaris has an answer for you, and the answer is the quot command, which we explore next.

Using the quot Command

There will be times when you want to know how much space is being used by each user on a given file system. The quot command is used to get the report on disk usage by user name. The syntax for the quot command is as follows:

    quot [<options>] [<fileSystem>] 

The <fileSystem> specifies the mount point for the file system(s) to be checked. The options are listed here:

  • -a. Report on all mounted file systems.

  • -f. Display the output in three columns representing user name, total number of blocks, and total number of files owned by the user.

  • -v. In addition to the default output, display the number of blocks not accessed during the past 30, 60, and 90 days.

The quot command displays the disk space in kilobytes, and you can use it as superuser.

The three most important takeaways from this chapter are the following:

  • Several file systems are created during Solaris installation, and these file systems are organized into an inverted hierarchy tree with the root (/) file system at the top. The consistency of these file systems is checked and maintained using the fsck command.

  • Most of the file systems reside on disk, and Solaris offers commands to monitor disk space usage at different levels of detail: df at file system level, du at file level, and quot at user level.

  • You can avoid direct exposure of the files to users by creating links, which come in two types: hard links and symbolic links.




Sun Certified System Administrator for Solaris 10 Study Guide Exams 310-XXX & 310-XXX
Sun Certified System Administrator for Solaris 10 Study Guide Exams 310-XXX & 310-XXX
ISBN: N/A
EAN: N/A
Year: 2005
Pages: 168

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net