2015年6月17日水曜日

うるう秒(閏秒)の際にcronが二重に実行されるかも?という都市伝説(?)について

今年のうるう秒調整(2015年7月1日午前9:00日本時間)実施まで、あと二週間に迫りましたが、 うるう秒の際に cron ジョブが二重に実行されるかも?という都市伝説(?)を耳にしたことがあるので、CentOS 6 に関して調べてみました。
そもそも /var/log/cron を見渡すと、どれもこれも毎分 :01 秒を狙っている感じです。
[root@hoge ~]# tail /var/log/cron
Jun 16 00:10:01 hoge CROND[9508]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jun 16 00:11:01 hoge CROND[9546]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jun 17 01:33:31 hoge crond[2699]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 72% if used.)
Jun 17 01:33:31 hoge crond[2699]: (CRON) INFO (running with inotify support)
Jun 17 01:34:01 hoge CROND[5736]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jun 17 01:35:01 hoge CROND[6163]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jun 17 01:36:01 hoge CROND[6197]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jun 17 01:37:01 hoge CROND[6223]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jun 17 01:38:01 hoge CROND[6254]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jun 17 01:39:01 hoge CROND[6736]: (root) CMD (/usr/lib64/sa/sa1 1 1)
それで検索してみますと、cronie について調べている先人の方がおられ、やはり毎分 :01 秒を狙ってスリープしているようです。
http://moro-archive.hatenablog.com/entry/2015/03/17/011823
なぜ、:01 秒狙いなのか?ソース上にはコメントないみたいですが、もしかしたら、うるう秒のことが視野に入っているということなのかも。

というわけで、あっけなく調査終了です。こういった実装なら、うるう秒の際に cron ジョブが二重に実行されるということは、なさそうです。

Linux カーネルのうるう秒調整は、:59 秒を 2 回続ける(ミリ秒単位だと ... :59.998 , :59.999 , :59.000 ... と進める)という実装になってますが、それって cron も意識しているのかもしれませんね。

■関連記事
2017年1月1日の うるう秒 調整時の ntpd の挙動観測データ (次回投稿するつもり)
2015年7月1日の うるう秒 調整時の ntpd の挙動観測データ
2012年7月1日の うるう秒 調整時の ntpd の挙動観測データ
ntpd を1日止めた場合のズレはどの程度か?

2015年6月15日月曜日

中古 HDD の初期確認

記憶する限り初めて、中古 HDD を購入した(中古 SSD は買ったことありましたが)のですが、Linux 上での初期確認ポイントについて、備忘録です。
CentOS 7.1 で操作しています。
■関連記事 中古 HDD の初期確認、2個目(2015年10月)

まず、とりあえず、認識されなれば、そこで終わりですが、
[    3.239373] scsi 3:0:0:0: Direct-Access     ATA      SEAGATE ST310003 NA02 PQ: 0 ANSI: 5
[    3.239662] sd 3:0:0:0: [sdd] 1953525168 512-byte logical blocks: (1.00 TB/931 GiB)
[    3.240247] sd 3:0:0:0: [sdd] Write Protect is off
[    3.240338] sd 3:0:0:0: [sdd] Mode Sense: 00 3a 00 00
[    3.240477] sd 3:0:0:0: [sdd] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[    3.260270] sd 3:0:0:0: [sdd] Attached SCSI disk
これは OK でした。ただし、しばらく試運転していて、どうも遅いと思ったら、Write cache が disabled になっていることに気がつきました。どうやら、このディスクは、RAID コントローラ配下で利用されていたのかもしれません。LSI とかの RAID コントローラ配下の場合、デフォルトでは HDD のキャッシュが off にされていることが多いですから。
キャッシュを enable にするには、hdparm -W1 コマンドを使えばいいです。
[root@hoge ~]# hdparm -W1 /dev/sdd

/dev/sdd:
 setting drive write-caching to 1 (on)
 write-caching =  1 (on)
[root@hoge ~]# hdparm -i /dev/sdd
dev/sdd:

 Model=SEAGATE ST31000340NS, FwRev=NA02, SerialNo=xxxxxxxx
 Config={ HardSect NotMFM HdSw>15uSec Fixed DTR>10Mbs RotSpdTol>.5% }
 RawCHS=16383/16/63, TrkSize=0, SectSize=0, ECCbytes=4
 BuffType=unknown, BuffSize=unknown, MaxMultSect=16, MultSect=off
 CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=1953525168
 IORDY=on/off, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120}
 PIO modes:  pio0 pio1 pio2 pio3 pio4 
 DMA modes:  mdma0 mdma1 mdma2 
 UDMA modes: udma0 udma1 udma2 udma3 udma4 udma5 *udma6 
 AdvancedPM=no WriteCache=enabled
 Drive conforms to: unknown:  ATA/ATAPI-4,5,6,7

 * signifies the current active mode

