fsck 명령어 (AIX 5.3·6.1)

핵심 정리

  • 파일 시스템의 일관성(블록 중복 할당, inode·디렉터리 오류, 맵 불일치 등)을 검사하고 묻고 고칩니다. 마운트한 파일 시스템은 고치지 않으므로 먼저 umount합니다.
  • 자주 쓰는 형태: fsck /dev/datalv나 fsck /data(묻고 고침), fsck -y /data(모두 yes, 심하게 망가졌을 때), fsck -n /data(검사만), fsck -p(작은 문제 자동 수정).
  • 인수가 없으면 /etc/filesystems에서 check=true(또는 check=번호)인 파일 시스템을 모두 검사합니다.
  • 부팅할 때 /, /usr, /var, /tmp를 fsck -fp로 검사하며, 실패하면 부팅하지 못해 매체로 부팅해 유지 보수 모드에서 고쳐야 합니다.
  • 되돌아갈 수 없는 곳은 lost+found로 옮기며, 종료 값 4는 즉시 재시작해야 한다는 뜻입니다. JFS2 로그 문제면 logform이 필요할 수 있습니다.
항목 내용
버전 AIX 5.3, AIX 6.1 (6.1에서 내부 스냅숏 삭제, 논리 볼륨 독점 접근 참고, RBAC 안내가 더해짐)
원문 IBM Commands Reference — 5.3 Volume 2, 6.1 Volume 2
파일 /usr/sbin/fsck, /etc/filesystems, /etc/vfs, /etc/rc
관련 명령어 umount, mount, fsdb, dfsck, logform

목적

파일 시스템의 일관성을 검사하고 대화식으로 고칩니다.

영어 원문

Checks file system consistency and interactively repairs the file system.

구문

text
fsck [ -n ] [ -p ] [ -y ] [ -dBlockNumber ] [ -f ] [ -ii-NodeNumber ] [ -o Options ] [ -tFile ] [ -V VfsName ] [ FileSystem1 - FileSystem2 ... ]

설명

주의: 시스템이 잘못 멈춘 뒤에는 항상 파일 시스템에 fsck를 실행합니다. 고치는 과정에서 데이터를 일부 잃을 수 있습니다. 고칠 때마다 기본으로 운영자가 yes나 no를 입력하기를 기다립니다. 해당 파일 시스템에 쓰기 권한이 없으면 실제 응답과 상관없이 no로 처리합니다.

참고:

  1. 마운트한 파일 시스템은 고치지 않습니다.
  2. 고치는 것 말고 다른 목적으로는 마운트한 파일 시스템에도 실행할 수 있지만, 이때는 잘못된 오류 메시지가 나올 수 있습니다.

fsck는 일관성이 깨진 파일 시스템을 검사하고 대화식으로 고칩니다. 파일 시스템을 마운트하기 전에 실행하는 것이 좋습니다. 파일 시스템이 있는 장치 파일(예: /dev/hd0)을 읽을 수 있어야 합니다. 보통은 일관된 상태라 파일 수, 사용 블록, 빈 블록만 보고하고, 일관성이 깨졌으면 찾은 내용을 보여 주고 고칠지 묻습니다.

fsck는 보수적으로 고치며 올바른 데이터를 잃을 수 있는 작업은 피하려 합니다. 그래도 손상된 파일을 없애자고 권하는 경우가 있습니다. 필요한 수리를 허락하지 않으면 일관성이 깨진 채로 남을 수 있고, 그런 파일 시스템을 마운트하면 시스템이 멈출 수 있습니다.

JFS2에 스냅숏이 있으면 보존하려 합니다. 실패하면 스냅숏이 원본 파일 시스템의 이전 이미지를 모두 담고 있다고 보장할 수 없으므로 스냅숏과 스냅숏 논리 볼륨을 지웁니다. (6.1) 파일 시스템을 고치면 내부 스냅숏은 지워집니다.

FileSystem 매개변수가 없으면 /etc/filesystems에서 check 속성이 True인 파일 시스템을 모두 검사합니다. 스탠자에 check=true를 넣어 켭니다.

