管理solaris10文件系统II
管理solaris10文件系统IIA
file system
can become damaged if it is corrupted from a power failure, a software error in the kernel, a hardware failure, or an improper shutdown of the
system
.
The file system check program, fsck, checks the data consistency of a file system and attempts to correct or repair any inconsistencies or damage found.
Caution: Never run the fsck command on a mounted file system. This could leave the file system in an unusable state. It could also delete data. The / (root), /usr, and /var file systems should have the fsck command run on them while in single-user mode.
Every time you boot a system, the
operating system
determines which file systems the fsck command should check. The fsck command checks and repairs any problems encountered in file systems before they are mounted.
Note: The status of a file system’s state flag determines whether the file system needs to be scanned by the fsck command. When the state flag is “clean,” “stable,” or “logging,” file system scans are not run.
The fsck command makes several passes through a file system. During each pass, the fsck command checks for several types of file system inconsistencies.
The file system superblock is checked for inconsistencies involving such parameters as file system size, free block count, and free inode count.
The fsck command checks any unallocated data blocks claimed by inodes, the unallocated data block count, and the unallocated inode count.
The fsck command checks for the allocation state of inodes, as well as the type, the link count, duplicate blocks (blocks already claimed by another inode), bad blocks, the inode size, and the block count for each inode. Any unreferenced inode with a nonzero link count is linked to the file system’s lost+found directory.
The fsck command cannot check ordinary data blocks, but it can check directory data blocks. In directory data blocks, the fsck command checks for inodes that point to unallocated blocks, unallocated blocks tagged as in use, allocated blocks tagged as free (incorrect inodes for . and ..) and directories not connected to the file system. These directories are linked back to the file system in its lost+found directory.
The fsck command puts files and directories that are allocated but unreferenced in the lost+found directory located in that file system. The inode number of each file is assigned as the file name. If the lost+found directory does not exist, the fsck command creates it. If not enough space exists in the lost+found directory, the fsck command increases the directory’s size.
During a normal system boot, the fsck command operates in noninteractive mode, which is often referred to as preen, or silent mode. In this mode, the fsck command addresses only minor inconsistency problems that can be corrected. If a more serious inconsistency is found and a decision has to be made, the fsck program terminates and requests the root password to enter single-user mode. Execute the fsck command in
interactive
mode to continue.
In interactive mode, the fsck command lists each problem it encounters, followed by a suggested corrective action in the form of a question that requires a yes or no response.
The following example shows how the fsck command displays a message that asks if you want to correct the block count.
# fsck /dev/rdsk/c0t0d0s7
** /dev/rdsk/c0t0d0s7
** Last Mounted on /export/home
** Phase 1 - Check Blocks and Sizes
INCORRECT BLOCK COUNT I=743 (5 should be 2)
CORRECT?
If you respond with yes, the fsck command applies the corrective action and moves on. If you respond with no, the fsck command repeats the message about the original problem and suggests corrective action. It does not fix the inconsistency until you respond yes.
The following examples demonstrate how you as the system’s root user can run the fsck command to check the integrity of file systems.
To check a single unmounted file system, perform the command: # fsck /dev/rdsk/c0t0d0s7
This is the only way to check a file system that has not been entered in the /etc/vfstab file.
To check a file system using the mount point directory name as listed in the /etc/vfstab file, perform the command: # fsck /export/home
In the following example, the fsck command checks and repairs the file system with the force (f) and preen (p) options.
# fsck -o f,p /dev/rdsk/c0t0d0s7
/dev/rdsk/c0t0d0s7: 77 files, 9621 used, 46089 free
/dev/rdsk/c0t0d0s7: (4 frags, 57 blocks, 0.0% fragmentation)
The f option of the fsck command forces a file system check, regardless of the state of the file system’s superblock state flag.
The p option checks and fixes the file system noninteractively (preen). The program exits immediately if a problem requiring intervention is found.
If problems are located in a file system, you are alerted by the fsck utility. Some of the more common file
system errors
that require interactive intervention are:
Allocated unreferenced file
Inconsistent link count
Free block count corruption
Superblock corruption
If the fsck command discovers an inode that is allocated but unreferenced or not linked in any directory, the command sends a message that asks you if you want to reconnect the inode.
** Phase 3 - Check Connectivity
UNREF FILE I=788 OWNER=root MODE=100644
SIZE=19994 MTIME=Oct 18 10:49 2004
RECONNECT? y
A yes response causes the fsck command to save the file to the lost+found directory. The fsck command references the inode number.
To determine the type of file moved to the lost+found directory by the fsck command, perform the following steps:
List the contents of the file system’s lost+found directory. # ls /export/home/lost+found
#788
Determine the
file type
by using the file command. # file /export/home/lost+found/#788
/export/home/lost+found/#788: ascii text
To view the contents of an
ASCII
text file, use the more or cat command. To view the contents of a binary file, use the strings command. If the file is associated with an
application
, such as a word processing document, use the application to view the contents of the file. # cat /export/home/lost+found/#788
If the file is intact and you know where it belongs, you can copy the file back to its original location in the file system. # cp /export/home/lost+found/#788 /export/home/user1/report
If the fsck program discovers that the value of a directory inode link counter and the actual number of directory links are inconsistent, the command displays a message that asks you if you want to adjust the counter.
** Phase 4 - Check Reference Counts
LINK COUNT DIR I=2 OWNER=root MODE=40755
SIZE=512 MTIME=Oct 18 15:59 2004 COUNT 4 SHOULD BE 3
ADJUST? y
In the example, a y (yes) response causes the fsck command to correct the directory inode link counter from 4 to 3.
During this phase, you might also be asked to clear or remove a link.
BAD/DUP type I=200 OWNER=root MODE=40755
SIZE=512 MTIME=Mar 14 08:03 2004
CLEAR? y
If the fsck utility discovers that the unallocated block count and the free block number listed in the superblock are inconsistent, the fsck command displays a message that asks if you want to salvage the free block count by rectifying it with the unallocated block count.
** Phase 5 - Check Cyl groups
CG 0: BAD MAGIC NUMBER
FREE BLK COUNT(S) WRONG IN SUPERBLK
SALVAGE? y
In the example, a y (yes) response causes the fsck command to update the information in the file system superblock.
Superblock corruption can cause a file system to be unmountable. A file system is unusable when the message such as “Can’t mount file_system_name” or “device_name is not this fstype” appears.
Can’t mount /dev/dsk/c0t0d0s7
This message can appear during a system boot or when you are manually mounting the file system.
If the fsck command fails because of a corrupted superblock, you see an
error message
that tells you to execute the fsck command using a superblock backup to recover the file system. Execute the fsck command with the -o option and with the b flag followed by a backup superblock number. Every file system has an alternative backup superblock at block number 32, which can be used with the fsck command to repair the primary superblock.
The following command uses a backup superblock.
# fsck -o b=32 /dev/rdsk/c0t0d0s7
Alternate super block location: 32.
** /dev/rdsk/c0t0d0s7
** 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
2 files, 9 used, 5174880 free (16 frags, 646858 blocks, 0.0% fragmentation)
#
The fsck utility compares the information in the backup superblock with the actual file system and attempts to rebuild the primary superblock. However, if the first backup superblock is part of the file system that was damaged, it might be unusable. Select another backup superblock to continue the fsck command.
To list the locations of all the alternative backup superblocks in the file system, run the newfs -N command.
Caution: This method works if the underlying file system was built using the newfs default parameters. If the file system was not built with these defaults, execute the newfs -N command, using the same parameters originally used, to generate identical superblock locations.
Use the -N option to view the file system parameters that you could use to create a new file system without actually creating the file system. A portion of the output is a list of the locations of all the alternative backup superblocks that can be used with the fsck -o b=# command.
# newfs -N /dev/rdsk/c1t3d0s7
/dev/rdsk/c1t3d0s7: 6295022 sectors in 1753 cylinders of 27 tracks, 133 sectors
3073.7MB in 110 cyl groups (16 c/g, 28.05MB/g, 3392 i/g)
super-block backups (for fsck -F ufs -o b=#) at:
32, 57632, 115232, 172832, 230432, 288032, 345632, 403232, 460832,
518432, 5746208, 5803808, 5861408, 5919008, 5976608, 6034208, 6091808,
6149408, 6207008, 6264608,
#
The -T option allows the file system to be a multi-Terabyte file system. You can view the file system parameters using this option without actually creating the file system.
# newfs -N -T /dev/rdsk/c1t3d0s7
Warning: cylinder groups must have a multiple of 16 cylinders with the
given parameters
Rounded cgsize up to 176
Warning: 15 sector(s) in last cylinder unallocated
/dev/rdsk/c1t3d0s7: 6295008 sectors in 1753 cylinders of 27 tracks, 133 sectors
3073.7MB in 11 cyl groups (160 c/g, 280.55MB/g, 320 i/g)
super-block backups (for fsck -F ufs -o b=#) at:
32, 574736, 1149440, 1724144, 2298848, 2873552, 3448256, 4022960,
4597664, 5172368, 5747072,
You can use any other alternative superblock number in the list with the fsck command.
# fsck -o b=535952 /dev/rdsk/c0t0d0s7
Alternate super block location: 518432
** /dev/rdsk/c0t0d0s7
** 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
7 files, 14 used, 279825 free (17 frags, 347891 blocks, 0.0% fragmentation)
*****FILE SYSTEM WAS MODIFIED*****
#
An important activity of a system administrator is to monitor file system use on a regular basis. There are three useful commands available for this task:
[*]df - Displays the number of free disk blocks
[*]du - Summarizes disk use
[*]quot - Summarizes file system ownership
Use the df command to display the amount of disk space used in file systems. This command lists the amount of used and available space and the amount of the file system’s total capacity being used.
The format for the df command is:
df -option resource
The table lists some of the more common options used with the df command.
Partial Listing of Options for the df Command :
Option
Description
-a
Reports on all file systems, including those with entries in the /etc/mnttab file for which the ignore option is set
-b
Prints the total number of Kbytes free
-e
Prints only the number of files free
-k
Displays disk allocation in Kbytes
-h
Acts like the -k option, except that sizes are in a more readable format, for example, 14K, 234M, 2.7G, or 3.0T
-l
Reports on local file systems only
-F FSType
Specifies the file system type on which to operate. This is intended for use on unmounted file systems.
To display the capacity of file systems, perform the command:
# df -k
Filesystem kbytes used avail capacityMounted on
/dev/dsk/c0t0d0s0 849518113485676567 15% /
/devices 0 0 0 0% /devices
ctfs 0 0 0 0% /system/contract
proc 0 0 0 0% /proc
mnttab 0 0 0 0% /etc/mnttab
swap 596608 360596248 1% /etc/svc/volatile
objfs 0 0 0 0% /system/object
/dev/dsk/c0t0d0p0:boot
11412 1504 9908 14% /boot
/dev/dsk/c0t0d0s6 3007086 2317518629427 79% /usr
fd 0 0 0 0% /dev/fd
/dev/dsk/c0t0d0s3 1785654 92508 1639577 6% /var
swap 596352 104596248 1% /var/run
swap 596568 320596248 1% /tmp
/dev/dsk/c0t0d0s7 424239 1046380770 1% /export/home
/dev/dsk/c1t3d0s7 3099093 3097 3065006 1% /data
The same file system displayed with the -h option would appear in human-readable format.
# df -h
Filesystem size usedavail capacityMounted on
/dev/dsk/c0t0d0s0 830M 111M 661M 15% /
/devices 0K 0K 0K 0% /devices
ctfs 0K 0K 0K 0% /system/contract
proc 0K 0K 0K 0% /proc
mnttab 0K 0K 0K 0% /etc/mnttab
swap 583M 360K 582M 1% /etc/svc/volatile
objfs 0K 0K 0K 0% /system/object
/dev/dsk/c0t0d0p0:boot
11M 1.5M 9.7M 14% /boot
/dev/dsk/c0t0d0s6 2.9G 2.2G 615M 79% /usr
fd 0K 0K 0K 0% /dev/fd
/dev/dsk/c0t0d0s3 1.7G 90M 1.6G 6% /var
swap 582M 104K 582M 1% /var/run
swap 583M 320K 582M 1% /tmp
/dev/dsk/c0t0d0s7 414M 1.0M 372M 1% /export/home
/dev/dsk/c1t3d0s7 3.0G 3.0M 2.9G 1% /data
The table defines the fields displayed by the df -k command.
Fields for the df -k Command
Field
Definition
Filesystem
The mounted file system
kbytes
The size of the file system in Kbytes (1024 bytes)
used
The number of Kbytes used
avail
The number of Kbytes available
capacity
The percentage of file system capacity used
Mounted on
The mount point
The amount of space that is reported as used and avail is typically less than the amount of total space in the file system. A fraction of space, from 1 to 10 percent, is reserved in each file system as the minfree value.
When all of the reported space on the file system is in use, the file system capacity is displayed as 100 percent. Regular users receive the message “File System Full” and cannot continue working. The reserved space is available to the root user, who can then delete or back up files in the file system.
The df -k command can be used with the device as the resource to show available space on the device:
# df -k /dev/dsk/c0t1d0s6
Filesystem kbytes used avail capacityMounted on
/dev/dsk/c0t1d0s6 17153338 9 16810225 0%
#
Use the du command to display the number of disk blocks used by directories and files. Each disk block consists of 512 bytes.
The format for the du command is:
du -options directory
The table describes the options for the du command.
Options for the du Command
Option
Description
-k
Displays disk use in Kbytes.
-s
Displays only the summary in 512-byte blocks. Using the s and k options together shows the summary in Kbytes.
-a
Displays the number of blocks used by all files in addition to directories within the specified directory hierarchy.
To display disk usage in kilobytes, perform the command:
# cd /opt
# du -k
8 ./lost+found
3 ./SUNWits/Graphics-sw/xil/lib
4 ./SUNWits/Graphics-sw/xil
5 ./SUNWits/Graphics-sw
6 ./SUNWits
15 ./SUNWmlib/lib/i386
30 ./SUNWmlib/lib
24 ./SUNWmlib/include
56 ./SUNWmlib
20873 ./sfw/info
15 ./sfw/share/emacs/site-lisp/emacspeak/etc/forms
20 ./sfw/share/emacs/site-lisp/emacspeak/etc/tables
253 ./sfw/share/emacs/site-lisp/emacspeak/etc
133 ./sfw/share/emacs/site-lisp/emacspeak/install-guide
2084 ./sfw/share/emacs/site-lisp/emacspeak/lisp/xml-forms
5672 ./sfw/share/emacs/site-lisp/emacspeak/lisp
686 .
To display disk usage in readable form, perform the command:
# du -h /opt |more
8K /opt/lost+found
3K /opt/SUNWits/Graphics-sw/xil/lib
4K /opt/SUNWits/Graphics-sw/xil
5K /opt/SUNWits/Graphics-sw
6K /opt/SUNWits
15K /opt/SUNWmlib/lib/i386
30K /opt/SUNWmlib/lib
24K /opt/SUNWmlib/include
56K /opt/SUNWmlib
20M /opt/sfw/info
15K /opt/sfw/share/emacs/site-lisp/emacspeak/etc/forms
20K /opt/sfw/share/emacs/site-lisp/emacspeak/etc/tables
253K /opt/sfw/share/emacs/site-lisp/emacspeak/etc
133K /opt/sfw/share/emacs/site-lisp/emacspeak/install-guide
2.0M /opt/sfw/share/emacs/site-lisp/emacspeak/lisp/xml-forms
5.5M /opt/sfw/share/emacs/site-lisp/emacspeak/lisp
1K
/opt/sfw/share/emacs/site-lisp/emacspeak/realaudio/books/burroughs
1K
/opt/sfw/share/emacs/site-lisp/emacspeak/realaudio/books/dickens
1K /opt/sfw/share/emacs/site-lisp/emacspeak/realaudio/books/doyle
1K
/opt/sfw/share/emacs/site-lisp/emacspeak/realaudio/books/fredrick-forsythe
1K
/opt/sfw/share/emacs/site-lisp/emacspeak/realaudio/books/graham-green
To display disk usage including files, perform the command:
# du -ak /opt
1 /opt/SUNWits/Graphics-sw/xil/lib/libxil.so
1 /opt/SUNWits/Graphics-sw/xil/lib/libxil.so.1
3 /opt/SUNWits/Graphics-sw/xil/lib
4 /opt/SUNWits/Graphics-sw/xil
(output removed for brevity)
184 /opt/sfw/GNUstep/Apps/WPrefs.app/tiff
1 /opt/sfw/GNUstep/Apps/WPrefs.app/xpm
4560 /opt/sfw/GNUstep/Apps/WPrefs.app/WPrefs
12 /opt/sfw/GNUstep/Apps/WPrefs.app/WPrefs.tiff
29 /opt/sfw/GNUstep/Apps/WPrefs.app/WPrefs.xpm
4787 /opt/sfw/GNUstep/Apps/WPrefs.app
4788 /opt/sfw/GNUstep/Apps
4789 /opt/sfw/GNUstep
1416254 /opt/sfw
1416325 /opt
To display only a summary of disk usage, perform the command:
# du -sk /opt
686 /opt
Use the quot command to display how much disk space, in kilobytes, is being used by users.
The format for the quot command is:
quot -options filesystem
The table describes the options for the quot command.
Options for the quot Command
Option
Description
-a
Reports on all mounted file systems
-f
Includes the number of files
To display disk space being used by users on all mounted file systems, perform the command:
# quot -af
/dev/rdsk/c0t0d0s0 (/):
112410 5246 root
31 12 uucp
11 11 lp
1 1 adm
/dev/rdsk/c0t0d0s6 (/usr):
2313692 102415root
806 15 uucp
11 4 bin
1 1 adm
…
The columns represent kilobytes used, number of files, and owner, respectively.
To display a count of the number of files and space owned by each user for a specific file system, enter the following:
# quot -f /dev/dsk/c0t0d0s7
/dev/rdsk/c0t0d0s7 (/export/home):
9 2 root
15 35 sue
51 51 paul
23 25 jeff
The Solaris Management Console Usage Tool provides a graphical display of the available space for all mounted file systems.
To use the Solaris Management Console storage Usage Tool, launch the Solaris Management Console by typing smc& at a command line, or select it from the Application Manager Window. To locate the Usage Tool, select This Computer, then select Storage, then select Mounts and Shares on the Solaris Management Console.
The image shows the Management Tools: Solaris Management Console window with the disk usage information.
http://blogimg.chinaunix.net/blog/upfile2/080119140935.gif
Performing Mounts and Umounts
The following procedure describes how to boot from the Solaris OS software CD-ROM to edit a mis-configured /etc/vfstab file.
Insert the
Solaris 10 OS
Software DVD or the 1 of 4 CD-ROM into the
CD-ROM drive
.
Your system needs to be configured to boot from the DVD or CD-ROM. This might need to be set in your BIOS settings before booting. Execute a single-user boot from the DVD or CD-ROM or boot from the DCA diskette.
If you are using the boot diskette, the Device Configuration Assistant menu is displayed. If you are using the Solaris Software 1 CD or DVD, the system boots automatically. To enter the Device Configuration Assistant menu, press Esc to interrupt the boot process, when prompted by the system.
Solaris
Booting System
Running Configuration Assistant…
If the system hardware has changed, or to boot from a different
device, interrupt the autoboot process by pressing ESC.
Press ESCape to interrupt autoboot in 5 seconds.
Initializing
system
Please wait…
The Current Boot Parameters menu is displayed after a few minutes. >>
Boot path: /pci@0,0/pci-ide@7,1/ide@1/sd@0,0:a
Boot args:
Select the type of installation you want to perform:
1 Solaris Interactive
2 Custom JumpStart
3 Solaris Interactive Text (
Desktop
session)
4 Solaris Interactive Text (Console session)
Enter the number of your choice followed by thekey.
Alternatively, enter custom boot arguments directly.
If you wait for 30 seconds without typing anything,
an interactive installation will be started.
Type b -s at the prompt. Press Enter. Select type of installation: b-s
After a few minutes, the single-user mode # prompt is displayed. (output omitted)
INIT: SINGLE USER MODE
#
Note: Performing a single-user boot operation from this software CD-ROM creates an in-memory copy of the /root
file system
, which supports your ability to perform administrative tasks.
Use the fsck command on the faulty / (root) partition to check and repair any potential problems in the file system and make device writable. # fsck /dev/rdsk/c0t0d0s0
If the fsck command is successful, mount the / (root) file system on the /a directory to gain access to the file system on disk.
# mount /dev/dsk/c0t0d0s0 /a
Set and export the TERM variable, which enables the vi editor to work properly. # TERM=sun
# export TERM
Edit the /etc/vfstab file, and correct any problems. Then exit the file. # vi /a/etc/vfstab
:wq!
Unmount the file system. # cd /
# umount /a
Reboot the system. # init 6
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/36549/showart_467843.html
页:
[1]