I know that the
eject command can be used to eject almost any hardware component attached, but can it be used to eject USB drives?
Is it possible to eject USB drives and external HDD's with the
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
Yes. For example:
sudo eject /dev/sda
Other answers here that indicate that you require mechanical ejection hardware are incorrect.
Unmounting is not the same thing as ejecting.
eject will work, but will not really "finish the job" regarding USB rotating drives.
The best way to unplug a USB external hard-drive, after proper unmounting, is:
udisks --detach /dev/sdb
This usually causes the drive to spin down gracefully.
Precisely, the current implementation:
EDIT: Also, as g.rocket points out, this command may be equivalent:
udisksctl power-off -b /dev/sdb
If you carefully read eject(1) man page you can see that there are 4 methods of ejecting:
-r This option specifies that the drive should be ejected using a CDROM eject command. -s This option specifies that the drive should be ejected using SCSI commands. -f This option specifies that the drive should be ejected using a remov‐ able floppy disk eject command. -q This option specifies that the drive should be ejected using a tape drive offline command.
When you call eject on HDD/SCSI it issue
ioctl(fd, SG_IO, (void *)&io_hdr); command (copy from
This is equivalent as you safely remove device in MS Windows or MaxOSX.
For some devices this have special mean. For example Kindle 3 after eject command has being moved to charging mode and allow browsing on device, while before screen was locked.
Another utilities do same thing, like this
scsi-spin --force --down /dev/sda
"Ejecting" has no meaning for hardware without a tray or other loading mechanism (I assume it works with tape drives too).
However, testing with an external USB flash drive tells that
eject works much like
umount - with the side effect of making the device nodes disappear, e.g.
% ls /dev/sdc* /dev/sdc /dev/sdc1 % sudo eject /dev/sdc % ls /dev/sdc* /dev/sdc
/dev/sdc1 has disappeared.
In osx command line you should use diskutil where LABEL is label of your usb drive.
diskutil eject /Volumes/<LABEL>
OK i will try to explain this better:
udisks command completely remove and power off any usb device mounted or attached in the system unmount command just unmount the partition ie: dev/sdb1 or whatever but the usb is still present in the system.
So is not the same unmount, eject and detach
udisks = power off the usb
umount = just unmount the partition not the whole pendrive
eject = the same or very close to umount command