次に S.M.A.R.T. の確認です。
[root@hoge ~]# smartctl -a /dev/sdd
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.10.0-229.4.2.el7.x86_64] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Device Model:     SEAGATE ST31000340NS
Serial Number:    xxxxxxxx
LU WWN Device Id: 5 000c50 yyyyyyyy
Firmware Version: NA02
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:   ATA8-ACS T13/1699-D revision 4
SATA Version is:  SATA 2.6, 3.0 Gb/s
Local Time is:    Mon Jun 15 18:09:51 2015 JST
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

General SMART Values:
Offline data collection status:  (0x82) Offline data collection activity
     was completed without error.
     Auto Offline Data Collection: Enabled.
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:   (  634) 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:   (   1) minutes.
Extended self-test routine
recommended polling time:   ( 227) minutes.
Conveyance self-test routine
recommended polling time:   (   2) minutes.
SCT capabilities:         (0x103f) SCT Status supported.
     SCT Error Recovery Control supported.
     SCT Feature Control supported.
     SCT Data Table supported.

SMART Attributes Data Structure revision number: 10
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  1 Raw_Read_Error_Rate     0x000f   084   063   044    Pre-fail  Always       -       237886154
  3 Spin_Up_Time            0x0003   099   091   000    Pre-fail  Always       -       0
  4 Start_Stop_Count        0x0032   100   100   020    Old_age   Always       -       179
  5 Reallocated_Sector_Ct   0x0033   100   100   036    Pre-fail  Always       -       0
  7 Seek_Error_Rate         0x000f   076   060   030    Pre-fail  Always       -       13038515776
  9 Power_On_Hours          0x0032   048   048   000    Old_age   Always       -       45906
 10 Spin_Retry_Count        0x0013   100   100   097    Pre-fail  Always       -       0
 12 Power_Cycle_Count       0x0032   100   037   020    Old_age   Always       -       132
184 End-to-End_Error        0x0032   100   100   099    Old_age   Always       -       0
187 Reported_Uncorrect      0x0032   100   100   000    Old_age   Always       -       0
188 Command_Timeout         0x0032   100   100   000    Old_age   Always       -       0
189 High_Fly_Writes         0x003a   100   100   000    Old_age   Always       -       0
190 Airflow_Temperature_Cel 0x0022   062   055   045    Old_age   Always       -       38 (Min/Max 27/38)
194 Temperature_Celsius     0x0022   038   045   000    Old_age   Always       -       38 (0 13 0 0 0)
195 Hardware_ECC_Recovered  0x001a   051   047   000    Old_age   Always       -       237886154
197 Current_Pending_Sector  0x0012   100   100   000    Old_age   Always       -       0
198 Offline_Uncorrectable   0x0010   100   100   000    Old_age   Offline      -       0
199 UDMA_CRC_Error_Count    0x003e   200   200   000    Old_age   Always       -       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.
不良セクタの有無なども勿論気になるところですが、まずは運用年数を確認です。9 Power_On_Hours の値が 45906 なので、
[root@hoge ~]# echo "45906 / 24 / 365" | bc -l
5.24041095890410958904
だいたい、きっちり 5年 ですね。うーん、プロの仕業でしょうか。ガタが来る前にリフレッシュですかね。
ちなみに HGST だと、ラベルに製造年月が書いていますが、今回入手した Seagate 製品(Barracuda ES.2)のラベルには記載ありませんでした。2015-06-20追記、後日よく見てみたら、Date Code: 09364 と記載ありました。http://www.j-pro.info/remake/sgcalc.php こちらのツールによると 03/2009 を意味するそうです。というわけで6歳でした。

そして、不良セクタ関係の項目(5 Reallocated_Sector_Ct、197 Current_Pending_Sector など)は、どれもゼロでした。
エラーログも無し(No Errors Logged)です。

なかなか、良さげな個体を安価に入手できたように思います。

