safely remove using command line

Solution 1:

Try this. Just press Ctrl+Alt+T on your keyboard to open Terminal. When it opens, run the command(s) below:

sudo umount /dev/<device_id> 

addition/correction (if you want to go by device uuid, i.e. not something like "sda3" but rather its unique long numeric/hex string like "366A52F225612...") use

sudo umount /dev/disk/by-uuid/<device_id>

Or you can use udisks.

sudo udisksctl unmount /dev/<device_id>

You can get the device ID using sudo fdisk -l command

To install udisks if not installed, just do

sudo apt-get install udisks

For more info see the udisks manpage

Solution 2:

Ubuntu comes with Udisks daemon, which allows mounting/unmounting , and doing several other things with block devices (aka drives) without need for sudo as in the case of mount commands. Of particular interest is the options for detaching/powering-off the drive.

For newer releases, use udisksctl command, specifically this sequence:

udisksctl unmount -b /dev/sdc1 && udisksctl power-off -b /dev/sdc                                                                                  

Older versions of Ubuntu (13.10 and earlier) can use the following

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

In both commands the idea is the same: the command both unmounts and then powers-down the device(if your USB device has LED, no LED will be flashing and it won't show up in udisksctl status or df).

For convenience, both of these commands could be made a function in ~/.bashrc , for instance:

drive_off(){
    # Function that unmounts and powers off a USB drive
    # Usage example: drive_off /dev/sdc1
    device=$(awk '{print substr($0,0,length($0)-1)}' <<< "$1")
    udisksctl unmount -b "$1" && udisksctl power-off -b "$device"
}

Reference: ubuntuforums.org

Also, refer to udisks manual page through terminal for more info: man udisks

Solution 3:

  1. Unmounting won't damage your disk or data. Unplugging it while it is still in use can corrupt the data. Unmounting it will generally also sync the filesystem which makes it safe to eject the disk. Check the led for activity. If you want to be totaly sure there is the command sync which, according to the man page, forces changed blocks to disk and updates the super block.

  2. Apparently its not safe for some devices to unplug them when they are on. So the to be absolutely safe some file managers give the option to remove the device from the system entirely.

Solution 4:

Run this command to get your device path:

lsblk

A command to unmount a drive would be:

udisksctl unmount -b /dev/$DEVICE