리눅스 (Linux)2015. 12. 24. 23:53

리눅스 파일시스템 점검및 복구를 할 수 있는 명령어입니다.

리눅스 시스템이 부팅되는 과정에서 /etc/rc.d/rc.sysinit 스크립트가 자동으로 실행이 됩니다.
/etc/rc.d/rc.sysinit 스크립트를 확인해 보시면 파일시스템을 점검하는 명령어가 실행되는 단계가 있습니다. 따라서 시스템부팅시마다 파일시스템점검명령어가 실행됩니다.

e2fsck 의 종료코드
0 - 에러없이 정상적인 종료를 의미함.
1 - 파일시스템을 복구하였음을 의미함.
2 - 파일시스템이 복구되어 시스템이 재부팅되어야함을 의미함.
4 - 작업대상 파일시스템에 문제가 있으나 복구하지않고 그대로 두었음을 의미함.
8 - 실행에러를 의미함.
16 - 사용법(Usage)또는 문법(Syntax)에러를 의미함.
32 - e2fsck 작업이 사용자에 의해서 취소(Cancel)되었음을 의미함.
128 - 공유 라이브러리(Shared library) 에러를 의미함.

[주의사항]
e2fsck 명령어로 파일시스템을 점검하고 복구할 때에는 대상 파일시스템이 마운트되어있지않은 상태에서 실행하시기 바랍니다. 만약 마운트되어있는 상태에서 이 명령어를 사용하신다면 원하지않은 오류를 발생할 수도 있습니다.
마운트된 파일시스템을 e2fsck 로 점검 할때는 "WARNING!!!" 메세지가 나온다~

사용하기전에 파일시스템 정보부터 확인한다.
-----------------------------------------------------------------------------------
[root@dg69 /]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda2              4957220   2726600   1978804  58% /
/dev/sdb1             17654736   2672588  14085324  16% /backup
/dev/sda1               101086     17979     77888  19% /boot
none                    517292         0    517292   0% /dev/shm
/dev/sda5             11084636    178904  10342656   2% /home
------------------------------------------------------------------------------------
[root@dg69 /]# mount
/dev/sda2 on / type ext3 (rw)
none on /proc type proc (rw)
none on /sys type sysfs (rw)
none on /dev/pts type devpts (rw,gid=5,mode=620)
usbfs on /proc/bus/usb type usbfs (rw)
/dev/sdb1 on /backup type ext3 (rw)
/dev/sda1 on /boot type ext3 (rw)
none on /dev/shm type tmpfs (rw)
/dev/sda5 on /home type ext3 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/proc on /var/named/chroot/proc type none (rw,bind)
------------------------------------------------------------------------------------
[root@dg69 /]# fdisk /dev/sdb
The number of cylinders for this disk is set to 2233.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): p
Disk /dev/sdb: 18.3 GB, 18373206016 bytes
255 heads, 63 sectors/track, 2233 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1        2233    17936541   83  Linux
Command (m for help): q
------------------------------------------------------------------------------------
[root@dg69 /]# fdisk /dev/sda
The number of cylinders for this disk is set to 2233.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): p
Disk /dev/sda: 18.3 GB, 18373206016 bytes
255 heads, 63 sectors/track, 2233 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14         640     5036377+  83  Linux
/dev/sda3             641         831     1534207+  82  Linux swap
/dev/sda4             832        2233    11261565    5  Extended
/dev/sda5             832        2233    11261533+  83  Linux
Command (m for help): q
[root@dg69 /]# cat /etc/fstab
# This file is edited by fstab-sync - see 'man fstab-sync' for details
LABEL=/                 /                       ext3    defaults        1 1
LABEL=/backup1          /backup                 ext3    defaults        1 2
LABEL=/boot             /boot                   ext3    defaults        1 2
none                    /dev/pts                devpts  gid=5,mode=620  0 0
none                    /dev/shm                tmpfs   defaults        0 0
LABEL=/home1            /home                   ext3    defaults        1 2
none                    /proc                   proc    defaults        0 0
none                    /sys                    sysfs   defaults        0 0
LABEL=SWAP-sda3         swap                    swap    defaults        0 0
/dev/hda                /media/cdrom            auto    pamconsole,exec,noauto,managed 0 0
/dev/fd0                /media/floppy           auto    pamconsole,exec,noauto,managed 0 0
[root@dg69 /]#
------------------------------------------------------------------------------------
e2fsck 사용법
------------------------------------------------------------------------------------
[root@dg69 /]# e2fsck /dev/sdb1              <-----일반적인 특정시스템 점검복구
e2fsck 1.35 (28-Feb-2004)
/dev/sdb1 is mounted. 
WARNING!!!  Running e2fsck on a mounted filesystem may cause
SEVERE filesystem damage.
Do you really want to continue (y/n)? yes
/backup1: clean, 62/2244608 files, 738598/4484135 blocks
------------------------------------------------------------------------------------
[root@dg69 /]# e2fsck -f /dev/sdb1                   <-----강제적인 특정시스템 점검복구
e2fsck 1.35 (28-Feb-2004)
/dev/sdb1 is mounted. 
WARNING!!!  Running e2fsck on a mounted filesystem may cause
SEVERE filesystem damage.
Do you really want to continue (y/n)? yes
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/backup1: 62/2244608 files (16.1% non-contiguous), 738598/4484135 blocks
------------------------------------------------------------------------------------
[root@dg69 /]# e2fsck -j ext3 /dev/sdb1      <-----ext3(저널링)파일시스템 점검복구
e2fsck 1.35 (28-Feb-2004)
/dev/sdb1 is mounted. 
WARNING!!!  Running e2fsck on a mounted filesystem may cause
SEVERE filesystem damage.
Do you really want to continue (y/n)? yes
/backup1: clean, 62/2244608 files, 738598/4484135 blocks
--------------------------------------------------------------------------------------
[root@dg69 /]# e2fsck -fv /dev/sdb1     <-----강제적인 특정시스템 점검복구및 상세정보출력
e2fsck 1.35 (28-Feb-2004)
/dev/sdb1 is mounted. 
WARNING!!!  Running e2fsck on a mounted filesystem may cause
SEVERE filesystem damage.
Do you really want to continue (y/n)? yes
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
      62 inodes used (0%)
      10 non-contiguous inodes (16.1%)
         # of inodes with ind/dind/tind blocks: 27/17/0
  738598 blocks used (16%)
       0 bad blocks
       1 large file
      43 regular files
      10 directories
       0 character device files
       0 block device files
       0 fifos
       0 links
       0 symbolic links (0 fast symbolic links)
       0 sockets