なお、新品であれば、全セクタ検査などしてから使い始めるのが私の慣例ですが、中古であるし、ZFS で冗長化して使うので、そのまま投入して使い倒すのみです。返品できないし、ベンダの保証も無いですから。


2015-06-20追記
初期確認では、S.M.A.R.T. は全く問題なさそうな状態でしたが、実際に RAIDZ に組み込んでみた(故障した HDD と zpool replace した)ところ、resilver(ZFS の用語でリビルドのこと)は問題なく成功したものの、そのあと更に、zpool scrub(整合性チェック)を行なったら、ATA bus error が多発しました。
smartctl -A の値を確認したところ、197 Current_Pending_Sector および 198 Offline_Uncorrectable の値が 6 になってました。つまり不良セクタが生じたことを示唆していました。過去の経験から、この程度ならまだ諦めることはなく、不良セクタの LBA 番号を確認して、そのセクタにゼロ書き込みすることで、代替セクタへの切り替えを促すことができると思われました。実際、手間はかかりましたが、うまく行きました。
次が、不良セクタの処置を終えたあとの smartctl -a の出力です。
[root@hoge ~]# smartctl -a /dev/sdd
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.10.0-229.4.2.el7.x86_64] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Device Model:     SEAGATE ST31000340NS
Serial Number:    xxxxxxxx
LU WWN Device Id: 5 000c50 yyyyyyyyy
Firmware Version: NA02
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:   ATA8-ACS T13/1699-D revision 4
SATA Version is:  SATA 2.6, 3.0 Gb/s
Local Time is:    Fri Jun 19 17:36:23 2015 JST
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

General SMART Values:
Offline data collection status:  (0x82) Offline data collection activity
     was completed without error.
     Auto Offline Data Collection: Enabled.
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:   (  634) 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:   (   1) minutes.
Extended self-test routine
recommended polling time:   ( 227) minutes.
Conveyance self-test routine
recommended polling time:   (   2) minutes.
SCT capabilities:         (0x103f) SCT Status supported.
     SCT Error Recovery Control supported.
     SCT Feature Control supported.
     SCT Data Table supported.

SMART Attributes Data Structure revision number: 10
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  1 Raw_Read_Error_Rate     0x000f   079   047   044    Pre-fail  Always       -       87683421
  3 Spin_Up_Time            0x0003   099   091   000    Pre-fail  Always       -       0
  4 Start_Stop_Count        0x0032   100   100   020    Old_age   Always       -       183
  5 Reallocated_Sector_Ct   0x0033   082   082   036    Pre-fail  Always       -       388
  7 Seek_Error_Rate         0x000f   076   060   030    Pre-fail  Always       -       13040071396
  9 Power_On_Hours          0x0032   048   048   000    Old_age   Always       -       46000
 10 Spin_Retry_Count        0x0013   100   100   097    Pre-fail  Always       -       0
 12 Power_Cycle_Count       0x0032   100   037   020    Old_age   Always       -       136
184 End-to-End_Error        0x0032   100   100   099    Old_age   Always       -       0
187 Reported_Uncorrect      0x0032   001   001   000    Old_age   Always       -       507
188 Command_Timeout         0x0032   100   100   000    Old_age   Always       -       0
189 High_Fly_Writes         0x003a   100   100   000    Old_age   Always       -       0
190 Airflow_Temperature_Cel 0x0022   065   055   045    Old_age   Always       -       35 (Min/Max 33/38)
194 Temperature_Celsius     0x0022   035   045   000    Old_age   Always       -       35 (0 13 0 0 0)
195 Hardware_ECC_Recovered  0x001a   052   041   000    Old_age   Always       -       87683421
197 Current_Pending_Sector  0x0012   100   100   000    Old_age   Always       -       0
198 Offline_Uncorrectable   0x0010   100   100   000    Old_age   Offline      -       0
199 UDMA_CRC_Error_Count    0x003e   200   200   000    Old_age   Always       -       0

SMART Error Log Version: 1
ATA Error Count: 244 (device log contains only the most recent five errors)
 CR = Command Register [HEX]
 FR = Features Register [HEX]
 SC = Sector Count Register [HEX]
 SN = Sector Number Register [HEX]
 CL = Cylinder Low Register [HEX]
 CH = Cylinder High Register [HEX]
 DH = Device/Head Register [HEX]
 DC = Device Command Register [HEX]
 ER = Error register [HEX]
 ST = Status register [HEX]
