7

I have a external seagate 1TB USB hard disk. Every time I connect it to my computer it gets automatically mounted. While removing it I select safely remove option rather than unmount because I read somewhere that it is recommended.

I have two questions:-

  1. Is true that just unmounting can damage my hard disk. Should I always select safely remove option? (I know the difference between unmount and safely remove and I have also noted that unmounting removes it from file table entry but safely removing actually stops using it. The power supply LED goes off after safely removing which doesn't happen with unmount).

  2. The first question leads me to this! How do I `safely remove my hard disk from command line?

(I know how to umount it.. but even if I unmount it it is still shown in fdiks -l I don't want that)

  • As I know, both options check the disk to be not used, and both are safe. Except that unmount gives the opportunity to re-mount. – Alen Nov 23 '13 at 16:19
  • But if I unmount the disk it is still in use (as shown by the LED). If I safely remove it then it actually stops using it i.e. it stops the power supply or something like that!(I think unmounting and then removing causes abrupt power cut off.) – Null pointer Nov 24 '13 at 5:44
  • 1
    It is preferred if you can post separate questions instead of combining your questions into one. That way, it helps the people answering your question and also others hunting for atleast one of your questions. Thanks! – kiri Jan 13 '14 at 22:26
6

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

  • 1
    First of all thanks Mitch for quick reply..I know about umount command..it will just unmount the drive and udisks --unmount also does the same thing..but when I do unmount --detach it gives error Detach failed: Device is not a drive..am I doing anything wrong? – Null pointer Nov 23 '13 at 10:22
  • What is the output of mount|grep ^'/dev' – Mitch Nov 23 '13 at 10:36
  • /dev/disk/by-uuid/a2fad9a2-7659-416b-a33a-c6f485386a7a on / type ext4 (rw,relatime,errors=remount-ro,data=ordered) – Null pointer Nov 23 '13 at 10:41
  • Have you tried copying and pasting the UUID rather than typing it? – Elder Geek Jun 20 '14 at 13:20
6

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

  • Adding "See man udisks for more info" (included in your reference) to you answer would do no harm and possibly help in more ways than this one. "Give a man a fish and feed him for a day, Teach a man to fish and feed him for life" – Elder Geek Jun 20 '14 at 13:15
  • When I am logged in via SSH in Ubuntu16.04 and try the first version it asks me twice for user authentication (unmount and power off). Is that normal? – CatMan Sep 24 '18 at 10:34
  • @CatMan Not normal for a desktop user, but probable for ssh user. I haven't explored how udiskctl does mounting/unmounting without prompting for password, but if I recall correctly it uses polkit settings, and those may limit passwordless use to local users only – Sergiy Kolodyazhnyy Sep 25 '18 at 16:09
1
  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.

1

Run this command to get your device path:

lsblk

A command to unmount a drive would be:

udisksctl unmount -b /dev/$DEVICE
1

These also work (14.04):

$ udisks --mount  /dev/sdi1
$ udisks --unmount  /dev/sdi1

NOTED: no need to 'sudo' and both of

$ udisks --unmount 
$ udisksctl unmount

leaves the LED lit on my Sandisk Imagemate (USB3.0 card reader).

Other ways to find out devices

blkid -o list
ls -lR /dev/disk/
  • udisks does not work in 16.04 default install (command not found). The man page is available, however. – CatMan Sep 24 '18 at 10:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.