check=Number로 파일 시스템을 묶어 검사할 수도 있습니다. Number는 그 파일 시스템이 속한 묶음이며, 같은 로그 장치를 쓰는 파일 시스템은 같은 묶음에 넣어야 합니다. 묶음 순서대로, 그 안에서는 /etc/filesystems에 적힌 순서대로 하나씩 검사합니다. check=true인 것은 모두 묶음 1입니다. 명령줄이나 파일의 순서와 상관없이 루트 파일 시스템을 가장 먼저 검사합니다.

검사하는 불일치:

  • 여러 파일에 할당된 블록이나 조각
  • 블록·조각 번호가 겹치는 inode
  • 범위를 벗어난 블록·조각 번호를 가진 inode
  • 파일을 가리키는 디렉터리 참조 수와 링크 수의 차이
  • 잘못 할당된 블록이나 조각
  • 디스크 맵에서 빈 것으로 표시된 블록·조각 번호를 가진 inode
  • 손상된 블록·조각 번호를 가진 inode
  • inode의 마지막 디스크 주소가 아닌 조각(압축 파일 시스템 제외)
  • 조각을 포함한 32KB보다 큰 파일(압축 파일 시스템 제외)
  • 크기 검사: 블록 수가 틀림, 디렉터리 크기가 512바이트의 배수가 아님(압축 파일 시스템 제외)
  • 디렉터리 검사: inode 맵에서 빈 것으로 표시된 inode 번호를 가진 항목, 범위를 벗어난 inode 번호, 자신을 가리키지 않거나 없는 ., 부모를 가리키지 않거나 없는 .., 참조되지 않는 파일이나 닿을 수 없는 디렉터리
  • 디스크 맵 불일치
  • inode 맵 불일치

닿을 수 없는(고아) 파일과 디렉터리는 허락하면 파일 시스템 루트의 lost+found 디렉터리에 inode 번호를 이름으로 붙여 다시 연결합니다. 다시 연결하지 않으면 지울지 묻습니다.

메시지와 함께 종료 값으로도 결과를 알립니다. 종료 값은 다음 값의 합입니다.

값 뜻
0 검사한 파일 시스템이 모두 정상
2 검사나 수리를 마치기 전에 중단됨
4 파일 시스템을 바꿨으므로 즉시 시스템을 다시 시작해야 함
8 고치지 못한 손상이 있음

(6.1) fsck는 파일 시스템 아래 논리 볼륨 장치를 독점해서 써야 합니다. 장치를 쓸 수 없어 실패했으면 장치가 풀린 뒤 다시 실행합니다.

디스크로 부팅하면 부팅 과정이 /, /usr, /var, /tmp에 -f, -p를 주어 fsck를 실행합니다. 이 가운데 하나라도 실패하면 부팅하지 못하며, 이동식 매체로 부팅해 유지 보수 작업을 해야 합니다.

넷 모두 성공하면 초기화를 이어 가고, /etc/rc에서 -f, -p로 check=true인 파일 시스템을 검사합니다. 여기서 일관성을 보장하지 못해도 초기화는 계속되지만, 그 파일 시스템은 마운트에 실패할 수 있고 초기화가 덜 끝날 수 있습니다.

참고: /, /usr, /var, /tmp는 /etc/filesystems에 기본으로 check=false입니다. 부팅 과정이 따로 검사하고, /etc/rc를 실행할 때는 이미 마운트되어 있어 fsck가 고치지 못하고 결과도 믿을 수 없기 때문입니다.

Web-based System Manager(wsm)의 File Systems 응용 프로그램이나 SMIT 빠른 경로 smit fsck로도 실행할 수 있습니다.

영어 원문

Attention: Always run the fsck command on file systems after a system malfunction. Corrective actions may result in some loss of data. The default action for each consistency correction is to wait for the operator to enter yes or no. If you do not have write permission for an affected file system, the fsck command defaults to a no response in spite of your actual response.

Notes:

  1. The fsck command does not make corrections to a mounted file system.

  2. The fsck command can be run on a mounted file system for reasons other than repairs. However, inaccurate error messages may be returned when the file system is mounted.

The fsck command checks and interactively repairs inconsistent file systems. You should run this command before mounting any file system. You must be able to read the device file on which the file system resides (for example, the /dev/hd0 device). Normally, the file system is consistent, and the fsck command merely reports on the number of files, used blocks, and free blocks in the file system. If the file system is inconsistent, the fsck command displays information about the inconsistencies found and prompts you for permission to repair them.

