2013. 12. 17. 17:36

[Linux/Ubuntu 파일 시스템 관리] file system 검사하기

badblocks 명령으로 물리적 검사를 수행하고, fsck 명령을 통해 논리적인 오류를 찾을 수 있다.


다음은 bad block을 검사하는 과정을 나타낸다.

~$ sudo badblocks -v /dev/sdb5

Checking blocks 0 to 36488191

Checking for bad blocks (read-only test): done                                

Pass completed, 0 bad blocks found.

~$

-v 옵션을 사용하여 보다 많은 정보를 확인할 수 있다. badblock은 기본으로 안전한 read-only로 테스트한다. 비-파괴적인 read/write test도 수행할 수 있는데, 이는 매우 느리지만, device로 부터 data 손실 없이 실행할 수 있는 최고의 검사 방법이다. 이는 -n option을 추가하면 된다. -s는 진행 정보를 표시해 준다.

~$ sudo badblocks -vsn /dev/sda1

Checking for bad blocks in non-destructive read-write mode

From block 0 to 41933191

Checking for bad blocks (non-destructive read-write test)

Testing with random pattern: done

Pass completed, 0 bad blocks found.

~$

다음은 파괴적 read-write test로, "파티션의 정보를 모두 삭제"하는 기능을 가진다.

~$ sudo badblocks -vsw /dev/sda1 * 주의 : 파티션의 내용을 모두 삭제할 수 있음 *

Checking for bad blocks in read-write mode

From block 0 to 41933191

Testing with pattern 0xaa: done                                

Reading and comparing: done                                

Testing with pattern 0x55: done                                

Reading and comparing: done                                

Testing with pattern 0xff: ...


fsck는 mkfs와 유사하게 되어있다. 다음은 그 실행 예이다.

~$ sudo fsck /dev/sdb5

fsck from util-linux-ng 2.17.2

e2fsck 1.41.14 (22-Dec-2010)

/dev/sdb5 is mounted.  


WARNING!!!  The filesystem is mounted.   If you continue you ***WILL***

cause ***SEVERE*** filesystem damage.


Do you really want to continue (y/n)? yes


/dev/sdb5: recovering journal

Clearing orphaned inode 1180978 (uid=1000, gid=1000, mode=0100600, size=0)

Clearing orphaned inode 1177423 (uid=1000, gid=1000, mode=0100600, size=0)

Clearing orphaned inode 1180983 (uid=1000, gid=1000, mode=0100644, size=32768)

Clearing orphaned inode 1180976 (uid=1000, gid=1000, mode=0100600, size=812)

Clearing orphaned inode 1839241 (uid=0, gid=0, mode=0100644, size=26112)

Clearing orphaned inode 1839239 (uid=0, gid=0, mode=0100644, size=711308)

Clearing orphaned inode 1180926 (uid=1000, gid=1000, mode=0100600, size=4096)

Clearing orphaned inode 1180914 (uid=1000, gid=1000, mode=0100644, size=32768)

Clearing orphaned inode 1180913 (uid=1000, gid=1000, mode=0100600, size=412)

Clearing orphaned inode 1177516 (uid=1000, gid=1000, mode=0100600, size=1)

Clearing orphaned inode 1177517 (uid=1000, gid=1000, mode=0100644, size=1410)

/dev/sdb5 has gone 532 days without being checked, check forced.

Pass 1: Checking inodes, blocks, and sizes

Inodes that were part of a corrupted orphan linked list found.  Fix<y>? yes


Inode 1177423 was part of the orphaned inode list.  FIXED.

Inode 1180978 was part of the orphaned inode list.  FIXED.

Pass 2: Checking directory structure

Pass 3: Checking directory connectivity

Pass 4: Checking reference counts

Pass 5: Checking group summary information


/dev/sdb5: ***** FILE SYSTEM WAS MODIFIED *****

/dev/sdb5: ***** REBOOT LINUX *****

/dev/sdb5: 150528/2281104 files (0.1% non-contiguous), 833631/9122048 blocks

~$ sudo fsck /dev/sdb5

fsck from util-linux-ng 2.17.2

e2fsck 1.41.14 (22-Dec-2010)

/dev/sdb5 is mounted.  


WARNING!!!  The filesystem is mounted.   If you continue you ***WILL***

cause ***SEVERE*** filesystem damage.


Do you really want to continue (y/n)? yes


/dev/sdb5: clean, 150528/2281104 files, 833631/9122048 blocks

~$

