====== Disconnect/Eject SATA devices in Linux ======
===== Disconnect =====
- Identify the device root@misaka:~# lsblk -S /dev/sdd
NAME HCTL TYPE VENDOR MODEL REV TRAN
sdd 3:0:0:0 disk ATA TOSHIBA MD04ABA4 FP1T sata
- Do the magic root@misaka:~# echo 1 > /sys/block/sdd/device/delete
[45625.431882] sd 3:0:0:0: [sdd] Synchronizing SCSI cache
[45625.437707] sd 3:0:0:0: [sdd] Stopping disk
[45626.375309] ata4.00: disabled
- Done root@misaka:~# lsblk -S /dev/sdd
lsblk: /dev/sdd: not a block device
===== Reconnect =====
- Locate the device bus root@misaka:~# grep . /sys/class/scsi_host/host*/proc_name
/sys/class/scsi_host/host0/proc_name:ahci
/sys/class/scsi_host/host1/proc_name:ahci
/sys/class/scsi_host/host2/proc_name:ahci
/sys/class/scsi_host/host3/proc_name:ahci
/sys/class/scsi_host/host4/proc_name:ahci
/sys/class/scsi_host/host5/proc_name:ahci
/sys/class/scsi_host/host6/proc_name:mptsas
- Do the magic root@misaka:~# tee /sys/class/scsi_host/host3/scan <<<'- - -' >/dev/null
[45661.380112] ata4: hard resetting link
[45661.697502] ata4: SATA link up 3.0 Gbps (SStatus 123 SControl 300)
[45666.837346] ata4.00: qc timeout (cmd 0x27)
[45666.841491] ata4.00: failed to read native max address (err_mask=0x4)
[45666.847972] ata4.00: HPA support seems broken, skipping HPA handling
[45666.854353] ata4: hard resetting link
[45669.217309] ata4: SATA link up 3.0 Gbps (SStatus 123 SControl 300)
[45669.224306] ata4.00: ATA-8: TOSHIBA MD04ABA400V, FP1T, max UDMA/100
[45669.230692] ata4.00: 7814037168 sectors, multi 16: LBA48 NCQ (depth 31/32), AA
[45669.239087] ata4.00: configured for UDMA/100
[45669.243390] ata4: EH complete
[45669.250523] scsi 3:0:0:0: Direct-Access ATA TOSHIBA MD04ABA4 FP1T PQ: 0 ANSI: 5
[45669.318120] sd 3:0:0:0: [sdd] 7814037168 512-byte logical blocks: (4.00 TB/3.64 TiB)
[45669.318165] sd 3:0:0:0: Attached scsi generic sg3 type 0
[45669.331210] sd 3:0:0:0: [sdd] 4096-byte physical blocks
[45669.336593] sd 3:0:0:0: [sdd] Write Protect is off
[45669.341485] sd 3:0:0:0: [sdd] Mode Sense: 00 3a 00 00
[45669.341509] sd 3:0:0:0: [sdd] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[45669.678780] sd 3:0:0:0: [sdd] Attached SCSI disk
- Done root@misaka:~# lsblk -S /dev/sdd
NAME HCTL TYPE VENDOR MODEL REV TRAN
sdd 3:0:0:0 disk ATA TOSHIBA MD04ABA4 FP1T sata
===== See Alsos =====
* https://unix.stackexchange.com/questions/43413/how-can-i-safely-remove-a-sata-disk-from-a-running-system/278068#278068
{{tag>linux eject hotplug sata}}