The fsck command is conservative in its repair efforts and tries to avoid actions that might result in the loss of valid data. In certain cases, however, the fsck command recommends the destruction of a damaged file. If you do not allow the fsck command to perform the necessary repairs, an inconsistent file system may result. Mounting an inconsistent file system may result in a system crash.

If a JFS2 file system has snapshots, the fsck command will attempt to preserve them. If this action fails, the snapshots cannot be guaranteed to contain all of the before-images from the snapped file system. The fsck command will delete the snapshots and the snapshot logical volumes. Internal snapshots are deleted if the fsck command modifies the file system.

If you do not specify a file system with the FileSystem parameter, the fsck command checks all file systems listed in the /etc/filesystems file for which the check attribute is set to True. You can enable this type of checking by adding a line in the stanza, as follows: check=true

You can also perform checks on multiple file systems by grouping the file systems in the /etc/filesystems file. To do so, change the check attribute in the /etc/filesystems file as follows: check=Number

The Number parameter tells the fsck command which group contains a particular file system. File systems that use a common log device should be placed in the same group. File systems are checked, one at a time, in group order, and then in the order that they are listed in the /etc/filesystems file. All check=true file systems are in group 1. The fsck command attempts to check the root file system before any other file system regardless of the order specified on the command line or in the /etc/filesystems file.

The fsck command checks for the following inconsistencies:

  • Blocks or fragments allocated to multiple files.

  • i-nodes containing block or fragment numbers that overlap.

  • i-nodes containing block or fragment numbers out of range.

  • Discrepancies between the number of directory references to a file and the link count of the file.

  • Illegally allocated blocks or fragments.

  • i-nodes containing block or fragment numbers that are marked free in the disk map.

  • i-nodes containing corrupt block or fragment numbers.

  • A fragment that is not the last disk address in an i-node. This check does not apply to compressed file systems.

  • Files larger than 32KB containing a fragment. This check does not apply to compressed file systems.

  • Size checks: – Incorrect number of blocks. – Directory size not a multiple of 512 bytes. These checks do not apply to compressed file systems.

  • Directory checks: – Directory entry containing an i-node number marked free in the i-node map. – i-node number out of range. – Dot (.) link missing or not pointing to itself. – Dot dot (..) link missing or not pointing to the parent directory. – Files that are not referenced or directories that are not reachable.

  • Inconsistent disk map.

  • Inconsistent i-node map.

Orphaned files and directories (those that cannot be reached) are, if you allow it, reconnected by placing them in the lost+found subdirectory in the root directory of the file system. The name assigned is the i-node number. If you do not allow the fsck command to reattach an orphaned file, it requests permission to destroy the file.

In addition to its messages, the fsck command records the outcome of its checks and repairs through its exit value. This exit value can be any sum of the following conditions:

  • 0 — All checked file systems are now okay.
  • 2 — The fsck command was interrupted before it could complete checks or repairs.
  • 4 — The fsck command changed the file system; the user must restart the system immediately.
  • 8 — The file system contains unrepaired damage.

The fsck command requires exclusive access to the underlying logical volume device of the file system. If fsck fails because the underlying device is unavailable, then fsck should be retried after the device is free to be opened.

When the system is booted from a disk, the boot process explicitly runs the fsck command, specified with the -f and -p flags on the /, /usr, /var, and /tmp file systems. If the fsck command is unsuccessful on any of these file systems, the system does not boot. Booting from removable media and performing maintenance work will then be required before such a system will boot.

If the fsck command successfully runs on /, /usr, /var, and /tmp, normal system initialization continues. During normal system initialization, the fsck command specified with the -f and -p flags runs from the /etc/rc file. This command sequence checks all file systems in which the check attribute is set to True (check=true). If the fsck command executed from the /etc/rc file is unable to guarantee the consistency of any file system, system initialization continues. However, the mount of any inconsistent file systems may fail. A mount failure may cause incomplete system initialization.

Note: By default, the /, /usr, /var, and /tmp file systems have the check attribute set to False (check=false) in their /etc/filesystem stanzas. The attribute is set to False for the following reasons:

  1. The boot process explicitly runs the fsck command on the /, /usr, /var, and /tmp file systems.

  2. The /, /usr, /var, and /tmp file systems are mounted when the /etc/rc file is executed. The fsck command will not modify a mounted file system. Furthermore, the fsck command run on a mounted file system produces unreliable results.

