32

When I insert a thumb drive, media card, or USB hard drive, to unmount it via the command line, I need to use:

sudo umount /media/the_device

But, I can unmount the device in a file manager like Nautilus simply by clicking the eject button or using the right-click context menu on the device.

What is the rationale for the difference? How can I change it so that I can unmount from the command line without needing root privileges? Is changing it a bad idea?

Edit: In case it has changed, I am running 9.04. I've run most versions 5.10--9.04, and as far as I recall, it has always been this way.

2
  • Yeah, and then there's the mystery mounts. I have been trying for a long time to figure out how nautilus locates and mounts the local Windows network the computers in the house run on. I can get to the shared folders of anywhere through nautilus, but it would be really nifty to know how to get there from a terminal. Jul 29, 2010 at 17:36
  • Any network drives in Nautilus can be accessed under ~/.gvfs. Also, I recommend the nautilus-open-terminal plugin. Jul 30, 2010 at 12:02

3 Answers 3

44

Nautilus doesn't unmount the device directly; it talks over DBus to a system daemon (udisks-daemon) and asks it to unmount.

The daemon checks if you're allowed to do that, by contacting another system daemon, PolicyKit.

PolicyKit uses the configuration defined in /usr/share/polkit-1/actions/org.freedesktop.udisks.policy (unless the local system administrator overrides it in /etc/polkit-1). That file tells PolicyKit that users with active console sessions can detatch drives, so PolicyKit talks to a third daemon, ConsoleKit, to see if you have active console sessions. Logging in via gdm counts as a console session; logging in via ssh doesn't.

There's a command-line tool udisks that lets you unmount devices without using sudo, using the same mechanism:

udisks --unmount /dev/sdb1

that unmounts the filesystem; I can also detatch the whole device with

udisks --detach /dev/sdb

which makes the LED on my USB key go dark.

3
  • 4
    I want to thank you very much for provoking me into doing this research. I wanted a command-line tool to unmount devices without using sudo for a long time. Jul 30, 2010 at 12:28
  • 1
    Um, your welcome for my provoking you into giving a really good answer to my question. :-)
    – vanden
    Jul 30, 2010 at 15:02
  • 1
    The rights to do this are no longer present (as of Ubuntu 12.10) - however the answer below with gvfs-mount now works Jun 5, 2013 at 14:30
9

The situation might have changed -- in current Ubuntu 10.04 umount works without sudo for USB drives. Generally I think that the command

gvfs-mount -u /media/the_device

(gvfs-mount is in the gvfs-bin package) should always work.

4

Current answers are deprecated. Try with GIO command line tool.

gio mount --unmount *mounted location*

Get the current mounted partitions with, for example:

lsblk | grep media

Reference

Gio is a GTK library providing useful classes for general purpose I/O, networking, IPC, settings, and other high level application functionality.

GIO provides a portable, modern and easy-to-use file system abstraction API for accessing local and remote files; a set of low and high level abstractions over the DBus IPC specification; an application settings API; portable networking abstractions; and additional utilities for writing asynchronous operations without blocking the user interface of your application.

gio mount

Provides commandline access to various aspects of GIO’s mounting functionality.

Mounting refers to the traditional concept of arranging multiple file systems and devices in a single tree, rooted at /. Classical mounting happens in the kernel and is controlled by the mount utility. GIO expands this concept by introducing mount daemons that can make file systems available to GIO applications without kernel involvement.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .