hdparm

最後更新: 2019-05-30

 

 


查看一般資料

 

hdparm /dev/sda

/dev/sda:
 multcount     = 16 (on)
 IO_support    =  1 (32-bit)
 readonly      =  0 (off)
 readahead     = 256 (on)
 geometry      = 30401/255/63, sectors = 488397168, start = 0

更多資料:

hdparm -i /dev/sda

/dev/sda:

 Model=Hitachi HDP725025GLAT80, FwRev=GM2OA4CA, SerialNo=GE1240RS0KA9XA
 Config={ HardSect NotMFM HdSw>15uSec Fixed DTR>10Mbs }
 RawCHS=16383/16/63, TrkSize=0, SectSize=0, ECCbytes=56
 BuffType=DualPortCache, BuffSize=7174kB, MaxMultSect=16, MultSect=16
 CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=488397168
 IORDY=on/off, tPIO={min:240,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=yes: disabled (255) WriteCache=enabled
 Drive conforms to: unknown:  ATA/ATAPI-2,3,4,5,6,7

 * signifies the current active mode

more detail than "-i"

hdparm -I /dev/sde

Capabilities:
        LBA, IORDY(can be disabled)
        Queue depth: 32
        Standby timer values: spec'd by Standard, no device specific minimum
        R/W multiple sector transfer: Max = 16  Current = ?
        Recommended acoustic management value: 208, current value: 0
        DMA: mdma0 mdma1 mdma2 udma0 udma1 udma2 udma3 udma4 udma5 *udma6
             Cycle time: min=120ns recommended=120ns
        PIO: pio0 pio1 pio2 pio3 pio4
             Cycle time: no flow control=120ns  IORDY flow control=120ns
Commands/features:
        Enabled Supported:
           *    SMART feature set
                Security Mode feature set
           *    Power Management feature set
           *    Write cache
           *    Look-ahead
           *    Host Protected Area feature set
           *    WRITE_BUFFER command
           *    READ_BUFFER command
           .........

Security:
        Master password revision code = 65534
                supported
        not     enabled
        not     locked
        not     frozen
        not     expired: security count
                supported: enhanced erase
        82min for SECURITY ERASE UNIT. 82min for ENHANCED SECURITY ERASE UNIT.

 


測試速度

 

Usage:

hdparm -tT /dev/sda

caching of data (從 HardDisk 的 cache 讀取資料):

hdparm -t /dev/sdd

/dev/sdd:
 Timing buffered disk reads: 104 MB in  3.02 seconds =  34.40 MB/sec

buffer cache speed (without  disk access):

hdparm -T /dev/sdd

/dev/sdd:
 Timing cached reads:   4334 MB in  2.00 seconds = 2167.95 MB/sec

 


Enable Write Cache

 

查看:

hdparm -W /dev/sda

/dev/sda:
 write-caching =  1 (on)

停用:

hdparm -W0 /dev/sda

 

立即寫入 Cache

-f     Sync and flush the buffer cache for the device on exit. 

       This operation is also performed internally as part of the -t and -T timings and other options.

 


Check Disk Cache

 

# tell whether a device needs cache flushes or not

cat /sys/block/sda/device/scsi_disk/*/cache_type

OR

cat /sys/block/sda/queue/write_cache

  • "write back"        # the device claims that it does require cache flushes.
                             # (hdparm -W1 /dev/sda)
  • "write through"   # the device claims that it does not require cache flushes.
                             # (hdparm -W0 /dev/sda)

 


令 Disk Sleep

 

# idle

Put the drive into idle (low-power) mode, and also set the standby (spindown) timeout for the drive.

# Standby

-y     # Force an IDE drive to immediately enter the low power consumption standby mode,

        # usually causing it to spin down.  

 * 在 standby mode 依然用到 smartctl -d sat -a /dev/sdd

hdparm -y /dev/sdd

# 此 cmd 會令 Load_Cycle_Count 上升

193 Load_Cycle_Count        0x0032   200   200   000    Old_age   Always       -       3

 * If anything access the disk, it will spin up again.

# Sleep

-Y     # Force an IDE drive to immediately enter the lowest power consumption sleep mode, causing it to shutdown completely.
        # A hard or soft reset is required before the drive can be accessed again
        # (the Linux IDE driver will automatically handle issuing a reset if/when needed)

# Checking

-C            # current power mode status

hdparm -C /dev/sdd

[1]

/dev/sdd:
 drive state is:  active/idle

[2]

/dev/sdd:
 drive state is:  standby

# Auto Sleep

-S    

Put the drive into idle (low-power) mode, and also set the standby (spindown) timeout for the drive.

This timeout value  is  used  by  the drive  to determine how long to wait (with no disk activity) before turning off the spindle motor to save power.  

Under such circumstances, the drive may take as long as 30 seconds to respond to a subsequent disk access, though most drives are much quicker.  

The encoding of  the  timeout  value  is somewhat peculiar. 

A value of zero means "timeouts are disabled": the device will not automatically enter standby mode.

Values from 1 to 240 specify multiples of 5 seconds, yielding timeouts from 5 seconds to 20 minutes.  

Values from 241 to 251 specify from 1 to  11  units  of 30 minutes, yielding timeouts from 30 minutes to 5.5 hours.  

A value of 252 signifies a timeout of 21 minutes. A value of 253 sets a vendor-defined timeout period between 8 and 12 hours,

and the value 254 is reserved.  255 is interpreted as 21 minutes  plus 15 seconds. 

Note that some older drives may have very different interpretations of these values.

 


Save Power

 

Most modern harddisk drives have the ability to speed down the head movements to reduce their noise output.

-M               # Get/set Automatic Acoustic Management (AAM) setting.

  • 0 (off)
  • 128 (quiet)
  • 254 (fast)

 


Lock HDD with Pass

 

此 lock 是透過 firmware password 實現

hard drive is really encrypted, and the password is used to unlock a decryption key

底板 BIOS 要 support HDD password protection 才會問密碼

強度: 32 bytes

測試 HDD:  ST500DM002-1BD142

查看 HDD 的 "Security" 情況

hdparm -I /dev/sde

Security:
        Master password revision code = 65534
                supported
        not     enabled
        not     locked
        not     frozen
        not     expired: security count
                supported: enhanced erase
        82min for SECURITY ERASE UNIT. 82min for ENHANCED SECURITY ERASE UNIT.

frozen => 無法執行使用 "Security" 功能, 比如 Secure Erase (Freeze security settings until power reset)

--security-freeze      # Freeze the drive´s security settings

                              # combination with --security-unlock to protect drive from any attempt to set a new password

對硬碟設置 Security 功能的密碼 (不影響現有 Data)

# When the user password is set the drive will be locked after next power cycle

# (the drive will deny normal access until unlocked with the correct password)

hdparm --security-set-pass 1234 /dev/sde

security_password: "1234"

/dev/sde:
 Issuing SECURITY_SET_PASS command, password="1234", user=user, mode=high

hdparm -I /dev/sde

Security:
        Master password revision code = 65534
                supported
                enabled
        not     locked

Power reset HDD 後 (soft reset 係唔得的 "echo 1 > /sys/block/sde/device/delete" )

Security:
        Master password revision code = 65534
                supported
                enabled
                locked

當 HDD 被 lock 後 dmesg 有

[ 3771.730005] ata5: exception Emask 0x10 SAct 0x0 SErr 0x90202 action 0xe frozen
[ 3771.730024] ata5: irq_stat 0x00400000, PHY RDY changed
[ 3771.730034] ata5: SError: { RecovComm Persist PHYRdyChg 10B8B }
[ 3771.730050] ata5: hard resetting link
[ 3772.454154] ata5: SATA link down (SStatus 0 SControl 300)
[ 3772.454164] ata5: EH complete
[ 3772.839999] ata5: exception Emask 0x10 SAct 0x0 SErr 0x40d0002 action 0xe frozen
[ 3772.840004] ata5: irq_stat 0x00000040, connection status changed
[ 3772.840007] ata5: SError: { RecovComm PHYRdyChg CommWake 10B8B DevExch }
[ 3772.840012] ata5: hard resetting link
[ 3778.645314] ata5: SATA link up 6.0 Gbps (SStatus 133 SControl 300)
[ 3778.646784] ata5.00: ATA-8: ST500DM002-1BD142, KC48, max UDMA/133
[ 3778.646787] ata5.00: 976773168 sectors, multi 0: LBA48 NCQ (depth 31/32)
[ 3778.648309] ata5.00: configured for UDMA/133
[ 3778.648317] ata5: EH complete
[ 3778.648450] scsi 4:0:0:0: Direct-Access     ATA      ST500DM002-1BD14 KC48 PQ: 0 ANSI: 5
[ 3778.648684] sd 4:0:0:0: [sde] 976773168 512-byte logical blocks: (500 GB/466 GiB)
[ 3778.648686] sd 4:0:0:0: [sde] 4096-byte physical blocks
[ 3778.648697] sd 4:0:0:0: [sde] Write Protect is off
[ 3778.648699] sd 4:0:0:0: [sde] Mode Sense: 00 3a 00 00
[ 3778.648717] sd 4:0:0:0: [sde] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[ 3778.650241] sd 4:0:0:0: Attached scsi generic sg4 type 0
[ 3778.752907] ata5.00: exception Emask 0x0 SAct 0x100 SErr 0x0 action 0x0
[ 3778.752912] ata5.00: irq_stat 0x40000001
[ 3778.752915] ata5.00: failed command: READ FPDMA QUEUED
[ 3778.752920] ata5.00: cmd 60/08:40:00:00:00/00:00:00:00:00/40 tag 8 ncq dma 4096 in
                        res 41/04:08:00:00:00/00:00:00:00:00/00 Emask 0x401 (device error) <F>
[ 3778.752922] ata5.00: status: { DRDY ERR }
[ 3778.752924] ata5.00: error: { ABRT }
[ 3778.755777] ata5.00: configured for UDMA/133
[ 3778.755792] ata5: EH complete
[ 3778.853038] ata5.00: NCQ disabled due to excessive errors
[ 3778.853042] ata5.00: exception Emask 0x0 SAct 0x400 SErr 0x0 action 0x0
[ 3778.853046] ata5.00: irq_stat 0x40000001
[ 3778.853050] ata5.00: failed command: READ FPDMA QUEUED
[ 3778.853055] ata5.00: cmd 60/08:50:00:00:00/00:00:00:00:00/40 tag 10 ncq dma 4096 in
                        res 41/04:08:00:00:00/00:00:00:00:00/00 Emask 0x401 (device error) <F>

# Disable Lock

# Switching "Locked" into"Not Locked" ("soft reset" / "hdparm -z" 後就 unlock 了, power reset 後就會 lock 後)

--security-unlock PASSWD       # Unlock drive

i.e.

hdparm --security-unlock 1234 /dev/sde

soft reset

hdparm -Y /dev/sde
echo 1 > /sys/block/sde/device/delete
echo "- - -" > /sys/class/scsi_host/host4/scan

hdparm -I /dev/sde

Security:
        Master password revision code = 65534
                supported
                enabled
        not     locked

# Switching "Enabled" into "Not Enabled" security lock

--security-disable PASSWD      # Disable drive locking, using password PWD (soft reset 後生效)

i.e.

hdparm --security-disable 1234 /dev/sde

Security:
        Master password revision code = 65534
                supported
        not     enabled
        not     locked

Remark

# Force a kernel re-read of the partition table of the specified device(s)

hdparm -z /dev/sde

 


Master password

 

Master password revision code

hdparm -I /dev/sde

...
Security:
        Master password revision code = 65534
                supported
        not     enabled
        not     locked
        not     frozen
        not     expired: security count
                supported: enhanced erase
        20min for SECURITY ERASE UNIT. 60min for ENHANCED SECURITY ERASE UNIT.
...

The default value 65534 (0xFFFE) references the manufacturer-defined password

The initial master password is unknown to the user but can be overwritten by the first call

hdparm -user-master m --security-set-pass 1234 /dev/sde

The Master Password Revision Code is then set to 1

Security:
        Master password revision code = 1

 * If only a master password, but no user password, is set, no security features are active.

Security level

--security-mode MODE

  • h        # high (Defaults)
  • m       # maximum

maximum

no longer unlock the device with the master password or directly disable the security features
( lose all user data if you forget the user password )

Usage

hdparm --security-mode m --security-set-pass 1234 /dev/sde

設定 master password

# u=user password(default), m=master password

hdparm --user-master m --security-disable datahunter /dev/sde

hdparm --user-master m --security-unlock datahunter /dev/sde

# Only useful in combination with

  • --security-unlock
  • --security-set-pass
  • --security-disable
  • --security-erase
  • --security-erase-enhanced

 


Secure Erase

 

# 使用與 "--security-set-pass" 相同的密碼執行 Secure Erase

# After a successful erasure the drive security should automatically be set to disabled

# (thus no longer requiring a password for access).

--security-erase PWD             #  Erase (locked) drive, using password PWD (DANGEROUS).

i.e.

hdparm --user-master u --security-set-pass 1234 /dev/sdx

hdparm --security-erase 1234 /dev/sdx

Result: hdparm 會在 console 執行並且不能 kill, harddisk 開始長轉

Secure erase

Overwrites all user data areas with binary zeroes.

Enhanced secure erase

Writes predetermined data patterns (set by the manufacturer) to all user data areas,

including sectors that are no longer in use due to reallocation.

 


 

Creative Commons license icon Creative Commons license icon