Powered_Up_Time is measured from power on, and printed as
DDd+hh:mm:SS.sss where DD=days, hh=hours, mm=minutes,
SS=sec, and sss=millisec. It "wraps" after 49.710 days.

Error 244 occurred at disk power-on lifetime: 45952 hours (1914 days + 16 hours)
  When the command that caused the error occurred, the device was active or idle.

  After command completion occurred, registers were:
  ER ST SC SN CL CH DH
  -- -- -- -- -- -- --
  40 51 00 ff ff ff 0f  Error: UNC at LBA = 0x0fffffff = 268435455

  Commands leading to the command that caused the error were:
  CR FR SC SN CL CH DH DC   Powered_Up_Time  Command/Feature_Name
  -- -- -- -- -- -- -- --  ----------------  --------------------
  60 00 08 ff ff ff 4f 00      03:07:15.069  READ FPDMA QUEUED
  ec 00 01 00 00 00 00 00      03:07:15.067  IDENTIFY DEVICE
  27 00 00 00 00 00 e0 00      03:07:15.065  READ NATIVE MAX ADDRESS EXT [OBS-ACS-3]
  ec 00 00 00 00 00 a0 00      03:07:15.064  IDENTIFY DEVICE
  ef 03 46 00 00 00 a0 00      03:07:15.064  SET FEATURES [Set transfer mode]

Error 243 occurred at disk power-on lifetime: 45952 hours (1914 days + 16 hours)
  When the command that caused the error occurred, the device was active or idle.

  After command completion occurred, registers were:
  ER ST SC SN CL CH DH
  -- -- -- -- -- -- --
  40 51 00 ff ff ff 0f  Error: UNC at LBA = 0x0fffffff = 268435455

  Commands leading to the command that caused the error were:
  CR FR SC SN CL CH DH DC   Powered_Up_Time  Command/Feature_Name
  -- -- -- -- -- -- -- --  ----------------  --------------------
  60 00 08 ff ff ff 4f 00      03:07:11.956  READ FPDMA QUEUED
  b0 d5 01 09 4f c2 00 00      03:06:53.011  SMART READ LOG
  b0 d5 01 06 4f c2 00 00      03:06:52.963  SMART READ LOG
  b0 d5 01 01 4f c2 00 00      03:06:52.954  SMART READ LOG
  b0 d5 01 00 4f c2 00 00      03:06:52.954  SMART READ LOG

Error 242 occurred at disk power-on lifetime: 45952 hours (1914 days + 16 hours)
  When the command that caused the error occurred, the device was active or idle.

  After command completion occurred, registers were:
  ER ST SC SN CL CH DH
  -- -- -- -- -- -- --
  40 51 00 ff ff ff 0f  Error: UNC at LBA = 0x0fffffff = 268435455

  Commands leading to the command that caused the error were:
  CR FR SC SN CL CH DH DC   Powered_Up_Time  Command/Feature_Name
  -- -- -- -- -- -- -- --  ----------------  --------------------
  60 00 08 ff ff ff 4f 00      03:04:27.167  READ FPDMA QUEUED
  27 00 00 00 00 00 e0 00      03:04:27.166  READ NATIVE MAX ADDRESS EXT [OBS-ACS-3]
  ec 00 00 00 00 00 a0 00      03:04:27.164  IDENTIFY DEVICE
  ef 03 46 00 00 00 a0 00      03:04:27.164  SET FEATURES [Set transfer mode]
  27 00 00 00 00 00 e0 00      03:04:27.163  READ NATIVE MAX ADDRESS EXT [OBS-ACS-3]

Error 241 occurred at disk power-on lifetime: 45952 hours (1914 days + 16 hours)
  When the command that caused the error occurred, the device was active or idle.

  After command completion occurred, registers were:
  ER ST SC SN CL CH DH
  -- -- -- -- -- -- --
  40 51 00 ff ff ff 0f  Error: UNC at LBA = 0x0fffffff = 268435455

  Commands leading to the command that caused the error were:
  CR FR SC SN CL CH DH DC   Powered_Up_Time  Command/Feature_Name
  -- -- -- -- -- -- -- --  ----------------  --------------------
  60 00 08 ff ff ff 4f 00      03:04:24.106  READ FPDMA QUEUED
  b0 d5 01 09 4f c2 00 00      03:04:03.645  SMART READ LOG
  b0 d5 01 06 4f c2 00 00      03:04:03.597  SMART READ LOG
  b0 d5 01 01 4f c2 00 00      03:04:03.588  SMART READ LOG
  b0 d5 01 00 4f c2 00 00      03:04:03.588  SMART READ LOG

