6

When I press "safely remove drive" in Nautilus as user to my USB 3.0 Transcent Storejet 25H3 drive it reconnects immediately.

How can I safely remove it without that behaviour?

I think the only solution is to disable the automounting in Ubuntu. I did that now with: How to disable automount in nautilus's preferences

But it is a shame, cause now my external music library doesn't automount anymore.

Isn't there a solution where harddisks don't remount on safely remove?!

rubo77
  • 32,486
  • See https://askubuntu.com/questions/89244/how-to-disable-automount-in-nautiluss-preferences – user.dz Feb 18 '14 at 09:01
  • I've reopened the question. Please post an answer. Thanks. – Seth May 03 '14 at 01:53
  • To still have it automounted once at system start, you can add it to your. /etc/fstab, so the drive will be auto mounted until you unmount it manually.

    Additionally, if you want to be sure, it even mounts if it failed to mount read-write (due to an unclean unmount in windows before) you can use this script to remount it readonly then: http://askubuntu.com/questions/424913/

    – rubo77 Aug 29 '14 at 22:47
  • 2
    bug: https://bugs.launchpad.net/ubuntu/+source/nautilus/+bug/792085 – Tim Abell Aug 08 '15 at 17:31

1 Answers1

5

Valid for this Ubuntu at least:

$ lsb_release -d  
Description:    Ubuntu 14.04.1 LTS


I have found that:
$ udisksctl mount --block-device /dev/$device

... will mount /dev/xxx in the same style as automount,
that is - in /media/$USER/Disk_Label-or-UUID/ with the last level dir auto-created.

$ udisksctl unmount --block-device /dev/$device;  

... will umount the above, but not '-eject' memory card/USB reader content.

$ gvfs-mount --eject "file:///media/$USER/DISK_LABEL"  

... lastly appears to be equal to 'Safely remove' or 'Eject' - and that WITHOUT an immediate re-mount.

Note: $ udisksctl power-off --block-device /dev/$device;
... would otherwise be a 'natural' option, but is hampered by an immediate re-mount.


EDIT --- you could use this script to "umount all" without having to dig out the names:
#! /bin/bash
#
for device in $(mount | grep "/media/$USER/" | cut -d" " -f1); do
        echo Unmounting $device 
        udisksctl unmount --block-device $device
done

if you prefer eject, change the -f1 into -f3 in the cut command and the line with udiskctl with

gvfs-mount --eject "file://$device"

(I think --- you can have problem with correctly quoting labels with blanks in it; and you'll have warnings if the device has multiple partitions mounted).



$ lsblk

... will display all the available block devices (except ram disks, no sudo required).
RAM and loop --> lsblk --all .



How do I "automount" a labelled disk?

Bring up the Dash (hit the 'Super' key) and type 'startup appl' and 'Startup Applications' should appear, click on it. Click Add and type anything you want in 'Name' and 'Comment' fields. Then fill in 'Command' with your version of:

/bin/bash -c '/bin/sleep 5 && /usr/bin/udisksctl mount -b /dev/disk/by-label/GreenWD_3TB'

... where /dev/disk/by-label/GreenWD_3TB is anything suitable you find from
the display of ls -lR /dev/disk/* | less



More:
How to access gvfs mounts from command line?
How to mount drive in /media/userName/ like nautilus does using udisks
Hannu
  • 5,374
  • 1
  • 23
  • 40
  • gvfs-mount --eject doesn't work as "Safely Remove" for me on the same 14.04.1 LTS. It just unmouts and keeps harddisk spinning. Error ejecting mount: Error ejecting /dev/sdc: Command-line 'eject "/dev/sdc"' exited with non-zero exit status 1: eject: unable to eject, last error: Invalid argument. It seems a bug. – AliNajafies Oct 18 '14 at 17:56
  • Please check above again; you cannot use /dev/sdc with gvfs-mount . – Hannu Oct 23 '14 at 19:16
  • Yeah, I see, the error uses this way to mention the drive. – AliNajafies Oct 23 '14 at 22:51
  • @Hannu I added a script to the answer --- I hope you don't mind. – Rmano Oct 17 '15 at 10:49
  • 2
    Well, does not seem directly related to answering the Q - but might be useful for someone. – Hannu Oct 17 '15 at 17:45