You can use the File Systems application in Web-based System Manager (wsm) to change file system characteristics. You could also use the System Management Interface Tool (SMIT) smit fsck fast path to run this command.

플래그

플래그 설명
-dBlockNumber 지정한 디스크 블록을 참조하는 곳을 찾아 그 블록을 가진 파일의 inode 번호와 경로를 모두 보여 줍니다. JFS2는 inode 번호만 보여 주고 경로는 보여 주지 않습니다.
-f 빠른 검사. 제대로 내려진(unmount) 파일 시스템은 검사하지 않습니다. 슈퍼블록의 s_fmod 플래그로 판단하는데, 마운트할 때 켜지고 제대로 내리면 꺼집니다. 대부분은 제대로 내려지므로 검사 시간을 줄일 수 있습니다.
-ii-NodeNumber 지정한 inode를 참조하는 디렉터리 항목을 찾아 전체 경로를 보여 줍니다.
-n 모든 질문에 no로 답하고, 파일 시스템을 쓰기용으로 열지 않습니다.
-o Options 쉼표로 구분한 옵션을 넘깁니다. JFS용이며 새 파일 시스템에는 쓰지 않습니다. mountable은 마운트할 수 있으면(clean) 0, 아니면 8로 끝냅니다. mytype은 /etc/filesystems나 -V로 준 유형과 같으면 0, 아니면 8로 끝냅니다. 예: fsck -o mytype -V jfs /는 /가 JFS면 0.
-p 작은 문제는 메시지 없이 자동으로 고칩니다. -y처럼 모든 것을 허락하지는 않으며, 시스템 시작 절차처럼 자동으로 돌릴 때 씁니다. 주 슈퍼블록이 손상되었으면 보조 슈퍼블록을 검사해 주 슈퍼블록으로 복사합니다.
-tFile 메모리가 모자라 표를 담지 못할 때 쓸 임시 파일(검사하는 것과 다른 파일 시스템에 있어야 함). 없는데 필요하면 이름을 묻지만, -p를 주었으면 실패합니다. 특수 파일이 아니면 끝날 때 지웁니다.
-V VfsName /etc/filesystems 대신 지정한 VFS 설명을 씁니다. 없으면 /etc/filesystems에서 맞는 스탠자의 vfs= 속성을 유형으로 봅니다.
-y 모든 질문에 yes로 답해 필요한 작업을 모두 하게 합니다. 심하게 손상된 파일 시스템에만 씁니다.
영어 원문
  • -dBlockNumber — Searches for references to a specified disk block. Whenever the fsck command encounters a file that contains a specified block, it displays the i-node number and all path names that refer to it. For JFS2 filesystems, the i-node numbers referencing the specified block will be displayed but not their path names."
  • -f — Performs a fast check. Under normal circumstances, the only file systems likely to be affected by halting the system without shutting down properly are those that are mounted when the system stops. The -f flag prompts the fsck command not to check file systems that were unmounted successfully. The fsck command determines this by inspecting the s_fmod flag in the file system superblock. This flag is set whenever a file system is mounted and cleared when it is unmounted successfully. If a file system is unmounted successfully, it is unlikely to have any problems. Because most file systems are unmounted successfully, not checking those file systems can reduce the checking time.
  • -ii-NodeNumber — Searches for references to a specified i-node. Whenever the fsck command encounters a directory reference to a specified i-node, it displays the full path name of the reference.
  • -n — Assumes a no response to all questions asked by the fsck command; does not open the specified file system for writing.
  • -o Options — Passes comma-separated options to the fsck command. The following options are currently supported for JFS (these options are obsolete for newer file systems and can be ignored): mountable Causes the fsck command to exit with success, returning a value of 0, if the file system in question is mountable (clean). If the file system is not mountable, the fsck command exits returning with a value of 8. mytype Causes the fsck command to exit with success (0) if the file system in question is of the same type as either specified in the /etc/filesystems file or by the -V flag on the command line. Otherwise, 8 is returned. For example, fsck -o mytype -V jfs / exits with a value of 0 if / (the root file system) is a journaled file system.
  • -p — Does not display messages about minor problems but fixes them automatically. This flag does not grant the wholesale license that the -y flag does and is useful for performing automatic checks when the system is started normally. You should use this flag as part of the system startup procedures, whenever the system is being run automatically. If the primary superblock is corrupt, the secondary superblock is verified and copied to the primary superblock.
  • -tFile — Specifies a File parameter as a scratch file on a file system other than the one being checked, if the fsck command cannot obtain enough memory to keep its tables. If you do not specify the -t flag and the fsck command needs a scratch file, it prompts you for the name of the scratch file. However, if you have specified the -p flag, the fsck command is unsuccessful. If the scratch file is not a special file, it is removed when the fsck command ends.
  • -V VfsName — Uses the description of the virtual file system specified by the VFSName variable for the file system instead of using the /etc/filesystems file to determine the description. If the -V VfsName flag is not specified on the command line, the /etc/filesystems file is checked and the vfs=Attribute of the matching stanza is assumed to be the correct file system type.
  • -y — Assumes a yes response to all questions asked by the fsck command. This flag lets the fsck command take any action it considers necessary. Use this flag only on severely damaged file systems.

