What's the proper way to disconnect hot-swap SATA hard drive?

I'm using a SATA hot-swap bay and I have in BIOS this particular port configured specifically for "Hot-Swap".

This bay has convenient "POWER ON/OFF" button, so no interruptions during plugging-in/out cables occurs.

When I'm turning a drive ON, I'm immediately getting some kernel errors, before it mounts:

[1263413.036674] ata6: exception Emask 0x10 SAct 0x0 SErr 0x4040000 action 0xe frozen
[1263413.036680] ata6: irq_stat 0x00000040, connection status changed
[1263413.036683] ata6: SError: { CommWake DevExch }
[1263413.036698] ata6: hard resetting link
[1263418.796687] ata6: link is slow to respond, please be patient (ready=0)
[1263423.052529] ata6: COMRESET failed (errno=-16)
[1263423.052547] ata6: hard resetting link
[1263428.032390] ata6: SATA link up 3.0 Gbps (SStatus 123 SControl 300)
[1263428.032836] ACPI Error: [DSSP] Namespace lookup failure, AE_NOT_FOUND (20150930/psargs-359)
[1263428.032846] ACPI Error: Method parse/execution failed [\_SB.PCI0.SAT0.SPT5._GTF] (Node ffff88040e0c5780), AE_NOT_FOUND (20150930/psparse-542)
[1263428.159582] ata6.00: ATA-9: HGST HDN726040ALE614, APGNW7JH, max UDMA/133
[1263428.159588] ata6.00: 7814037168 sectors, multi 0: LBA48 NCQ (depth 31/32), AA
[1263428.161980] ACPI Error: [DSSP] Namespace lookup failure, AE_NOT_FOUND (20150930/psargs-359)
[1263428.161988] ACPI Error: Method parse/execution failed [\_SB.PCI0.SAT0.SPT5._GTF] (Node ffff88040e0c5780), AE_NOT_FOUND (20150930/psparse-542)
[1263428.164472] ata6.00: configured for UDMA/133
[1263428.164483] ata6: EH complete
[1263428.164650] scsi 5:0:0:0: Direct-Access     ATA      HGST HDN726040AL W7JH PQ: 0 ANSI: 5
[1263428.165064] sd 5:0:0:0: Attached scsi generic sg4 type 0
[1263428.165502] sd 5:0:0:0: [sdd] 7814037168 512-byte logical blocks: (4.00 TB/3.64 TiB)
[1263428.165508] sd 5:0:0:0: [sdd] 4096-byte physical blocks
[1263428.165582] sd 5:0:0:0: [sdd] Write Protect is off
[1263428.165587] sd 5:0:0:0: [sdd] Mode Sense: 00 3a 00 00
[1263428.165618] sd 5:0:0:0: [sdd] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[1263428.213630]  sdd: sdd1
[1263428.214062] sd 5:0:0:0: [sdd] Attached SCSI disk
[1263534.534238] EXT4-fs (dm-5): mounted filesystem with ordered data mode. Opts: (null)

And when I'm unmounting it (like any other drive) and then turning the bay OFF, I'm getting more weird output from kernel (last parts occurs about 10 seconds after turning OFF - system still thinks that drive is connected for a while until it timeouts):

[1263588.964461] ata6: exception Emask 0x10 SAct 0x0 SErr 0x4090000 action 0xe frozen
[1263588.964467] ata6: irq_stat 0x00400040, connection status changed
[1263588.964478] ata6: SError: { PHYRdyChg 10B8B DevExch }
[1263588.964483] ata6: hard resetting link
[1263589.687000] ata6: SATA link down (SStatus 0 SControl 300)
[1263594.686806] ata6: hard resetting link
[1263595.006827] ata6: SATA link down (SStatus 0 SControl 300)
[1263595.006837] ata6: limiting SATA link speed to 1.5 Gbps
[1263600.006678] ata6: hard resetting link
[1263600.330626] ata6: SATA link down (SStatus 0 SControl 310)
[1263600.330634] ata6.00: disabled
[1263600.330645] ata6: EH complete
[1263600.330653] ata6.00: detaching (SCSI 5:0:0:0)
[1263600.334909] sd 5:0:0:0: [sdd] Synchronizing SCSI cache
[1263600.334943] sd 5:0:0:0: [sdd] Synchronize Cache(10) failed: Result: hostbyte=DID_BAD_TARGET driverbyte=DRIVER_OK
[1263600.334946] sd 5:0:0:0: [sdd] Stopping disk
[1263600.334955] sd 5:0:0:0: [sdd] Start/Stop Unit failed: Result: hostbyte=DID_BAD_TARGET driverbyte=DRIVER_OK

However drive works fine, no problems or data errors whatsoever, but I'm getting a feeling that it might have been done in a better/safer way, without such timeout-ing.

Is there a more proper way for disconnecting hot-swap SATA ?


I've been trying sending a udisksctl power-off -b /dev/sdd command, but while it works fine for USB drives, it does not do anything with SATA. Best thing I figured is to suspend a drive, before powering OFF, but kernel output is this same anyway.


$ uname -a
Linux dev 4.4.0-93-generic #116-Ubuntu SMP Fri Aug 11 21:17:51 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

Here's the weirdest command that actually does the trick I was looking for:

device=sde; sudo sh -c "echo 1 > /sys/block/${device}/device/delete"

Replace sde in this example with the respective drive. sh is a link to /bin/dash.

... and after this it goes:

[1285227.129329] sd 5:0:0:0: [sde] Synchronizing SCSI cache
[1285227.129566] sd 5:0:0:0: [sde] Stopping disk
[1285228.209095] ata6.00: disabled

... and now I can POWER OFF and it goes:

[1285259.491044] ata6: exception Emask 0x10 SAct 0x0 SErr 0x4090000 action 0xe frozen
[1285259.491049] ata6: irq_stat 0x00400040, connection status changed
[1285259.491052] ata6: SError: { PHYRdyChg 10B8B DevExch }
[1285259.491058] ata6: hard resetting link
[1285260.211923] ata6: SATA link down (SStatus 0 SControl 300)
[1285260.211934] ata6: EH complete

Little bummer that it needs root privilege, but it looks much more satisfying :)


When you have unmounted all the partitions with file systems in the drive (and swapped off any active swap partitions), you can turn off the power without any risk for the file systems (and maybe data storage of a hibernated state), and after that you can disconnect the drive.

I have used that method for years with eSATA drives, that I use for backup, and I have had no problems.


The unmount process starts with flushing the buffers (finishes writing data to the mounted file systems, which can also be done separately with the command sync), and after that the unmount process is finished (and the file systems are no longer available).

The following links may help describing unmounting and ejecting USB pendrives, (eject = unmount and turn off the power),

  • more about unmount: Unmount my Windows dedicated drive on Ubuntu pendrive

  • unmount versus eject: How to unmount MTP USB device from command line

    This is unmount. The buffers are flushed, so it is safe to unplug the device. The device has still power on, so it can be 'seen on the desktop', and it can be mounted again. This is different from eject. An ejected pendrive will be powered off, and must be unplugged and plugged in again if you want to mount it.

    I don't use any general automatic eject method for [e]SATA drives in linux, but you can use the following sequence of actions,

    • unmount
    • turn off power
    • disconnect

You can find methods via hdparm to turn off a SATA drive, but I have not used them, and I don't think they are necessary.