Error 240 occurred at disk power-on lifetime: 45952 hours (1914 days + 16 hours)
  When the command that caused the error occurred, the device was active or idle.

  After command completion occurred, registers were:
  ER ST SC SN CL CH DH
  -- -- -- -- -- -- --
  40 51 00 ff ff ff 0f  Error: UNC at LBA = 0x0fffffff = 268435455

  Commands leading to the command that caused the error were:
  CR FR SC SN CL CH DH DC   Powered_Up_Time  Command/Feature_Name
  -- -- -- -- -- -- -- --  ----------------  --------------------
  60 00 08 ff ff ff 4f 00      02:59:16.039  READ FPDMA QUEUED
  27 00 00 00 00 00 e0 00      02:59:16.037  READ NATIVE MAX ADDRESS EXT [OBS-ACS-3]
  ec 00 00 00 00 00 a0 00      02:59:16.035  IDENTIFY DEVICE
  ef 03 46 00 00 00 a0 00      02:59:16.035  SET FEATURES [Set transfer mode]
  27 00 00 00 00 00 e0 00      02:59:16.034  READ NATIVE MAX ADDRESS EXT [OBS-ACS-3]

SMART Self-test log structure revision number 1
Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error
# 1  Selective offline   Completed without error       00%     45955         -
# 2  Short offline       Completed without error       00%     45953         -
# 3  Selective offline   Completed: read failure       90%     45953         914942610
# 4  Short offline       Completed without error       00%     45953         -
# 5  Selective offline   Completed: read failure       90%     45953         914941117
# 6  Short offline       Completed without error       00%     45953         -
# 7  Selective offline   Completed: read failure       90%     45953         914938130
# 8  Short offline       Completed without error       00%     45953         -
# 9  Selective offline   Completed: read failure       90%     45953         914936637
#10  Short offline       Completed without error       00%     45953         -
#11  Selective offline   Completed: read failure       90%     45953         914925917
#12  Short offline       Completed without error       00%     45953         -
#13  Selective offline   Completed: read failure       90%     45953         914924423
#14  Short offline       Completed without error       00%     45953         -
#15  Selective offline   Completed: read failure       90%     45953         914916690
#16  Selective offline   Completed: read failure       90%     45953         914916690
#17  Short offline       Completed without error       00%     45953         -
#18  Selective offline   Completed: read failure       90%     45953         914896743
#19  Short offline       Completed without error       00%     45953         -
#20  Selective offline   Completed: read failure       90%     45953         914895250
#21  Short offline       Completed without error       00%     45953         -

SMART Selective self-test log data structure revision number 1
 SPAN    MIN_LBA     MAX_LBA  CURRENT_TEST_STATUS
    1  914940000  1953525167  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.
5 Reallocated_Sector_Ct の VALUE が 100 から 082 に低下しており、代替セクタが使われたことを示唆しています。

不良セクタの除去は、次のような手順で行いました。
[root@hoge ~]# smartctl -t long /dev/sdd
               ※(1) long テスト実行
...
[root@hoge ~]# smartctl -a /dev/sdd
               ※(2) long テストの終了確認(終るまで繰り返し確認)
...
[root@hoge ~]# dd if=/dev/zero of=/dev/sdd bs=4096 seek=$((LBA_of_first_errorの値/8)) count=1
               ※(3) 不良セクタへのゼロ書き込み
...
[root@hoge ~]# smartctl -t short /dev/sdd
               ※(4) short テスト実行
...
[root@hoge ~]# smartctl -a /dev/sdd
               ※(5) short テストの終了確認(終るまで繰り返し確認)
...
[root@hoge ~]# smartctl -t select,LBA_of_first_errorの値-max /dev/sdd
               ※(6) 不良セクタが発見された位置から続きのテスト(selectモード)を実行
...
[root@hoge ~]# smartctl -a /dev/sdd
               ※(7) select テストの終了確認(終るまで繰り返し確認)
...
※以降は、LBA_of_first_error が無くなるまで、手順 (3) から (7) まで繰り返し
コツがいくつかありますので以下補足です。

手順 (3) で、4096 バイト境界で書き込む必要がありました。表面上は 512n な HDD ですが、もしかしたら本当の物理セクタサイズは 4096 なのかも?(憶測です)。
■関連記事 物理セクタサイズが 4K bytes のディスクで不良セクタが発生した事例と処置