다음과 같이 보통 -TV option이 사용되기도 한다. -T는 fsck 버전 표시를 생략하며, -V는 보다 많은 정보를 표시하도록 한다.

~$ sudo fsck -TV /dev/sdb5

[/sbin/fsck.ext4 (1) -- /] fsck.ext4 /dev/sdb5 

e2fsck 1.41.14 (22-Dec-2010)

/dev/sdb5 is mounted.  


WARNING!!!  The filesystem is mounted.   If you continue you ***WILL***

cause ***SEVERE*** filesystem damage.


Do you really want to continue (y/n)? yes


/dev/sdb5: recovering journal

Clearing orphaned inode 1180983 (uid=1000, gid=1000, mode=0100644, size=32768)

Clearing orphaned inode 1180976 (uid=1000, gid=1000, mode=0100600, size=812)

Clearing orphaned inode 1839241 (uid=0, gid=0, mode=0100644, size=26112)

Clearing orphaned inode 1839239 (uid=0, gid=0, mode=0100644, size=711308)

Clearing orphaned inode 1180926 (uid=1000, gid=1000, mode=0100600, size=4096)

Clearing orphaned inode 1180914 (uid=1000, gid=1000, mode=0100644, size=32768)

Clearing orphaned inode 1180913 (uid=1000, gid=1000, mode=0100600, size=412)

Clearing orphaned inode 1177516 (uid=1000, gid=1000, mode=0100600, size=1)

Clearing orphaned inode 1177517 (uid=1000, gid=1000, mode=0100644, size=1410)

/dev/sdb5 has gone 532 days without being checked, 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

Block bitmap differences:  +(264416--264432) -(581338--581353)

Fix<y>? yes


Free blocks count wrong for group #8 (14424, counted=14407).

Fix<y>? yes


Free blocks count wrong for group #17 (8675, counted=8691).

Fix<y>? yes


Free blocks count wrong (8288426, counted=8288425).

Fix<y>? yes


Inode bitmap differences:  -1177423 +1180977

Fix<y>? yes



/dev/sdb5: ***** FILE SYSTEM WAS MODIFIED *****

/dev/sdb5: ***** REBOOT LINUX *****

/dev/sdb5: 150528/2281104 files (0.1% non-contiguous), 833623/9122048 blocks

~$

-y 옵션을 사용하면, 질문에 대한 답변을 자동으로 해준다. (yes)

~$ sudo fsck -TVy /dev/sdb5

[/sbin/fsck.ext4 (1) -- /] fsck.ext4 -y /dev/sdb5 

e2fsck 1.41.14 (22-Dec-2010)

/dev/sdb5 is mounted.  


WARNING!!!  The filesystem is mounted.   If you continue you ***WILL***

cause ***SEVERE*** filesystem damage.


Do you really want to continue (y/n)? yes


/dev/sdb5: recovering journal

Clearing orphaned inode 1180983 (uid=1000, gid=1000, mode=0100644, size=32768)

Clearing orphaned inode 1180976 (uid=1000, gid=1000, mode=0100600, size=812)

Clearing orphaned inode 1839241 (uid=0, gid=0, mode=0100644, size=26112)

Clearing orphaned inode 1839239 (uid=0, gid=0, mode=0100644, size=711308)

Clearing orphaned inode 1180926 (uid=1000, gid=1000, mode=0100600, size=4096)

Clearing orphaned inode 1180914 (uid=1000, gid=1000, mode=0100644, size=32768)

Clearing orphaned inode 1180913 (uid=1000, gid=1000, mode=0100600, size=412)

Clearing orphaned inode 1177516 (uid=1000, gid=1000, mode=0100600, size=1)

Clearing orphaned inode 1177517 (uid=1000, gid=1000, mode=0100644, size=1410)

/dev/sdb5 has gone 532 days without being checked, 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

Block bitmap differences:  +(264416--264432) -(581338--581353)

Fix? yes


Free blocks count wrong for group #8 (14424, counted=14407).

Fix? yes


Free blocks count wrong for group #17 (8675, counted=8691).

Fix? yes


Free blocks count wrong (8288426, counted=8288425).

Fix? yes


Inode bitmap differences:  -1177423

Fix? yes



/dev/sdb5: ***** FILE SYSTEM WAS MODIFIED *****

/dev/sdb5: ***** REBOOT LINUX *****

/dev/sdb5: 150528/2281104 files (0.1% non-contiguous), 833623/9122048 blocks

~$