--------
      53 files
-----------------------------------------------------------------------------------------

*점검 복구 자동 : e2fsck -p /dev/sdb1

*점검,복구시 묻는질문에 무조건 yes : e2fsck -y /dev/sdb1

*점검,복구시 묻는질문에 무조건 no : e2fsck -n /dev/sdb1

*버퍼캐쉬의 내용을 디스크에 저장하기 : e2fsck -F /dev/sdb1


파일시스템의 수퍼블록을 이용한 파일시스템 복구방법

리눅스의 파일시스템은 블록그룹(Block Group)이라는 것으로 기본구조를 이루고 있으며 모든 블록그룹의 맨 앞에는 수퍼블록이라는 것이 존재합니다. 블록그룹에 존재하는 모든 수퍼블록들은 동일한 정보를 가지고 있으며 파일시스템이 파괴되었을 경우에 이 정보를 이용하여 복구를 할 수 있도록 준비하고 있습니다.

- 첫번째 수퍼블록 : 1 번블록에 위치함.
- 두번째 수퍼블록 : 1 번블록 + 8192 번블록*1 = 8193 번째 블록에 위치함.
- 세번째 수퍼블록 : 1 번블록 + 8192 번블록*2 = 16385 번째 블록에 위치함.
- n 번째 수퍼블록 : 1 번블록 + 8192 번블록*n 번째블록에 위치함.

ex)  첫번째 수퍼블록이 깨졌기 때문에 일반적인 방법으로 복구가 불가능하게 된 경우로서 두번째 수퍼블록으로 복구를 하는 예
----------------------------------------------------------------------------------------
[root@file root]# e2fsck -b 8193 /dev/sda1
e2fsck 1.32 (09-Nov-2002)
/dev/sda1 is mounted.
WARNING!!! Running e2fsck on a mounted filesystem may cause
SEVERE filesystem damage.
Do you really want to continue (y/n)? yes
/boot was not cleanly unmounted, check forced.
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/boot: ***** FILE SYSTEM WAS MODIFIED *****
-------------------------------------------------------------------------------------------
세번째 수퍼블록을 이용한 복구작업 : # e2fsck -b 16385 /dev/sda1
네번째 수퍼블록을 이용한 복구작업 : # e2fsck -b 24577 /dev/sda1

'리눅스 (Linux)' 카테고리의 다른 글

리눅스 비트 확인 방법  (0) 2015.12.24
e2fsck 리눅스 파일시스템 점검 및 복구  (0) 2015.12.24
배드블럭 검사  (0) 2015.12.24
리눅스 기본 명령어  (0) 2015.12.24
openssl_1.0.2d 적용하기  (0) 2015.12.24
Posted by 랩퍼우