본문 바로가기

Engineering/__00. Linux

DISK 검사와 read only mount 조치 법

mount 상태가 아래와 같이 ro (read only)로 자주 변경 되는 경우나 ata, I/O error 같은 메시지가 자주 발생하는 경우 등

Storage 문제로 추정되는 상황이 발생하는 경우가 있다.

 

ex 1)

# mount
rootfs on / type rootfs (rw)
/dev/root on / type ext2 (rw)
/dev/sda1 on /mnt/kernel type msdos (rw,fmask=0022,dmask=0022,codepage=cp437)
/dev/sda2 on /xxx/conf type ext3 (rw,data=ordered)
/dev/sda3 on /usr/local type ext3 (rw,data=ordered)
none on /proc type proc (rw)
none on /sys type sysfs (rw)
none on /var/klog type tmpfs (rw)
/dev/ram1 on /etc/webadmin type tmpfs (rw)
/dev/sdb1 on /xxx/log type ext3 (ro,data=ordered)

 

ex 2)

May 25 21:16:34 kernel: end_request: I/O error, dev sda, sector 85439281

 

 

이 경우 논리적인 filesystem 이 손상되어 문제(SW)가 되는 경우가 있고 물리적 DISK(HW) 가 손상되어 발생할 수 있다.

대부분 논리적인 문제인데 HW 손상으로 오판하여 장비를 교체하는 등 막대한 비용손실을 발생하지 않도록 하기 위해

SW or HW 문제를 식별하여 처리하는 방법을 기술한다. 

 

먼저 Linux 에서 데이터를 저장장치(디스크)에 저장하는 동작을 이해하자.

 

리눅스에서 데이터는 HDD 와 같은 디스크에 바로 저장하지 않고 전부 시스템 메모리에서 그 작업이 이루어 진다.

작업의 대상이 되는 데이터는 메모리에 존재하기 때문에 저장하지 않는 한 디스크에 저장되지 않는다.

작업 도중 갑자기 전원이 나가거나 장애로 시스템이 다운되거나 리부팅되면 작업 중이던 메모리의 데이터는 유실될 것이다.

 

따라서 사용자가 작업 중이던 데이터를 메모리에서 디스크로 저장하는 작업을 프로그램이 주기적으로 자동으로 해주는데

이를 데이터 동기화라고 한다. 그런데 아직 자동으로 데이터 동기화가 되지 않은 경우 사용자가 직접 해 주어야 하고

이때 사용하는 명령이 sync 명령이다. 

즉, 디스크에 저장되어 있지 않은 메모리 버퍼의 데이터를 디스크에 저장하는 것을 sync 작업이라고 하고

sync 명령은 시스템 버퍼에 있는 데이터를 디스크에 저장하는 명령이다.

 

reboot 이나 halt, poweroff 등의 명령을 수행하면 시스템 종료 과정에 자동으로 sync 명령이 실행되는 이유이기도 하다.

 

만약 sync 작업이 없이 장비 전원 버튼을 눌러 장비를 끄면 아직 메모리에 있던 데이터는 디스크에 저장되지 못한 상태로

유실될 것이고 이는 데이터 손실을 발생할 수도, 파일시스템이 정리되지 못한 상태로 종료되어

결과적으로 파일시스템이 논리적으로 손상되는 결과로 나타날 수 있고, 이러한 일이 계속 반복되면 물리적으로 손상될 수도 있다.

(디스크 헤더가 안정화되지 않고 비정상 종료되고 디스크를 긁거나 큰 부담을 주어 물리적으로 손상되는 일이 발생할 수도 있다.)

 

따라서, 우리 제품도 poweroff 등의 명령 없이 장비의 전원 버튼을 그냥 끄면 안되는 것이다.

 

자, 그럼 이러저러한 이유들로 지금 디스크에 문제가 있는 것으로 의심되는 상황이라고 가정하자.

어떻게 판단하여 처리할 것인가....

 

다음과 같이 확인하도록 한다.

 

기본 Flow

 

1. 논리적 디스크 검사 및 오류 복원

    --> 문제가 없을 경우 2. 물리적 디스크 검사 수행

    --> 문제가 있을 경우 오류 수정을 시행하고 2. 물리적 디스크 검사 수행

 

2. 물리적 디스크 검사 및 조치

    --> 물리적 디스크 검사에서 문제가 있을 경우 (아래 확인 방법 참조) 디스크를 교체한다.

 

 

세부 확인 방법

 

