728x90
1. fsck 란?
- 파일 시스템 검사 도구(File System Consistency Check): 디스크의 파일 시스템에서 오류를 감지하고, 데이터를 보호하기 위해 수정하는 역할을 합니다.
- 언제 사용해야 할까?
- 갑작스러운 시스템 종료로 인해 데이터 손상이 의심될 때
- 파일 또는 디렉터리가 제대로 읽히지 않을 때
- 파일 시스템이 "read-only" 모드로 전환되었을 때
2. 사용 전 주의 사항
2.1 데이터 손실 위험 알림
- 고객 또는 사용자 공지
- 파일 시스템 복구 작업 중 데이터 손실 가능성이 있음을 사전에 알려야함
- 복구 작업으로 인해 서비스 중단이 발생할 수 있음을 공지
- 데이터 백업
- 중요한 데이터를 복구 전에 백업해야함. 백업이 없는 상태에서 복구를 진행하면 문제가 있는 데이터를 복구 불가능하게 만들 수 있음
- 파일 시스템 umount
- 마운트된 파일 시스템에서 fsck를 실행하면 심각한 데이터 손상이 발생할 수 있음
- 복구를 진행할 디스크를 umount 상태로 유지
# umount /dev/sda1
3. 기본 사용법
3.1 fsck 명령어 형식
# fsck [옵션] [파일 시스템 또는 디스크 장치]
3.2 자주 사용하는 예제
- 특정 디스크 검사
# fsck /dev/sda1
fsck from util-linux 2.32.1
e2fsck 1.45.6 (20-Mar-2020)
ext2fs_open2: Bad magic number in super-block
fsck.ext2: Superblock invalid, trying backup blocks...
fsck.ext2: Bad magic number in super-block while trying to open /dev/sda1
The superblock could not be read or does not describe a valid ext2/ext3/ext4
filesystem. If the device is valid and it really contains an ext2/ext3/ext4
filesystem (and not swap or ufs or something else), then the superblock
is corrupt, and you might try running e2fsck with an alternate superblock:
e2fsck -b 8193 <device>
or
e2fsck -b 32768 <device>
- 모든 파일 시스템 검사
# fsck -A
fsck from util-linux 2.32.1
e2fsck 1.45.6 (20-Mar-2020)
/dev/sda2 is mounted.
e2fsck: Cannot continue, aborting.
- 자동으로 오류 수정
# fsck -y /dev/sda1
fsck from util-linux 2.32.1
e2fsck 1.45.6 (20-Mar-2020)
ext2fs_open2: Bad magic number in super-block
fsck.ext2: Superblock invalid, trying backup blocks...
fsck.ext2: Bad magic number in super-block while trying to open /dev/sda1
The superblock could not be read or does not describe a valid ext2/ext3/ext4
filesystem. If the device is valid and it really contains an ext2/ext3/ext4
filesystem (and not swap or ufs or something else), then the superblock
is corrupt, and you might try running e2fsck with an alternate superblock:
e2fsck -b 8193 <device>
or
e2fsck -b 32768 <device>
- 수정 없이 파일 시스템 상태만 확인
# fsck -n /dev/sda1
fsck from util-linux 2.32.1
e2fsck 1.45.6 (20-Mar-2020)
ext2fs_open2: Bad magic number in super-block
fsck.ext2: Superblock invalid, trying backup blocks...
fsck.ext2: Bad magic number in super-block while trying to open /dev/sda1
The superblock could not be read or does not describe a valid ext2/ext3/ext4
filesystem. If the device is valid and it really contains an ext2/ext3/ext4
filesystem (and not swap or ufs or something else), then the superblock
is corrupt, and you might try running e2fsck with an alternate superblock:
e2fsck -b 8193 <device>
or
e2fsck -b 32768 <device>
4. 주요 옵션
옵션 | 설명 |
-A | /etc/fstab 에 정의된 모든 파일 시스템을 검사함 |
-y | 사용자 확인 없이 모든 오류를 자동으로 수정함 |
-n | 수정하지 않고 파일 시스템 상태만 점검 |
-C | 진행 상황을 화면에 표시함 |
-t <fstype> | 특정 파일 시스템 유형만 검사 |
-r | 상호 작용 모드로 오류를 수정함(사용자가 직접 확인) |
5. 실행 과정과 결과 메시지
fsck 실행 시 파일 시스템 상태에 따라 5단계로 점검이 이루어짐
- 디렉터리 구조 확인
- 파일 연결 상태 확인
- 사용하지 않는 블록 탐지
- 디렉터리 정합성 점검
- 파일 크기 및 할당 상태 확인
결과 메시지
- CLEAN: 파일 시스템이 정상입니다.
- UNEXPECTED INCONSISTENCY: 파일 시스템에 문제가 발생했으며 복구가 필요합니다.
- FILE SYSTEM WAS MODIFIED: 파일 시스템이 수정되었음을 알립니다.
6. 긴급 복구 방법
6.1 싱글 유저 모드에서 복구
멀티 유저 환경에서는 fsck를 실행하지 마세요. 싱글 유저 모드로 전환 후 복구 작업을 진행합니다:
# init 1
# fsck /dev/sda1
6.2 루트 파일 시스템 복구
루트 파일 시스템(/)을 복구하려면 부팅 시점에서 실행해야합니다.
- GRUB에서 fsck 강제 실행
# fsck.mode=force fsck.repair=yes
- 긴급 모드로 부팅 후 수동 복구
# fsck -f /
7. 데이터 손실 방지 및 예방 방법
7.1 자동 검사 설정
파일 시스템이 마운트될 때 자동으로 검사되도록 설정할 수 있습니다. /etc/fstab에서 검사 우선순위를 설정하세요:
# vi /etc/fstab
--------------------------------------------
UUID=xxxx-xxxx-xxxx / ext4 defaults 1 1
7.2 정기 검사 주기 설정
tune2fs 명령어로 파일 시스템 검사 주기를 설정할 수 있습니다
# tune2fs -c 30 /dev/sda1 # 30번 부팅 후 검사
# tune2fs -i 7d /dev/sda1 # 7일마다 검사
8. 유의 사항
fsck는 파일 시스템의 무결성을 유지하는 강력한 도구지만, 데이터 손실 가능성이 있기 때문에 신중히 사용해야 합니다. 특히, 복구 전에 데이터 백업과 공지는 필수입니다. 정기적으로 파일 시스템을 점검하여 갑작스러운 오류로 인한 장애를 예방하세요.
'OS > Linux' 카테고리의 다른 글
[Linux] CentOS7.4 버전에서 Python 3.10.14 설치 및 Troubleshooting 매뉴얼 (0) | 2025.02.16 |
---|---|
[Linux] watch 명령어 : 실시간 모니터링 (0) | 2025.02.09 |
[Linux] smartctl 명령어 (0) | 2025.01.26 |
[Linux] dmidecode 명령어 (0) | 2025.01.25 |
[Linux] hwclock 명령어 (0) | 2025.01.23 |