보안

(6.1) RBAC와 Trusted AIX 사용자: 이 명령은 특권 작업을 할 수 있으며 특권 사용자만 할 수 있습니다. 권한과 특권은 lssecattr 명령이나 getcmdattr 하위 명령으로 봅니다.

영어 원문

Attention RBAC users and Trusted AIX users: This command can perform privileged operations. Only privileged users can run privileged operations. For more information about authorizations and privileges, see Privileged Command Database in Security. For a list of privileges and the authorizations associated with this command, see the lssecattr command or the getcmdattr subcommand.

예제

명령 하는 일
fsck /etc/filesystems에서 check=true인 파일 시스템을 모두 검사. 바꾸기 전에 허락을 물음
fsck -p 기본 파일 시스템의 작은 문제를 자동으로 고침
fsck /dev/hd1 /dev/hd1 장치에 있는 마운트하지 않은 파일 시스템을 검사

자주 쓰는 형태:

bash
umount /data
fsck -y /dev/datalv          # 모두 yes로 고침
mount /data
fsck -n /data                # 고치지 않고 검사만
영어 원문
  1. To check all the default file systems, enter: fsck

This command checks all the file systems marked check=true in the /etc/filesystems file. This form of the fsck command asks you for permission before making any changes to a file system.

  1. To fix minor problems with the default file systems automatically, enter: fsck -p

  2. To check a specific file system, enter: fsck /dev/hd1

This command checks the unmounted file system located on the /dev/hd1 device.

파일

파일 설명
/usr/sbin/fsck fsck 명령
/etc/filesystems 알려진 파일 시스템과 그 특성
/etc/vfs 가상 파일 시스템 유형 설명
/etc/rc 시스템을 시작할 때 실행하는 명령(fsck 포함)
영어 원문
  • /usr/sbin/fsck — Contains the fsck command.
  • /etc/filesystems — Lists the known file systems and defines their characteristics.
  • /etc/vfs — Contains descriptions of virtual file system types.
  • /etc/rc — Contains commands (including the fsck command) that are run when the system is started.

Related reference:

  • dfsck Command
  • “fsdb Command”

Related information:

  • filsys.h file
  • File systems

리눅스(GNU)와 다른 점

리눅스에서는 파일 시스템 정보가 /etc/fstab에 있고(AIX는 스탠자 형식의 /etc/filesystems), LVM과 파일 시스템 명령이 나뉘어 있습니다. 만들기는 lvcreate 뒤 mkfs.xfs·mkfs.ext4, 늘리기는 lvextend -r(또는 lvextend 뒤 xfs_growfs·resize2fs), 지우기는 umount 뒤 /etc/fstab 항목과 lvremove로 따로 합니다. AIX의 crfs·chfs·rmfs는 이것을 한 명령으로 합니다. 리눅스 fsck는 fsck.ext4, xfs_repair 같은 유형별 도구를 부르는 앞단이며, 부팅 검사는 /etc/fstab의 여섯째 필드(pass)로 정합니다. -y, -n, -p(또는 -a)의 뜻은 비슷합니다.