1. 논리적 디스크 검사 및 오류 복원

 

    - 논리적 디스크 검사는 HW Raid Card를 사용하던 안하던 동일하다.

       1) 검사하고자 하는 device를 umount 상태로 변경한다.

              

 

 

  
 먼저 마운트 상태를 확인하고 디스크 검사하려는 장치가 mount 되어 있을 경우 umount 시켜 준다.


# mount
rootfs on / type rootfs (rw)
/dev/root on / type ext2 (rw)
/dev/sda1 on /mnt/kernel type msdos (rw,fmask=0022,dmask=0022,codepage=cp437)
/dev/sda2 on /xxx/conf type ext3 (rw,data=ordered)
/dev/sda3 on /usr/local type ext3 (rw,data=ordered)
/dev/sdb1 on /xxx/log type ext3 (rw,data=ordered)
none on /proc type proc (rw)
none on /sys type sysfs (rw)
none on /var/klog type tmpfs (rw)
/dev/ram1 on /etc/webadmin type tmpfs (rw)
# umount /dev/sdb1
# mount
rootfs on / type rootfs (rw)
/dev/root on / type ext2 (rw)
/dev/sda1 on /mnt/kernel type msdos (rw,fmask=0022,dmask=0022,codepage=cp437)
/dev/sda2 on /xxx/conf type ext3 (rw,data=ordered)
/dev/sda3 on /usr/local type ext3 (rw,data=ordered)
none on /proc type proc (rw)
none on /sys type sysfs (rw)
none on /var/klog type tmpfs (rw)
/dev/ram1 on /etc/webadmin type tmpfs (rw)



umount 된 것을 확인하였으면 다음과 같이 디스크 검사와 자동 복구를 수행한다.


# e2fsck -fyv /dev/sdb1
e2fsck 1.40.8 (13-Mar-2008)
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

    1034 inodes used (0.00%)
     270 non-contiguous inodes (26.1%)
         # of inodes with ind/dind/tind blocks: 220/6/0
 7779155 blocks used (1.59%)
       0 bad blocks
       1 large file

     965 regular files
      60 directories
       0 character device files
       0 block device files
       0 fifos
       0 links
       0 symbolic links (0 fast symbolic links)
       0 sockets
--------
    1025 files
#



위와 같이 모두 pass 된 경우 문제가 없는 것이고,
만약, 디스크 검사 중 문제가 발생하면 다음과 같이 문제를 검출하고 수정하는 과정이 보일 것이다.


ex)
node 2060353 is a unknown file type with mode 0137642 but it looks
like it is really a directory.
Fix? yes



문제 검출되어 수정한 경우에는 모두 pass 되는지 e2fsck 명령으로 다시 한번 확인한다.
이후 리부팅하여 사용하거나 물리적 디스크 검사도 수행한다.

 

 

 

2. 물리적 디스크 검사 및 조치

 

    smartctl 명령을 사용하여 물리적인 문제가 있는지 확인한다. 

    smartctl 명령은 mount 가 되어 있어도 상관 없다. umount 작업을 수행하지 않아도 된다.

 

    smartctl 명령은 물리적 디바이스를 검사하므로  sdb1, sdb2 와 같이 파티션을 구분하지 않고 sdb 와 같이 디스크 전체로 디바이스를 지정한다.

    만약 해당 디스크 장치가 raid 로 구성되어 있을 경우 raid volume 이 아닌 각 물리적 디바이스를 찾아 수행해야 한다.

 

    # smartctl --scan

    # smartctl -a /dev/sdb  

   

     (smartctl 명령이 설치되지 않았을 경우에는 apt install smartmontools 등의 명령으로 설치한다.)

 

Raid 구성이 아닌 경우에는 /dev/sdb 와 같이 디스크를 직접 지정하여 검사하면 되고
Raid 구성일 경우에는 --scan 옵션으로 Raid 연결 정보를 확인하여 DISK 를 검사한다.


다음과 같이 storage vendor/model 정보가 출력되지 않고 raid vendor 가 출력되면 raid 로 구성되어 있는 장치이다.


(ex, Storage Vendor/model : Western Digital, HGST, Seagate, SATADOM 등)


# smartctl -i /dev/sdb
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-2.6.20] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Vendor:               LSI
Product:              MR9271-8i  (or 9341 or 9211 등)
Revision:             3.45
User Capacity:        1,999,844,147,200 bytes [1.99 TB]
Logical block size:   512 bytes
Logical Unit id:      0x600605b00a6b78402924de2922967328
Serial number:        002873962229de242940786b0ab00506
Device type:          disk
Local Time is:        Thu Apr 14 11:38:19 2022 KST
SMART support is:     Unavailable - device lacks SMART capability.


