Sun Microsystems System Administration Guide, Volume 1 (2000) - page 16

 

  Index      Manuals     Sun Microsystems System Administration Guide, Volume 1 (2000)

 

Search            copyright infringement  

 

 

 

 

 

 

 

 

 

 

 

Content      ..     14      15      16      17     ..

 

 

 

Sun Microsystems System Administration Guide, Volume 1 (2000) - page 16

 

 

CHAPTER
38
Configuring Additional Swap Space
(Tasks)
This is a list of the overview conceptual information and step-by-step instructions in
this chapter.
“Swap Space and Virtual Memory” on page 498
“Swap Space and the TMPFS File System” on page 498
“How Do I Know If I Need More Swap Space?” on page 499
“How Swap Space Is Allocated” on page 500
“Planning for Swap Space” on page 501
“Monitoring Swap Resources” on page 501
“Adding More Swap Space” on page 503
“Removing a Swap File From Use” on page 505
About Swap Space
It is important for administrators to understand the features of the SunOS swap
mechanism in determining:
Swap space requirements
The relationship with the TMPFS file system
Recovery from error messages related to swap space
497
Swap Space and Virtual Memory
The Solaris software uses some disk slices for temporary storage rather than for file
systems. These slices are called swap slices. Swap slices are used as virtual memory
storage areas when the system does not have enough physical memory to handle
current processes.
The virtual memory system maps physical copies of files on disk to virtual addresses
in memory. Physical memory pages which contain the data for these mappings can
be backed by regular files in the file system, or by swap space. If the memory is
backed by swap space it is referred to as anonymous memory because there is no
identity assigned to the disk space backing the memory.
The Solaris environment uses the concept of virtual swap space, a layer between
anonymous memory pages and the physical storage (or disk-backed swap space) that
actually back these pages. A system’s virtual swap space is equal to the sum of all its
physical (disk-backed) swap space plus a portion of the currently available physical
memory.
Virtual swap space has these advantages:
The need for large amounts of physical swap space is reduced because virtual
swap space does not necessarily correspond to physical (disk) storage.
A pseudo file system called SWAPFS provides addresses for anonymous memory
pages. Because SWAPFS controls the allocation of memory pages, it has greater
flexibility in deciding what happens to a page. For example, it might change the
page’s requirements for disk-backed swap storage.
Swap Space and the TMPFS File System
The TMPFS file system is activated automatically in the Solaris environment by an
entry in the /etc/vfstab file. The TMPFS file system stores files and their
associated information in memory (in the /tmp directory) rather than on disk, which
speeds access to those files. This results in a major performance enhancement for
applications such as compilers and DBMS products that use /tmp heavily.
The TMPFS file system allocates space in the /tmp directory from the system’s swap
resources. This means that as you use up space in /tmp, you are also using up swap
space. So if your applications use /tmp heavily and you do not monitor swap space
usage, your system could run out of swap space.
Use the following if you want to use TMPFS but your swap resources are limited:
Mount the TMPFS file system with the size option (o size) to control how much
of the swap resources TMPFS can use.
If you are close to running out of swap space, you can use your compiler’s
TMPDIR environment variable to point to a larger, real directory.
Using your compiler’s TMPDIR variable only controls whether the compiler is
using /tmp or not. It has no effect on other programs’ use of /tmp.
498
How Do I Know If I Need More Swap
Space?
This section lists several possible error messages displayed when you run out of
swap space.
Swap-Related Error Messages
These messages indicate that an application was trying to get more anonymous
memory and there was no swap space left to back it.
application is out of memory
malloc error O
messages.1:Sep 21 20:52:11 mars genunix: [ID 470503 kern.warning]
WARNING: Sorry, no swap space to grow stack for pid 100295 (myprog)
TMPFS-Related Error Messages
directory: File system full, swap space limit exceeded
This message is displayed if a page could not be allocated when writing a file. This
can occur when TMPFS tries to write more than it is allowed or if currently executed
programs are using a lot of memory.
directory: File system full, memory allocation failed
This message means TMPFS ran out of physical memory while attempting to create a
new file or directory.
See TMPFS(7FS) for information on recovering from the TMPFS-related error
messages.
Configuring Additional Swap Space (Tasks)
499
How Swap Space Is Allocated
Initially, swap space is allocated as part of the Solaris installation process. If you use
the installation program’s automatic layout of disk slices and do not manually
change the size of the swap slice, the Solaris installation program allocates default
swap slices as shown in the table below.
TABLE 38-1
Default Swap Space Allocations
If Your System Has n Mbytes of
Then the Default Swap Space Allocated Is ...
Physical Memory ...
16-63
32 Mbytes
64-127
64 Mbytes
128-511
128 Mbytes
greater than 512
256 Mbytes
Additional swap space can also be added to the system by creating a swap file. See
“Adding More Swap Space” on page 503 for information about creating a swap file.
The /etc/vfstab File
After the system is installed, swap slices and files are listed in the /etc/vfstab file
and are activated by the /sbin/swapadd script when the system is booted.
An entry for a swap device in the /etc/vfstab file contains:
The full path name of the swap slice or file
File system type of swap
Because the file system containing a swap file must be mounted before the swap file
is activated, make sure that the entry that mounts the file system comes before the
entry that activates the swap file in the /etc/vfstab file.
500
Planning for Swap Space
The most important factors in determining swap space size are the requirements of
the system’s software applications. For example, large applications such as
computer-aided-design simulators, database-management products, transaction
monitors, and geologic analysis systems can consume as much as 200-1000 Mbytes of
swap space.
Consult your application vendor for swap space requirements for any application
whose data files typically exceed 10-20 Mbytes in size.
If you are unable to determine swap space requirements from the application vendor,
use the following guidelines to allocate swap space:
To support your applications, allocate:
1 Mbyte per trivial application such as xterm.
2-3 Mbytes per lightweight application such as a calendar or mail application.
20-50 Mbytes for large applications such as desktop publishing software.
To save crash dumps, allocate 100% of physical memory to save a worst-case crash
dump.
If you are unsure of system or application requirements, allocate 50 to 100% of the
system’s physical memory. For example, allocate 16-32 Mbytes of swap space for a
system with 32 Mbytes of physical memory. This will provide 48-64 Mbytes of
total virtual swap space.
Determine whether large applications (like compilers) will be using the /tmp
directory. Then allocate additional swap space to be used by TMPFS. See “Swap
Space and the TMPFS File System” on page 498 for information about TMPFS.
Monitoring Swap Resources
The /usr/sbin/swap command is used to manage swap areas. Two options,l
ands, are used to display information about swap resources.
Use the swap -l command to identify a system’s swap areas. Activated swap
devices or files are listed under the swapfile column.
# swap -l
swapfile
dev swaplo blocks
free
(continued)
Configuring Additional Swap Space (Tasks)
501
(Continuation)
/dev/dsk/c0t2d0s1 32,17
8 205624 192704
Use the swap -s command to monitor swap resources.
# swap -s
total:
10492k
bytes allocated + 7840k reserved = 18332k used, 21568k available
The used plus available figures equals total swap space on the system, which
includes a portion of physical memory and swap devices (or files).
You can use the amount of swap space available and used (in the swap -s output)
as a way to monitor swap space usage over time. If a system’s performance is good,
use swap -s to see how much swap space is available. When the performance of a
system slows down, check the amount of swap space available to see if it has
decreased. Then you can identify what changes to the system might have caused
swap space usage to increase.
Keep in mind when using this command that the amount of physical memory
available for swap usage changes dynamically as the kernel and user processes lock
down and release physical memory.
Note - The swap -l command displays swap space in 512-byte blocks and the
swap -s command displays swap space in 1024-byte blocks. If you add up the
blocks from swap -l and convert them to Kbytes, it will be less than used +
available (in the swap -s output) because swap -l does not include physical
memory in its calculation of swap space.
The output from the swap -s command is summarized in the table below.
TABLE 38-2
Output of the swap -s Command
Keyword
Description
bytes allocated
The total amount of swap space in 1024-byte blocks that is
currently allocated as backing store (disk-backed swap space).
The total amount of swap space in 1024-byte blocks not
reserved
currently allocated, but claimed by memory for possible future
use.
502
TABLE 38-2
Output of the swap -s Command
(continued)
Keyword
Description
used
The total amount of swap space in 1024-byte blocks that is
either allocated or reserved.
available
The total amount of swap space in 1024-byte blocks that is
currently available for future reservation and allocation.
Adding More Swap Space
As system configurations change and new software packages are installed, you
might need to add more swap space. The easiest way to add more swap space is to
use the mkfile and swap commands to designate a part of an existing UFS or NFS
file system as a supplementary swap area. These commands, described below, enable
you to add more swap space without repartitioning a disk.
Alternative ways to add more swap space are to repartition an existing disk or add
another disk. See Chapter 28 for information on how to repartition a disk.
Creating a Swap File
The following general steps are involved in creating a swap file:
Creating a swap file using the mkfile command.
Activating the swap file with the swap command.
Adding an entry for the swap file in the /etc/vfstab file so that it’s activated
automatically when the system is booted.
The mkfile Command
The mkfile command creates a file that is suitable for use either as an
NFS-mounted or local swap area. The sticky bit is set, and the file is filled with zeros.
You can specify the size of the swap file in bytes (the default) or in kilobytes, blocks,
or megabytes using the k, b, or m suffixes, respectively.
The table below shows the options to the mkfile command.
Configuring Additional Swap Space (Tasks)
503
TABLE 38-3
Options to the mkfile Command
Option
Description
Creates an empty file. The size is noted, but the disk blocks are not
n
allocated until data is written to them.
Verbose. Reports the names and sizes of created files.
v
Caution - Use then option only when creating an NFS swap file.
How to Create a Swap File and Make It Available
1.
Become superuser.
You can create a swap file without root permissions, but it is a good idea for root
to be the owner of the swap file to avoid accidental overwriting.
2.
Create the swap file.
# mkfile nnn[k|b|m] filename
The swap file of the size nnn (in Kbytes, bytes, or Mbytes) and name you specify
is created.
3.
Activate the swap file.
# /usr/sbin/swap -a /path/filename
You must use the absolute path name to specify the swap file. The swap file is
added and available until the file system is unmounted, the system is rebooted, or
the swap file is removed. Keep in mind that you can’t unmount a file system
while some process or program is swapping to the swap file.
4.
Add an entry for the swap file to the /etc/vfstab file that specifies the full
path name of the file, and designates swap as the file system type, like this:
/path/filename
-
-
swap
-
no
-
5.
Verify that the swap file is added.
504
$ /usr/sbin/swap -l
Example—Creating a Swap File and Making It Available
The following examples shows how to create a 24 Mbyte swap file called
/files/swapfiles.
# mkdir /files
# mkfile 24m /files/swapfile
# swap -a /files/swapfile
# vi /etc/vfstab
(An entry is added for the swap file):
/files/swapfile
-
-
swap
-
no
-
# swap -l
swapfile
dev swaplo blocks
free
/dev/dsk/c0t2d0s1
32,17
8 205624 192704
/files/swapfile
-
8
40952
40952
Removing a Swap File From Use
If the user no longer needs the extra swap space, you can remove it.
How to Remove Extra Swap Space
1. Become superuser.
2. Use the swap -d command to remove swap space.
# /usr/sbin/swap -d /path/filename
The swap file name is removed from the list so that it is no longer available for
swapping. The file itself is not deleted.
3. Edit the /etc/vfstab file and delete the entry for the swap file.
4. Recover the disk space so that you can use it for something else.
# rm swap-filename
Configuring Additional Swap Space (Tasks)
505
If the swap space is a file, remove it. Or, if the swap space is on a separate slice
and you are sure you will not need it again, make a new file system and mount
the file system.
See Chapter 36 for information on mounting a file system.
Example—Removing Extra Swap Space
The following examples shows how to delete the /files/swapfile swap file.
# swap -d /files/swapfile
# (Remove the deleted swap entry from the /etc/vfstab file)
# rm /files/swapfile
# swap -l
swapfile
dev swaplo blocks
free
/dev/dsk/c0t2d0s1
32,17
8
205624
192720
506
CHAPTER
39
Checking File System Integrity
This is a list of the conceptual information and step-by-step instructions in this
chapter.
“How the File System State Is Recorded” on page 508
“What fsck Checks and Tries to Repair” on page 510
“Modifying File System Checking at Boot Time” on page 517
“Interactively Checking and Repairing a UFS File System” on page 519
“Restoring a Bad Superblock” on page 522
“Syntax and Options for the fsck Command” on page 524
See “Troubleshooting File System Problems” in System Administration Guide, Volume
2 for information about fsck error messages.
See Chapter 40 for background information on the UFS file system structures referred
to in this chapter.
File System Integrity
The UFS file system relies on an internal set of tables to keep track of inodes used
and available blocks. When these internal tables are not properly synchronized with
data on a disk, inconsistencies result and file systems need to be repaired.
File systems can be damaged or become inconsistent because of abrupt termination
of the operating system in these ways:
Power failure
Accidental unplugging of the system
Turning the system off without proper shutdown procedure
507
A software error in the kernel
File system corruption, while serious, is not common. When a system is booted, a file
system consistency check is automatically performed (with the fsck program). Most
of the time, this file system check repairs problems it encounters.
This chapter describes what the fsck program checks and repairs, and the fsck
options. It also describes the following tasks:
How to modify the automatic checking done during booting
How to find out if a file system needs to be checked
How to check and repair a UFS file system interactively
How to restore a bad superblock
How to fix a UFS file system that fsck cannot repair
The fsck error messages are covered in “Troubleshooting File System Problems” in
System Administration Guide, Volume
2.
The fsck program places files and directories that are allocated but unreferenced in
the lost+found directory. The inode number of each file is assigned as the name. If
the lost+found directory does not exist, fsck creates it. If there is not enough
space in the lost+found directory, fsck increases its size.
How the File System State Is Recorded
The fsck command uses a state flag, which is stored in the superblock, to record the
condition of the file system. This flag is used by the fsck command to determine
whether or not a file system needs to be checked for consistency. The flag is used by
the /sbin/rcS script during booting and by the fsck command when run from a
command line using them option. If you ignore the result from them option to
fsck, all file systems can be checked regardless of the setting of the state flag.
The possible state flag values are described in the table below.
508
TABLE 39-1
State Flag Values
State Flag Value
Description
FSACTIVE
When a file system is mounted and then modified, the state flag is set to
FSACTIVE. The file system might contain inconsistencies. A file system
will be marked as FSACTIVE before any modified metadata is written to
the disk. When a file system is unmounted gracefully, the state flag is set
to FSCLEAN. A file system with the FSACTIVE flag must be checked by
fsck because it might be inconsistent.
FSBAD
If the root (/) file system is mounted when its state is not FSCLEAN or
FSSTABLE, the state flag is set to FSBAD. The kernel will not change this
file system state to FSCLEAN or FSSTABLE. If a root (/) file system is
flagged FSBAD as part of the boot process, it will be mounted read-only.
You can run fsck on the raw root device. Then remount the root (/) file
system as read/write.
FSCLEAN
If the file system was unmounted properly, the state flag is set to
FSCLEAN. Any file system with an FSCLEAN state flag is not checked
when the system is booted.
FSLOG
If the file system was mounted with UFS logging, the state flag is set to
FSLOG. Any file system with an FSLOG state flag is not checked when the
system is booted.
The file system is (or was) mounted but has not changed since the last
FSSTABLE
checkpoint (sync or fsflush) which normally occurs every 30 seconds.
For example, the kernel periodically checks if a file system is idle and, if
so, flushes the information in the superblock back to the disk and marks
it FSSTABLE. If the system crashes, the file system structure is stable, but
users might lose a small amount of data. File systems that are marked
FSSTABLE can skip the checking before mounting. The mount(2) system
call will not mount a file system for read/write if the file system state is
not FSCLEAN, FSSTABLE, or FSLOG.
The table below shows how the state flag is modified by the fsck command, based
on its initial state.
Checking File System Integrity
509
TABLE 39-2
How the State Flag is Modified by fsck
Inital State: Before
State After fsck
fsck
No Errors
All Errors Corrected Uncorrected Errors
unknown
unknown
FSSTABLE
FSSTABLE
FSACTIVE
FSSTABLE
FSSTABLE
FSACTIVE
FSSTABLE
FSSTABLE
FSSTABLE
FSACTIVE
FSCLEAN
FSCLEAN
FSSTABLE
FSACTIVE
FSBAD
FSSTABLE
FSSTABLE
FSBAD
FSLOG
FSLOG
FSLOG
FSLOG
What fsck Checks and Tries to Repair
This section describes what happens in the normal operation of a file system, what
can go wrong, what problems fsck (the checking and repair utility) looks for, and
how it corrects the inconsistencies it finds.
Why Inconsistencies Might Occur
Every working day hundreds of files might be created, modified, and removed. Each
time a file is modified, the operating system performs a series of file system updates.
These updates, when written to the disk reliably, yield a consistent file system.
When a user program does an operation to change the file system, such as a write,
the data to be written is first copied into an in-core buffer in the kernel. Normally,
the disk update is handled asynchronously; the user process is allowed to proceed
even though the data write might not happen until long after the write system call
has returned. Thus at any given time, the file system, as it resides on the disk, lags
behind the state of the file system represented by the in-core information.
510
The disk information is updated to reflect the in-core information when the buffer is
required for another use or when the kernel automatically runs the fsflush
daemon (at 30-second intervals). If the system is halted without writing out the
in-core information, the file system on the disk might be in an inconsistent state.
A file system can develop inconsistencies in several ways. The most common causes
are operator error and hardware failures.
Problems might result from an unclean shutdown, if a system is shut down
improperly, or when a mounted file system is taken offline improperly. To prevent
unclean shutdowns, the current state of the file systems must be written to disk (that
is, “synchronized”) before halting the CPU, physically taking a disk pack out of a
drive, or taking a disk offline.
Inconsistencies can also result from defective hardware. Blocks can become damaged
on a disk drive at any time, or a disk controller can stop functioning correctly.
The UFS Components That Are Checked for
Consistency
This section describes the kinds of consistency checks that fsck applies to these UFS
file system components: superblock, cylinder group blocks, inodes, indirect blocks,
and data blocks.
Superblock Checks
The superblock stores summary information, which is the most commonly corrupted
item in a UFS file system. Each change to the file system inodes or data blocks also
modifies the superblock. If the CPU is halted and the last command is not a sync
command, the superblock will almost certainly be corrupted.
The superblock is checked for inconsistencies in:
File system size
Number of inodes
Free-block count
Free-inode count
File System and Inode List Size Checks
The file system size must be larger than the number of blocks used by the superblock
and the list of inodes. The number of inodes must be less than the maximum number
allowed for the file system. The file system size and layout information are the most
critical pieces of information for fsck. Although there is no way to actually check
Checking File System Integrity
511
these sizes, because they are statically determined when the file system is created,
fsck can check that the sizes are within reasonable bounds. All other file system
checks require that these sizes be correct. If fsck detects corruption in the static
parameters of the primary superblock, it requests the operator to specify the location
of an alternate superblock.
Free Block Checks
Free blocks are stored in the cylinder group block maps. fsck checks that all the
blocks marked as free are not claimed by any files. When all the blocks have been
accounted for, fsck checks to see if the number of free blocks plus the number of
blocks claimed by the inodes equal the total number of blocks in the file system. If
anything is wrong with the block allocation maps, fsck rebuilds them, leaving out
blocks already allocated.
The summary information in the superblock contains a count of the total number of
free blocks within the file system. The fsck program compares this count to the
number of free blocks it finds within the file system. If the counts do not agree, fsck
replaces the count in the superblock with the actual free-block count.
Free Inode Checks
The summary information in the superblock contains a count of the free inodes
within the file system. The fsck program compares this count to the number of free
inodes it finds within the file system. If the counts do not agree, fsck replaces the
count in the superblock with the actual free inode count.
Inodes
The list of inodes is checked sequentially starting with inode 2 (inode 0 and inode 1
are reserved). Each inode is checked for inconsistencies in:
Format and type
Link count
Duplicate block
Bad block numbers
Inode size
Format and Type of Inodes
Each inode contains a mode word, which describes the type and state of the inode.
Inodes might be one of eight types:
Regular
512
Directory
Block special
Character special
FIFO (named-pipe)
Symbolic link
Shadow (used for ACLs)
Socket
Inodes might be in one of three states:
Allocated
Unallocated
Partially allocated
When the file system is created, a fixed number of inodes are set aside, but they are
not allocated until they are needed. An allocated inode is one that points to a file. An
unallocated inode does not point to a file and, therefore, should be empty. The
partially allocated state means that the inode is incorrectly formatted. An inode can
get into this state if, for example, bad data is written into the inode list because of a
hardware failure. The only corrective action fsck can take is to clear the inode.
Link Count Checks
Each inode contains a count of the number of directory entries linked to it. The fsck
program verifies the link count of each inode by examining the entire directory
structure, starting from the root directory, and calculating an actual link count for
each inode.
Discrepancies between the link count stored in the inode and the actual link count as
determined by fsck might be of three types:
The stored count is not 0 and the actual count is 0.
This condition can occur if no directory entry exists for the inode. In this case,
fsck puts the disconnected file in the lost+found directory.
The stored count is not 0 and the actual count is not 0, but the counts are unequal.
This condition can occur if a directory entry has been added or removed but the
inode has not been updated. In this case, fsck replaces the stored link count with
the actual link count.
The stored count is 0 and the actual count is not 0.
In this case fsck changes the link count of the inode to the actual count.
Checking File System Integrity
513
Duplicate Block Checks
Each inode contains a list, or pointers to lists (indirect blocks), of all the blocks
claimed by the inode. Because indirect blocks are owned by an inode, inconsistencies
in indirect blocks directly affect the inode that owns the indirect block.
The fsck program compares each block number claimed by an inode to a list of
allocated blocks. If another inode already claims a block number, the block number is
put on a list of duplicate blocks. Otherwise, the list of allocated blocks is updated to
include the block number.
If there are any duplicate blocks, fsck makes a second pass of the inode list to find
the other inode that claims each duplicate block. (A large number of duplicate blocks
in an inode might be caused by an indirect block not being written to the file
system.) It is not possible to determine with certainty which inode is in error. The
fsck program prompts you to choose which inode should be kept and which should
be cleared.
Bad Block Number Checks
The fsck program checks each block number claimed by an inode to see that its
value is higher than that of the first data block and lower than that of the last data
block in the file system. If the block number is outside this range, it is considered a
bad block number.
Bad block numbers in an inode might be caused by an indirect block not being
written to the file system. The fsck program prompts you to clear the inode.
Inode Size Checks
Each inode contains a count of the number of data blocks that it references. The
number of actual data blocks is the sum of the allocated data blocks and the indirect
blocks. fsck computes the number of data blocks and compares that block count
against the number of blocks the inode claims. If an inode contains an incorrect
count, fsck prompts you to fix it.
Each inode contains a 64-bit size field. This field shows the number of characters
(data bytes) in the file associated with the inode. A rough check of the consistency of
the size field of an inode is done by using the number of characters shown in the
size field to calculate how many blocks should be associated with the inode, and
then comparing that to the actual number of blocks claimed by the inode.
Indirect Blocks
Indirect blocks are owned by an inode. Therefore, inconsistencies in an indirect block
affect the inode that owns it. Inconsistencies that can be checked are:
Blocks already claimed by another inode
514
Block numbers outside the range of the file system
The consistency checks listed above are also performed for indirect blocks.
Data Blocks
An inode can directly or indirectly reference three kinds of data blocks. All
referenced blocks must be of the same kind. The three types of data blocks are:
Plain data blocks
Symbolic-link data blocks
Directory data blocks
Plain data blocks contain the information stored in a file. Symbolic-link data blocks
contain the path name stored in a symbolic link. Directory data blocks contain
directory entries. fsck can check the validity only of directory data blocks.
Directories are distinguished from regular files by an entry in the mode field of the
inode. Data blocks associated with a directory contain the directory entries. Directory
data blocks are checked for inconsistencies involving:
Directory inode numbers pointing to unallocated inodes
Directory inode numbers greater than the number of inodes in the file system
Incorrect directory inode numbers for “.” and “..” directories
Directories disconnected from the file system
Directory Unallocated Checks
If the inode number in a directory data block points to an unallocated inode, fsck
removes the directory entry. This condition can occur if the data blocks containing a
new directory entry are modified and written out but the inode does not get written
out. This condition can occur if the CPU is halted without warning.
Bad Inode Number Checks
If a directory entry inode number points beyond the end of the inode list, fsck
removes the directory entry. This condition can occur when bad data is written into a
directory data block.
Incorrect “.” and “..” Entry Checks
The directory inode number entry for “.” must be the first entry in the directory
data block. It must reference itself; that is, its value must be equal to the inode
number for the directory data block.
Checking File System Integrity
515
The directory inode number entry for “..” must be the second entry in the directory
data block. Its value must be equal to the inode number of the parent directory (or
the inode number of itself if the directory is the root directory).
If the directory inode numbers for “.” and “..” are incorrect, fsck replaces them
with the correct values. If there are multiple hard links to a directory, the first one
found is considered the real parent to which “..” should point. In this case, fsck
recommends you have it delete the other names.
Disconnected Directories
The fsck program checks the general connectivity of the file system. If a directory is
found that is not linked to the file system, fsck links the directory to the
lost+found directory of the file system. (This condition can occur when inodes are
written to the file system but the corresponding directory data blocks are not.)
Regular Data Blocks
Data blocks associated with a regular file hold the contents of the file. fsck does not
attempt to check the validity of the contents of a regular file’s data blocks.
The fsck Summary Message
When you run fsck interactively and it completes successfully, the following message
is displayed:
# fsck /dev/rdsk/c0t0d0s7
** /dev/rdsk/c0t0d0s7
** Last Mounted on /export/home
** Phase 1 - Check Blocks and Sizes
** Phase 2 - Check Pathnames
** Phase 3 - Check Connectivity
** Phase 4 - Check Reference Counts
** Phase 5 - Check Cyl groups
2 files, 9 used, 2833540 free (20 frags, 354190 blocks, 0.0% fragmentation)
#
The last line of fsck output describes the following information about the file
system:
516
# files
Number of inodes in use
Number of fragments in use
# used
# free
Number of unused fragments
Number of unused non-block fragments
# frags
# blocks
Number of unused full blocks
Percentage of fragmentation, where: free
% fragmentation
fragments x 100 / total fragments in the file
system
Modifying File System Checking at Boot
Time
During boot up, a preliminary check on each file system to be mounted from a hard
disk is run using the boot script /sbin/rcS, which checks the root (/), /usr, and
/var file systems. The other rc shell scripts then use the fsck command to check
each additional file system sequentially. They do not check file systems in parallel.
File systems are checked sequentially during booting even if the fsck pass
numbers are greater than one.
The /etc/vfstab File
When you run the commands for checking and mounting file systems without
specifying a file system directly, the commands step through the file system table
(/etc/vfstab) using the information specified in the various fields. The fsck
pass field specifies information for file system checking. The mount at boot field
specifies information for mounting the file system at boot time.
When you create new file systems, add entries to /etc/vfstab indicating whether
they are to be checked and mounted at boot time. See Chapter 36 for more
information about adding entries to the /etc/vfstab file.
Information in the /etc/vfstab file is specific for the slices and file systems for
each system. Here is an example of an /etc/vfstab file:
Checking File System Integrity
517
$ more /etc/vfstab
#device
device
mount
FS
fsck
mount
mount
#to mount
to fsck
point
type
pass
at boot
options
#/dev/dsk/c1d0s2 /dev/rdsk/c1d0s2 /usr
ufs
1
yes
-
/proc
-
/proc
proc
-
no
-
fd
-
/dev/fd
fd
-
no
-
swap
-
/tmp
tmpfs
-
yes
-
/dev/dsk/c0t0d0s0 /dev/rdsk/c0t0d0s0 /
ufs
1
no
-
/dev/dsk/c0t0d0s1 -
-
swap
-
no
-
/dev/dsk/c0t0d0s6 /dev/rdsk/c0t0d0s6 /usr
ufs
2
no
-
/dev/dsk/c0t0d0s7 /dev/rdsk/c0t0d0s7 /opt
ufs
3
yes
-
pluto:/usr/dist -
/usr/dist
nfs
no
yes
-
$
The table below describes the function of the fsck pass field.
TABLE 39-3
The fsck pass Field
If the fsck pass
Field is Set To ...
Then ...
Comments
The generic fsck command
Use a hyphen for read-only file
- (hyphen)
will not check the file system
systems, remote file systems, or
regardless of the state of the file
pseudo file systems, such as /
system.
proc, to which checking does
not apply.
0
The file system specific fsck
When the value is 0 for UFS file
command is called.
systems, the file system is not
checked.
1 or greater and fsck
The file system specific fsck
The value can be any number
-o p is used
automatically checks UFS file
greater than 1.
systems in parallel.
In preen mode (o p option), fsck allows only one active file system check per
disk, starting a new check only after the previous one is completed. fsck
automatically uses the major and minor numbers of the devices on which the file
systems reside to determine how to check file systems on different disks at the same
time.
When the fsck pass number is 1, file systems are checked sequentially, in the
order they appear in the /etc/vfstab file. Usually, the root (/) file system has the
fsck pass set to 1.
518
Note - fsck does not use the fsck pass number to determine the sequence of file
system checking.
How to Modify File System Checking at Boot Time
1. Become superuser.
2. Edit /etc/vfstab entries in the fsck pass field, and save the changes.
The next time the system is booted, the new values are used.
Interactively Checking and Repairing a
UFS File System
You might need to interactively check file systems:
When they cannot be mounted
When they develop problems while in use
When an in-use file system develops inconsistencies, error messages might be
displayed in the console window or the system might crash.
Before using fsck, you might want to refer to “Syntax and Options for the fsck
Command” on page 524 and “Troubleshooting File System Problems” in System
Administration Guide, Volume
2 for more information.
How to See If a File System Needs Checking
1. Become superuser.
2. Unmount the file system if it is mounted.
# umount /mount-point
3. Check the file system.
# fsck -m /dev/rdsk/device-name
Checking File System Integrity
519
In this command, the state flag in the superblock of the file system you specify is
checked to see whether the file system is clean or requires checking.
If you omit the device argument, all the UFS file systems listed in /etc/vfstab
with a fsck pass value greater than 0 are checked.
Example—Seeing If a File System Needs Checking
The following example shows that the file system needs checking.
# fsck -m /dev/rdsk/c0t0d0s6
** /dev/rdsk/c0t0d0s6
ufs fsck: sanity check: /dev/rdsk/c0t0d0s6 needs checking
How to Check File Systems Interactively
1. Become superuser.
2. Unmount the local file systems except root (/) and /usr.
# umountall -l
3. Check the file system.
# fsck
All file systems in the /etc/vfstab file with entries in the fsck pass field
greater than zero are checked. You can also specify the mount point directory or
/dev/rdsk/device-name as arguments to fsck. Any inconsistency messages are
displayed. See “Troubleshooting File System Problems” in System Administration
Guide, Volume
2 for information about how to respond to the error message
prompts to interactively check one or more UFS file systems.
Caution - Running fsck on a mounted file system might cause a system to crash if
fsck makes any changes, unless stated otherwise, such as running fsck in
single-user mode to repair a file system.
4. If you corrected any errors, type fsck and press Return.
520
fsck might not be able to fix all errors in one execution. If you see the message
FILE SYSTEM STATE NOT SET TO OKAY, run the command again. If that does
not work, see “How to Fix a UFS File System fsck Cannot Repair” on page 524.
5. Rename and move any files put in the lost+found directory.
Individual files put in the lost+found directory by fsck are renamed with their
inode numbers. If possible, rename the files and move them where they belong.
You might be able to use the grep command to match phrases with individual
files and the file command to identify file types. When whole directories are
dumped into lost+found, it is easier to figure out where they belong and move
them back.
Example—Checking File Systems Interactively
The following example checks /dev/rdsk/c0t0d0s6 and corrects the incorrect
block count.
# fsck /dev/rdsk/c0t0d0s6
checkfilesys: /dev/rdsk/c0t0d0s6
** Phase 1 - Check Block and Sizes
INCORRECT BLOCK COUNT I=2529 (6 should be 2)
CORRECT? y
** Phase 2 - Check Pathnames
** Phase 3 - Check Connectivity
** Phase 4 - Check Reference Counts
** Phase 5 - Cylinder Groups
929 files, 8928 used, 2851 free (75 frags, 347 blocks, 0.6%
fragmentation)
/dev/rdsk/c0t0d0s6 FILE SYSTEM STATE SET TO OKAY
***** FILE SYSTEM WAS MODIFIED *****
Preening UFS File Systems
The preen option to fsck (fsck -o p) checks UFS file systems and automatically
fixes the simple problems that normally result from an unexpected system shutdown.
It exits immediately if it encounters a problem that requires operator intervention.
The preen option also permits parallel checking of file systems.
You can run fsck with theo p option to preen the file systems after an unclean
shutdown. In this mode, fsck does not look at the clean flag and does a full check.
These actions are a subset of the actions that fsck takes when it runs interactively.
How to Preen a File System
1. Become superuser.
Checking File System Integrity
521
2. Unmount the file system.
# umount mount-point
3. Check a UFS file system with the preen option.
# fsck -o p /dev/rdsk/device-name
You can preen individual file systems by using mount-point or
/dev/rdsk/device-name as arguments to fsck.
Example—Preening a File System
The following example preens the /usr file system.
# fsck -o p /usr
Restoring a Bad Superblock
When the superblock of a file system becomes damaged, you must restore it. fsck
tells you when a superblock is bad. Fortunately, redundant copies of the superblock
are stored within a file system. You can use fsck -o b to replace the superblock
with one of the copies.
How to Restore a Bad Superblock
1. Become superuser.
2. Change to a directory outside the damaged file system.
3. Unmount the file system.
# umount mount-point
Caution - Be sure to use the newfs -N in the next step. If you omit theN option,
you will create a new, empty file system.
522
4. Display the superblock values with the newfs -N command.
# newfs -N /dev/rdsk/device-name
The output of this command displays the block numbers that were used for the
superblock copies when newfs created the file system, unless the file system was
created with special parameters. See “Deciding on Custom File System
Parameters” on page 542 for information on creating a customized file system.
5. Provide an alternative superblock with the fsck command.
# fsck -F ufs -o b=block-number /dev/rdsk/device-name
fsck uses the alternative superblock you specify to restore the primary
superblock. You can always try 32 as an alternative block, or use any of the
alternative blocks shown by newfs -N.
Example—Restoring a Bad Superblock
The following example restores the superblock copy 5264 for the /files7 file
system:
# cd /
# umount /files7
# newfs -N /dev/rdsk/c0t3d0s7
/dev/rdsk/c0t3d0s7: 163944 sectors in 506 cylinders of 9 tracks, 36 sectors
83.9MB in 32 cyl groups (16 c/g, 2.65MB/g, 1216 i/g)
super-block backups (for fsck -b #) at:
32, 5264, 10496, 15728, 20960, 26192, 31424, 36656, 41888,
47120, 52352, 57584, 62816, 68048, 73280, 78512, 82976, 88208,
93440, 98672, 103904, 109136, 114368, 119600, 124832, 130064, 135296,
140528, 145760, 150992, 156224, 161456,
# fsck -F ufs -o b=5264 /dev/rdsk/c0t3d0s7
Alternate superblock location: 5264.
** /dev/rdsk/c0t3d0s7
** Last Mounted on
** Phase 1 - Check Blocks and Sizes
** Phase 2 - Check Pathnames
** Phase 3 - Check Connectivity
** Phase 4 - Check Reference Counts
** Phase 5 - Check Cyl groups
36 files, 867 used, 75712 free (16 frags, 9462 blocks, 0.0% fragmentation)
/dev/rdsk/c0t3d0s7 FILE SYSTEM STATE SET TO OKAY
***** FILE SYSTEM WAS MODIFIED *****
#
If the superblock in the root (/) file system becomes damaged and you cannot boot
the system, reinstall /kernel/unix and rebuild the root (/) file system with newfs.
Checking File System Integrity
523
Because a superblock is created by the newfs command, you do not need to restore
it.
How to Fix a UFS File System fsck Cannot Repair
Sometimes you need to run fsck a few times to fix a file system because problems
corrected on one pass might uncover other problems not found in earlier passes.
fsck does not keep running until it comes up clean, so you must rerun it manually.
Pay attention to the information displayed by fsck. It might help you fix the
problem. For example, the messages might point to a bad directory. If you delete the
directory, you might find that fsck runs cleanly.
If fsck still cannot repair the file system, you can try to use the fsdb, ff, clri, and
ncheck commands to figure out and fix what is wrong. See fsdb(1M), ff(1M),
clri(1M), and ncheck(1M) for information about how to use these commands. You
might, ultimately, need to re-create the file system and restore its contents from
backup media. See Chapter 44 for information about restoring complete file systems.
If you cannot fully repair a file system but you can mount it read-only, try using cp,
tar, or cpio to retrieve all or part of the data from the file system.
If hardware disk errors are causing the problem, you might need to reformat and
divide the disk into slices again before re-creating and restoring file systems.
Hardware errors usually display the same error again and again across different
commands. The format command tries to work around bad blocks on the disk. If
the disk is too severely damaged, however, the problems might persist, even after
reformatting. See format(1M) for information about using the format command.
See Chapter 30 or Chapter 31 for information about installing a new disk.
Syntax and Options for the fsck
Command
The fsck command checks and repairs inconsistencies in file systems. It has four
options:
Checks only whether a file system can be mounted (fsck -m)
Interactively asks for confirmation before making repairs (fsck)
Assumes yes or no response for all repairs (fsck -y or fsck -n)
Noninteractively preens the file system, fixing all expected (innocuous)
inconsistencies, but exiting when a serious problem is encountered (fsck -o p)
524
Generic fsck Command Syntax, Options, and
Arguments
The fsck command has two components: a generic component and a component
specific to each type of file system. The generic commands apply to most types of file
systems, while the specific commands apply to only one type of file system. You
should always use the generic command, which calls the file system-specific
command, as needed.
Usually, you must be superuser to run fsck. You can run the fsck command
without being superuser; but to make repairs, you should unmount the file system
and you must have read permission for the raw device file for the slice (a potential
security hole).
The generic fsck command goes through /etc/vfstab to see what file systems to
check. It runs the appropriate file system-specific fsck command on each file system
listed, except those excluded by an fsck pass number of - or 0 (UFS only).
The generic fsck command has the following syntax:
/usr/sbin/fsck [-F type] [-V] [-m] [special]
/usr/sbin/fsck [-F type] [-V] [-y|Y|n|N] [-o specific-options][special]
The table below describes the options and arguments to the generic fsck command.
TABLE 39-4
The fsck Command Options and Arguments
Option Type
Option
Description
Generic
Specifies the file system type (type). If type is
F
not specified on the command line, it is obtained
from /etc/vfstab by matching an entry in that
file with the special device name specified. If no
entry is found, the default local file system type
specified in /etc/default/fs is used.
Echoes the completed command line (verbose).
V
The echoed line includes additional information
derived from /etc/vfstab. This option can be
used to verify and validate the command line. It
does not execute the command.
Performs a preliminary check only. It returns a
m
code indicating the state of the file system: 0 for
“clean” and 32 for “dirty.” This option is used by
the startup script /sbin/rcS to determine
whether a file system needs to be checked.
Checking File System Integrity
525
TABLE 39-4
The fsck Command Options and Arguments
(continued)
Option Type
Option
Description
Runs the command automatically answering yes
y orY orn or
or no to all prompts.
N
c
Converts an old pre-SunOS 4.1 file system with
statically allocated tables to new dynamically
allocated tables. Static allocation imposes a hard
maximum on table size, while dynamic allocation
means space for tables can be added as needed
after the initial allocation. If the file system is in
the new format, convert it to the old format,
unless the table allocation exceeds the fixed
maximum allowed in the old format. fsck lists
the direction of the conversion. In interactive
mode, fsck prompts for confirmation before
doing the conversion. When you use theo p
option, the conversion is attempted without asking
for confirmation. This option is useful when you
want to convert a number of file systems at once.
You can determine whether a file system is in the
old or new format by running the fstyp
command, and looking at the first line displayed.
w
Checks only file systems that permit write access.
special
Specifies the mount point or raw device name of
one or more file systems. An entry for the mount
point must exist in /etc/vfstab. If you omit the
special argument, entries in /etc/vfstab with a
specified fsck device and a fsck pass number
greater than zero are checked. If preening (o p)
is in effect and more than one entry has an fsck
pass number greater than 1, file systems on
different disks are checked in parallel.
Specific
This is a comma-separated list of options that
follow theo option. Describes the options that
are passed to the UFS-specific fsck command for
interpretation.
526
TABLE 39-4
The fsck Command Options and Arguments
(continued)
Option Type
Option
Description
p
Preens. Runs the command automatically in silent
mode, correcting what it can, but exiting when it
encounters a problem that requires intervention.
This option also enables parallel checking of UFS
file systems.
b=blocknumber
Uses the alternative (redundant) superblock,
located at the specified location. This option can
be used to repair a bad superblock. You can
display a list of alternative superblocks by using
the newfs -N command.
Checking File System Integrity
527
528
CHAPTER
40
UFS File System Reference
This is a list of the reference information in this chapter.
“Default Directories for root (/) and /usr File Systems” on page 529
“The Structure of UFS File System Cylinder Groups” on page 538
“Deciding on Custom File System Parameters” on page 542
“Commands for Creating a Customized File System” on page 545
Default Directories for root (/) and
/usr File Systems
The /kernel directory contains only platform-independent objects, including a
platform-independent kernel, genunix. See Table 40-3 for a description of
/platform and /usr/platform, the platform-dependent directories.
The table below describes all the default directories contained in the root (/) file
system.
TABLE 40-1
Default Directories in the root (/) File System
Directory
Description
/
Root of the overall file system name space
/dev
Primary location for special files
529

 

 

 

 

 

 

 

Content      ..     14      15      16      17     ..