A while ago I wrote about  auto-mounting media on an Ubuntu Server, and  the conclusion was to use udisks-glue.  Here’s an updated version that uses a proper init script and works for Ubuntu Server 12.04 and 14.04.

Install

First, install udisks:

sudo apt-get install udisks

Next, install udisks-glue.  On 12.04, this is as simple as ‘sudo apt-get install udisks-glue’, but on 14.04 you’ll need to build udisks-glue from source (which isn’t very hard).

Configure

Different Linux distributions, and even different versions of the same distribution (ie. Ubuntu) may or may not include a default /etc/udisks-glue.conf, which may or may not need editing to allow auto mounting and un-mounting to work properly.  Here’s a simple version that works well with card readers:

filter disks {
    optical = false
    partition_table = false
    usage = filesystem
}
match disks { 
    automount=true
    automount_options= {"sync", "dmask=0000"}
}

Edit or create /etc/udisks-glue.conf to suit your auto-mounting needs.

Use

With udisks and udisks-glue installed, the last step is to make everything start up automatically.  To do this, use an init script:

To use this script:

git clone https://gist.github.com/5399914.git udisks-glue  #(or copy and paste from above if you don't like git)
cd udisks-glue
chmod +x udisks-glue
sudo cp udisks-glue /etc/init.d/.
sudo update-rc.d udisks-glue defaults

Now udisks-glue will start automatically on each boot.  Here are some other handy commands you can use now that udisks-glue has a proper init script:

sudo service udisks-glue [start|stop|restart|status]
Tagged with →  
Share →

13 Responses to How to Automount Removable Media on Ubuntu Server

  1. Alexandre Magno says:

    Fixes below.

    git clone https://gist.github.com/5399914.git udisks-glue

    Before chmod:

    cd udisks-glue

    Then:

    sudo update-rc.d udisks-glue defaults

    sudo service [start|stop|restart] udisks-glue
    sudo service udisks-glue [start|stop|restart|status]

    Or:

    sudo /etc/init.d/udisks-glue status
    sudo /etc/init.d/udisks-glue [start|stop|restart|status]

  2. Alexandre Magno says:

    I use Ubuntu 12.04.2 LTS. But udisks-glue is action less there [because /etc/udisks-glue.conf is empty].

    My [test] configuration in /etc/udisks-glue.conf:

    filter disks {
    optical = false
    usage = filesystem
    }
    match disks {
    post_mount_command = "echo test > /home/alexandre/teste.txt"
    }

  3. Mathieu says:

    Thanks you very much for this init.d script

    If udisks-glue doesn’t start on boot:
    Replace $local_fs with $all

    On Debian 6 (Squeeze) or later replace this:
    sudo update-rc.d udisks-glue defaults
    with this:
    sudo insserv udisks-glue

  4. […] start udisks-glue at boot by adding “/usr/bin/udisks-glue” to /etc/rc.local or use this init script. […]

  5. MocArt says:

    Hi, help me please, how i can include mount options in ntfs-3g driver? 4 ex: option “big_writes” And second Question, when i mount like your instruction, i can’t write by user, only root, can you help me please?

    • Andrew says:

      Sorry, don’t know. That’s not really what this article is about. Likely there are some clues in ‘man udisks-glue.conf’ – looks like the ‘automount_options’ might be what you’re after. Good luck.

  6. Etch says:

    This script didn’t work for me as it mounted the disks without proper permissions for access.
    I usually just directly call udisks-glue executable from my kodi.desktop file (without a custom init script) and it mounts everything properly and all users can access them, but when replaced it with this init script like so:
    /etc/init.d/udisks-glue start
    the disks were mounted but no one could access them.
    Had to revert to just calling udisks-glue without the init script.

    • Andrew says:

      Have you set the correct permissions in udisks-glue.conf? Something like:

      automount_options= {“sync”, “dmask=0000”}

      Will allow all users to access the auto-mounted disks. See the man page for more details.

  7. leninb says:

    Hi, very interesting article. I have a doubt though. How do you make it autostart on boot with ubuntu 16.04 and systemd, instead of init?
    Thanks in advance

  8. Lenb says:

    Hi, I wanted to try this but I am stuck here :)
    sudo apt-get install udisks

    Package udisks is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source
    E: Package ‘udisks’ has no installation candidate

    What should I do?
    I am running minimal version of Ubuntu 16.04 64 bits (mini.iso)
    Thanks in advance

Leave a Reply

Your email address will not be published.