How to eject SATA device properly in Linux? I know eject command can do it for usb device:
eject usbDevicePath
Does it work same way for SATA devices? Will it sync caches, and properly power down SATA device?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Sign up to join this communityThe solution is to spin down the drive via software before turning it off and unplugging it. The best way to do this is with a utility called scsiadd. This program can add and remove drives to Linux’s SCSI subsystem. Additionally, with fairly modern kernels, removing a device will issue a stop command, which is exactly what we’re looking for.
Run:
$ sudo scsiadd -p
which should print something like:
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
Vendor: ATA Model: SAMSUNG HD300LJ Rev: ZT10
Type: Direct-Access ANSI SCSI revision: 05
Host: scsi4 Channel: 00 Id: 00 Lun: 00
Vendor: LITE-ON Model: DVDRW LH-20A1L Rev: BL05
Type: CD-ROM ANSI SCSI revision: 05
Host: scsi5 Channel: 00 Id: 00 Lun: 00
Vendor: ATA Model: WDC WD10EACS-00Z Rev: 01.0
Type: Direct-Access ANSI SCSI revision: 05
Identify the drive you want to remove and then issue:
$ sudo scsiadd -r host channel id lun
substituting the corresponding values from the scsiadd -p output. For example, if I wanted to remove “WDC WD10EACS-00Z”, I would run:
$ sync & sudo scsiadd -r 5 0 0 0
If everything works, scsiadd should print:
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
Vendor: ATA Model: SAMSUNG HD300LJ Rev: ZT10
Type: Direct-Access ANSI SCSI revision: 05
Host: scsi4 Channel: 00 Id: 00 Lun: 00
Vendor: LITE-ON Model: DVDRW LH-20A1L Rev: BL05
Type: CD-ROM ANSI SCSI revision: 05
You can double-check the end of dmesg. You should see:
[608188.235216] sd 5:0:0:0: [sdb] Synchronizing SCSI cache
[608188.235362] sd 5:0:0:0: [sdb] Stopping disk
[608188.794296] ata6.00: disabled
At this point, the drive is removed from Linux’s SCSI subsystem and it should not be spinning. It’s safe to unplug and turn off.
scsiadd
from? I don't have that command available on my system.
Apr 20, 2019 at 7:31
This answer was most useful: after umounting, stopping LVM, LUKS, etc. you do:
echo 1 >/sys/block/sdX/device/delete
And since this answer seems to have attracted *buntu users who don’t know how to use sudo(8) with redirections correctly, here’s the easiest way to do it with sudo:
echo 1 | sudo dd of=/sys/block/sdX/device/delete
The literal way is:
sudo sh -c 'echo 1 >/sys/block/sdX/device/delete'
An otherwise unquoted redirection is handled by the shell outside of the call to sudo instead, and you need the redirection, not the echo, to be run with superuser privilegues.
lsblk
, but what about stopping the drive from spinning?
Apr 20, 2019 at 7:33
mount command can help you, see man mount
So, you need to 'eject' that device, just check which device it is, you can do it with:
# sudo df -lh
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 145G 50G 87G 37% /
So if you want to 'eject' /dev/sda1 just use:
sudo umount /dev/sda1
Ofcourse if device is in use/busy it won't let you do it, like sda1 is where my OS is :D