You can do this with udisks. it is not installed by default, but simple enough to install (the package is installed as the mega-size after installation) ...
sudo apt-get install udisks
After installation, you can disconnect the USB drive with the following commands ...
sudo udisks --unmount /dev/sdb1 sudo udisks --detach /dev/sdb
The first line disables it. Like any other partition, you can still remount it at this point. The second line separates it. After that, it disconnects and you need to remove / reinsert it to reconnect.
To clarify, sdb is the device, and sdb1 / 2/3 / etc are partitions on the device. In addition, before attempting to disconnect the device, you must disable all mount points. Usually there is only one with a USB stick / drive, but this is a warning you should be aware of nonetheless.
Getting the device name from the mount point will require you to pull it out of mount or something like that.
Omnikrys Nov 05 '12 at 1:27 2012-11-05 01:27
source share