sata hotplug

最後更新: 2017-12-23

目錄

 

 


Un-plug

 

# 令 fs clean

umount /dev/sde1

# Disk to sleep ( 非必要 )

hdparm -Y /dev/sdb

/dev/sdb:
 issuing sleep command

# unregister the device from the kernel

# /dev/sdb* 會不見了

# Start_Stop_Count ( 4 ) 及 Load_Cycle_Count (193) 都會加 1

cat /sys/block/sde/device/model

echo 1 > /sys/block/sde/device/delete

[255365.430922] sd 1:0:0:0: [sdb] Synchronizing SCSI cache
[255365.431083] sd 1:0:0:0: [sdb] Stopping disk
[255366.306530] ata2.00: disabled

# unplug disk

[255407.546721] ata2: exception Emask 0x10 SAct 0x0 SErr 0x90200 action 0xe frozen
[255407.546750] ata2: irq_stat 0x00400000, PHY RDY changed
[255407.546767] ata2: SError: { Persist PHYRdyChg 10B8B }
[255407.546786] ata2: hard resetting link
[255408.259004] ata2: SATA link down (SStatus 0 SControl 300)
[255408.259016] ata2: EH complete

P.S.

[1] 不用 hdparm -Y /dev/sdb

"echo 1 > /sys/block/sdb/device/delete" 已經很夠, 不用 "hdparm -Y /dev/sdb"

原因係 Start_Stop_Count (  4  ) 及 Load_Cycle_Count (193) 都會加 1 

亦即是說 "echo 1 > delete" 與 "hdparm -Y" 有同樣效果

Remark

smartctl -a /dev/sdb 不會叫醒 HDD, touch /dev/sdb 就會了)

touch /dev/sdb

[256487.855328] ata2.00: exception Emask 0x0 SAct 0x0 SErr 0x0 action 0x6
[256487.855359] ata2.00: waking up from sleep
[256487.855377] ata2: hard resetting link
[256488.331339] ata2: SATA link up 3.0 Gbps (SStatus 123 SControl 300)
[256488.332491] ata2.00: configured for UDMA/133
[256488.332513] ata2: EH complete

[2] 真正的 Path

cd /sys/block/sde/device

pwd -P

# start with ata1
/sys/devices/pci0000:00/0000:00:11.0/ata3/host2/target2:0:0/2:0:0:0

 * 當沒有 Harddisk 時, 只有有

/sys/devices/pci0000:00/0000:00:11.0/ata3/host2

[3] runtime_status

cd /sys/devices/pci0000:00/0000:00:11.0/ata3/host2

cat power/runtime_status

suspended

# unit: ms

cat power/runtime_suspended_time

256356

cat power/runtime_active_time

712280

 


Plug

 

# When you plug the disks, you need to tell the OS to scan for new SATA devices

ls -l  /sys/class/scsi_host/host*

lrwxrwxrwx 1 root root 0 May 30 22:24 /sys/class/scsi_host/host0 -> ../../devices/pci0000:00/0000:00:11.0/ata1/host0/scsi_host/host0
lrwxrwxrwx 1 root root 0 May 30 22:24 /sys/class/scsi_host/host1 -> ../../devices/pci0000:00/0000:00:11.0/ata2/host1/scsi_host/host1
lrwxrwxrwx 1 root root 0 May 30 22:24 /sys/class/scsi_host/host2 -> ../../devices/pci0000:00/0000:00:11.0/ata3/host2/scsi_host/host2
lrwxrwxrwx 1 root root 0 May 30 22:24 /sys/class/scsi_host/host3 -> ../../devices/pci0000:00/0000:00:11.0/ata4/host3/scsi_host/host3
lrwxrwxrwx 1 root root 0 May 30 22:24 /sys/class/scsi_host/host4 -> ../../devices/pci0000:00/0000:00:11.0/ata5/host4/scsi_host/host4
lrwxrwxrwx 1 root root 0 May 30 22:24 /sys/class/scsi_host/host5 -> ../../devices/pci0000:00/0000:00:11.0/ata6/host5/scsi_host/host5

readlink /sys/block/sde

../devices/pci0000:00/0000:00:11.0/ata5/host4/target4:0:0/4:0:0:0/block/sde

echo "- - -" > /sys/class/scsi_host/host1/scan

# The three values stand for channel, SCSI target ID, and LUN.

# The dashes act as wildcards meaning "rescan everything"

[256607.348863] ata2: hard resetting link
[256607.824702] ata2: SATA link up 3.0 Gbps (SStatus 123 SControl 300)
[256607.825500] ata2.00: ATA-8: WDC WD10EAVS-00D7B1, 01.01A01, max UDMA/133
[256607.825505] ata2.00: 1953525168 sectors, multi 0: LBA48 NCQ (depth 31/32), AA
[256607.826077] ata2.00: configured for UDMA/133
[256607.826085] ata2: EH complete
[256607.826652] scsi 1:0:0:0: Direct-Access     ATA      WDC WD10EAVS-00D 1A01 PQ: 0 ANSI: 5
[256607.827216] sd 1:0:0:0: [sdb] 1953525168 512-byte logical blocks: (1.00 TB/932 GiB)
[256607.827235] sd 1:0:0:0: [sdb] Write Protect is off
[256607.827238] sd 1:0:0:0: [sdb] Mode Sense: 00 3a 00 00
[256607.827269] sd 1:0:0:0: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[256607.831369] sd 1:0:0:0: Attached scsi generic sg1 type 0
[256615.710099]  sdb: sdb1
[256615.711816] sd 1:0:0:0: [sdb] Attached SCSI removable disk

 


Remark

 

[1] SATA hotplug does not (usually) work until you set BIOS to use AHCI for the chipsets; on most motherboards it is set to ‘ide-emulation’ or such by default.

 

[2] Further notes, even AHCI is enabled, some motherboards required to set a seprate option for SATA hotplugging.

check removable

cat /sys/block/sdb/removable

1

cat /sys/block/sda/removable

0

快速找出 removable disk - lsblk

lsblk --nodeps --output NAME,TRAN,RM

rm       # which devices are removable
 

NAME  TRAN   RM
sdd   sata    0
sdb   sata    1
zram1         0
loop0         0
sdc   sata    0
sda   sata    0
zram0         0