5

I have a question for some time in my head:

I have an external hard drive, when I want to dismount it I simply give in the icon that says: "Remove unit safely" in the Nautilus (use Nautilus from Gnome 3.14 in Debian 8), but in reality what is the process behind? It's a way to see what really happens? Some kind of logs?

I imagine that the first process is umount /wherever/its/mount, but I noticed that when I unmount it using umount the led of the external hard drive stays on (when Windows OS turn off the led), so: the umount command should also cuts off the power of the USB port where the hard drive is connected? Or is another command doing this?

Thanks

k.Cyborg
  • 487

2 Answers2

4

umount command itself doesn't cut off power to the drive, mounting really means linking a filesystem on drive with a directory, so unmounting just does that - unlinks a mount from particular directory; and as far as Nautilus file manager goes that's not what it uses under the hood, in fact it uses GMount objects from the standard Gio API for all GNOME-related type of development.

Without confusing you too much, let me explain it in terms of source code and documentation. Brief search through source code reveals that in nautilus-file-operations.c file, the nautilus_file_operations_unmount_mount_full function calls do_unmount, which calls g_mount_eject_with_operation function. That last one belongs to GMount portion of API. Ejecting would involve sync-ing remaining data that needs to be written to the mount, unmounting a volume or drive, and then powering it off in case of USB drive or optical disk.

If you're expecting a shell command that can power off a drive just like in Nautilus, there is one via udisks or udisksctl, and if I'm not mistaken udisksctl comes with OSes that use systemd (but don't quote me on this last statement, that's an opinion only). That makes use of UDisks2, which is actually another API for handling drives and volumes via D-Bus interface; it is actually quite nice and I've used for developing my own indicator on Ubuntu.

So TL;DR:

  • Nautilus uses Gio API to handle mounts, but doesn't call any external or standalone command-line utility
  • There is command-line equivalent that performs similar operations as Nautilus
  • You can always write your own using Gio API, UDisks API, or call external udisks or udisksctl command.

See also:

M Y
  • 103
  • 1
  • 5
  • 1
    While I finished to write this question I keep searching for info and I see the link you left me at the end, and that answer me some doubts but your answer complete the "question I had in mind"...very useful information! THANKS!!!! – k.Cyborg Feb 03 '18 at 21:48
1

In gnome, the best way to mimic eject of a MYUSB drive within nautilus is

$ gio mount -e /media/dzmanto/MYUSB

It does not require root privileges.

dzmanto
  • 131