# smartctl --scan
/dev/hda -d ata # /dev/hda, ATA device
/dev/hdb -d ata # /dev/hdb, ATA device
/dev/hdc -d ata # /dev/hdc, ATA device
/dev/sda -d scsi # /dev/sda, SCSI device
/dev/sdb -d scsi # /dev/sdb, SCSI device
/dev/sdc -d scsi # /dev/sdc, SCSI device
/dev/bus/6 -d megaraid,0 # /dev/bus/6 [megaraid_disk_00], SCSI device
/dev/bus/6 -d megaraid,1 # /dev/bus/6 [megaraid_disk_01], SCSI device

 
 

# smartctl -a /dev/bus/6 -d megaraid,0
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-2.6.20] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org

/dev/bus/6 [megaraid_disk_00] [SAT]: Device open changed type from 'megaraid,0' to 'sat+megaraid,0'
=== START OF INFORMATION SECTION ===
Device Model:     HGST HUS722T1TALA604
Serial Number:    WCC6M3VKVJS0
LU WWN Device Id: 5 0014ee 267dd5a3a
Firmware Version: RAGNWA09
User Capacity:    1,000,204,886,016 bytes [1.00 TB]
Sector Size:      512 bytes logical/physical
Rotation Rate:    7200 rpm
Device is:        Not in smartctl database [for details use: -P showall]
ATA Version is:   ACS-3 (unknown minor revision code: 0x006d)
SATA Version is:  SATA 3.1, 6.0 Gb/s (current: 6.0 Gb/s)
Local Time is:    Wed Jun 30 18:00:39 2021 KST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED
Warning: This result is based on an Attribute check.

General SMART Values:
Offline data collection status:  (0x00) Offline data collection activity
                                        was never started.
                                        Auto Offline Data Collection: Disabled.
Self-test execution status:      (   0) The previous self-test routine completed
                                        without error or no self-test has ever
                                        been run.
Total time to complete Offline
data collection:                (    0) seconds.
Offline data collection
capabilities:                    (0x7b) SMART execute Offline immediate.
                                        Auto Offline data collection on/off support.
                                        Suspend Offline collection upon new
                                        command.
                                        Offline surface scan supported.
                                        Self-test supported.
                                        Conveyance Self-test supported.
                                        Selective Self-test supported.
SMART capabilities:            (0x0003) Saves SMART data before entering
                                        power-saving mode.
                                        Supports SMART auto save timer.
Error logging capability:        (0x01) Error logging supported.
                                        General Purpose Logging supported.
Short self-test routine
recommended polling time:        (   2) minutes.
Extended self-test routine
recommended polling time:        ( 109) minutes.
Conveyance self-test routine
recommended polling time:        (   5) minutes.
SCT capabilities:              (0x603d) SCT Status supported.
                                        SCT Error Recovery Control supported.
                                        SCT Feature Control supported.
                                        SCT Data Table supported.

SMART Attributes Data Structure revision number: 16
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  1 Raw_Read_Error_Rate     0x002f   200   200   051    Pre-fail  Always       -       0
  3 Spin_Up_Time            0x0027   140   140   021    Pre-fail  Always       -       3958
  4 Start_Stop_Count        0x0032   100   100   000    Old_age   Always       -       41
  5 Reallocated_Sector_Ct   0x0033   200   200   140    Pre-fail  Always       -       0
  7 Seek_Error_Rate         0x002e   100   200   000    Old_age   Always       -       0
  9 Power_On_Hours          0x0032   093   093   000    Old_age   Always       -       5794
 10 Spin_Retry_Count        0x0032   100   253   000    Old_age   Always       -       0
 11 Calibration_Retry_Count 0x0032   100   253   000    Old_age   Always       -       0
 12 Power_Cycle_Count       0x0032   100   100   000    Old_age   Always       -       41
 16 Unknown_Attribute       0x0022   001   199   000    Old_age   Always       -       73169337804
183 Runtime_Bad_Block       0x0032   100   100   000    Old_age   Always       -       0
192 Power-Off_Retract_Count 0x0032   200   200   000    Old_age   Always       -       38
193 Load_Cycle_Count        0x0032   200   200   000    Old_age   Always       -       19
194 Temperature_Celsius     0x0022   108   104   000    Old_age   Always       -       35
196 Reallocated_Event_Count 0x0032   200   200   000    Old_age   Always       -       0
197 Current_Pending_Sector  0x0032   200   200   000    Old_age   Always       -       0
198 Offline_Uncorrectable   0x0030   100   253   000    Old_age   Offline      -       0
199 UDMA_CRC_Error_Count    0x0032   200   200   000    Old_age   Always       -       0
200 Multi_Zone_Error_Rate   0x0008   100   253   000    Old_age   Offline      -       0

