Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux (Ubuntu): safely remove a USB flash disk via the command line [closed]

Tags:

ubuntu

usb

People also ask

How do I safely remove USB from Ubuntu?

Locate the device in the sidebar. It should have a small eject icon next to the name. Click the eject icon to safely remove or eject the device. Alternately, you can right-click the name of the device in the sidebar and select Eject.

Which command is used to disconnect pendrive in Linux?

eject -v --scsi /dev/sdb (explicitly chosen method) actually succeeded in ejecting, but the drive was detected right back (as evidenced by dmesg )

How do I reinitialize a USB drive in Linux?

Make sure that the USB stick that you want to reset is unplugged. Choose Applications ▸ Utilities ▸ Disks to start GNOME Disks. A list of all the storage devices on the computer appears in the left pane of the window. Plug the USB stick that you want to reset.


You can do this using udisks. It is not installed by default, but it is easy enough to install (the package is like a megabyte in size once installed)...

sudo apt-get install udisks

Once installed, you can detach a USB drive with the following commands...

sudo udisks --unmount /dev/sdb1
sudo udisks --detach /dev/sdb

The first line unmounts it. Just like any other partition you can still remount it at this point. The second line detaches it. After this it is powered down and you have to remove/reinsert it to remount.

To clarify, sdb is the device and sdb1, sdb2, sdb3, etc. are partitions on the device. Also, you will need to unmount all mount points before you attempt to detach the device. Usually with a USB stick/drive there is only one but it is a warning you should know about none the less.

Getting the device name from the mount point would require you pull it from mount or something.