手順 (4) を行わないと、手順 (3) でゼロ書き込みした箇所が正常化されたとみなされないようでした。short テストを行わずに select テストへ進むと、再度同じ LBA が LBA_of_first_error に出てきてしまいます。上の smartctl 出力の紫色の箇所のことです。

手順 (6) の select モードの代わりに、再び long テストでも可ですが、当然セクタゼロ(LBA番号 0)から再検査することになり、所要時間が倍増してしまいます。


2015-07-05追記
その後、2週間経ちましたが、ひとまずは安定した様子で、エラーが出なくなりました。

2015-07-25追記
使用開始してから1ヵ月経ちましたが、その後は ATA bus error が出ることはなく、安定して使えています。細かく見ると、5 Reallocated_Sector_Ct が +1 増えています。
[root@hoge ~]# smartctl -A /dev/sdd
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.10.0-229.7.2.el7.x86_64] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF READ SMART DATA SECTION ===
SMART Attributes Data Structure revision number: 10
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  1 Raw_Read_Error_Rate     0x000f   078   047   044    Pre-fail  Always       -       72754870
  3 Spin_Up_Time            0x0003   099   091   000    Pre-fail  Always       -       0
  4 Start_Stop_Count        0x0032   100   100   020    Old_age   Always       -       183
  5 Reallocated_Sector_Ct   0x0033   082   082   036    Pre-fail  Always       -       389
  7 Seek_Error_Rate         0x000f   076   060   030    Pre-fail  Always       -       13042155971
  9 Power_On_Hours          0x0032   047   047   000    Old_age   Always       -       46843
 10 Spin_Retry_Count        0x0013   100   100   097    Pre-fail  Always       -       0
 12 Power_Cycle_Count       0x0032   100   037   020    Old_age   Always       -       136
184 End-to-End_Error        0x0032   100   100   099    Old_age   Always       -       0
187 Reported_Uncorrect      0x0032   001   001   000    Old_age   Always       -       507
188 Command_Timeout         0x0032   100   100   000    Old_age   Always       -       0
189 High_Fly_Writes         0x003a   100   100   000    Old_age   Always       -       0
190 Airflow_Temperature_Cel 0x0022   065   055   045    Old_age   Always       -       35 (Min/Max 33/39)
194 Temperature_Celsius     0x0022   035   045   000    Old_age   Always       -       35 (0 13 0 0 0)
195 Hardware_ECC_Recovered  0x001a   050   041   000    Old_age   Always       -       72754870
197 Current_Pending_Sector  0x0012   100   100   000    Old_age   Always       -       0
198 Offline_Uncorrectable   0x0010   100   100   000    Old_age   Offline      -       0
199 UDMA_CRC_Error_Count    0x003e   200   200   000    Old_age   Always       -       0

2015-08-27追記
使用開始してから2ヵ月経過ですが、その後も ATA bus error が出ることはなく、S.M.A.R.T. の不良セクタ関係のカウンタは、前回(1ヶ月前)から変化なしです。

2015年6月2日火曜日

ntpd を1日止めた場合のズレはどの程度か?

巷で話題の2015年7月1日の閏秒(うるう秒)挿入まで、あと1ヶ月。少し前に、うるう秒対策手法の一つとして、ntpd を止めればいいのではと書いたのですが、実際 ntpd を1日止めた場合に、どのぐらい時刻がズレるのか実験してみました。
外部の NTP サーバから時刻を参照している内部 NTP サーバを止めてみて、下位の NTP クライアントの時刻がどの程度ズレるかを観測しました。




設備の都合上、2サンプルだけですが、だいたい 13 ミリ秒程度という結果になりました。ちなみに、両マシンともに、かなり古く(約10年もの)、上が Pentium4 3.06G (Northwood,FSB533Mhz)、下が PentiumD 950 3.40G (SL95V,C1) 搭載です。
OS は、どちらも CentOS 6 で、ntpd は slew モードで動作させました。

グラフは、munin によるものです。

■関連記事
2012年7月1日の うるう秒 調整時の ntpd の挙動観測データ
うるう秒(閏秒)の際にcronが二重に実行されるかも?という都市伝説(?)について
2015年7月1日の うるう秒 調整時の ntpd の挙動観測データ
人気ブログランキングへ にほんブログ村 IT技術ブログへ