SMART Error Log Version: 1
No Errors Logged

SMART Self-test log structure revision number 1
No self-tests have been logged.  [To run self-tests, use: smartctl -t]


SMART Selective self-test log data structure revision number 1
 SPAN  MIN_LBA  MAX_LBA  CURRENT_TEST_STATUS
    1        0        0  Not_testing
    2        0        0  Not_testing
    3        0        0  Not_testing
    4        0        0  Not_testing
    5        0        0  Not_testing
Selective self-test flags (0x0):
  After scanning selected spans, do NOT read-scan remainder of disk.
If Selective self-test is pending on power-up, resume after 0 minute delay.



#

r

검사 결과 중 굵은 글씨체의 내용을 중심으로 확인한다.

이 중 RAW_VALUE 값이 THRESH(threshold) 값을 넘어서면 물리적인 문제가 있을 수 있으므로 디스크 교체를 수행한다.

민감한 환경이라면 해당 값이 0이 아닌 경우, 주기적으로 값의 증가 여부를 확인하고 증가가 확인되면 미리 교체를 권장한다. 

 

다음 Power-Off_Retract_Count  항목은 디스크를 정상 종료하지 않고 전원을 뽑는 등 비정상 종료된 경우를 의미한다.

이 값이 0이 아니라면 사용에 주의하고 앞에서도 언급하였 듯이 sync, poweroff 수행 후 종료하도록 한다.

192 Power-Off_Retract_Count 0x0032   200   200   000    Old_age   Always       -       38

 

 

주1) 1.논리적 디스크 검사 및 오류 복원 방법으로 검사 한 후에는 # sync 명령 및 # reboot 명령으로 리부팅 후 사용한다.

 

주2)  smartctl 명령은 HDD 뿐 아니라 CF, SATADOM, SSD 등 모두 사용할 수 있다.

       단 해당 장치가 SMART 기능을 지원해야 한다.

 

주3) SMART 정보는 장치 내에 저장되는 것으로 format 등을 수행해도 장치에 남아 있다.

 

주4) smartctl 검사 결과로 나오는 항목들은 저장장치 제조사 및 모델 마다 상이하다.

      (HDD/SSD 의 차이에 의한 것도 있음)

 

주5) Seagate HDD 는 smartctl RWA_VALUE 결과 값이 매우 크게 이상하게 읽힌다.

      기본 명령어에 다음 옵션을 추가한다.

      # smartctl -a /dev/sdb --> # smartctl -a -v 1,raw48:54 /dev/sdb

 

주6) 저장장치를 쓰는데 이상이 감지되면 Linux OS 에서는 mount rw -> ro (read only) 로 변경한다.

      이 경우 이미 기술한 디스크 검사를 수행하여 오류를 복구한다.

      만약 급히 rw 로 다시 마운트를 하고자 하면 다음 명령을 수행한다.

 

 

# mount
rootfs on / type rootfs (rw)
/dev/root on / type ext2 (rw)
/dev/sda3 on /usr/local type ext3 (ro,data=ordered)
/dev/sdb1 on /xxx/log type ext3 (rw,data=ordered)
none on /proc type proc (rw)
none on /sys type sysfs (rw)
none on /var/klog type tmpfs (rw)
/dev/ram1 on /etc/webadmin type tmpfs (rw)
/dev/sdc1 on /xxx/backup type ext3 (rw,data=ordered)
none on /etc/flook type ramfs (rw)
none on /dev/pts type devpts (rw)


# mount -o remount,rw /dev/sda3


# mount
rootfs on / type rootfs (rw)
/dev/root on / type ext2 (rw)
/dev/sda3 on /usr/local type ext3 (rw,data=ordered)
/dev/sdb1 on /xxx/log type ext3 (rw,data=ordered)
none on /proc type proc (rw)
none on /sys type sysfs (rw)
none on /var/klog type tmpfs (rw)
/dev/ram1 on /etc/webadmin type tmpfs (rw)
/dev/sdc1 on /xxx/backup type ext3 (rw,data=ordered)
none on /etc/flook type ramfs (rw)
none on /dev/pts type devpts (rw)
#

 

     

 

 

'Engineering > __00. Linux' 카테고리의 다른 글

evtest - Input device event monitor and query tool  (0) 2024.02.21
nc - arbitrary TCP and UDP connections and listens  (0) 2023.03.15
[터미널 단축기]  (0) 2022.10.26
open 된 서비스 찾기 (lsof)  (0) 2021.12.07
[Sendmail/Postfix]  (0) 2021.08.31