back

Automounting USB drives

The upside of using developer friendly software on your computer is that you can automate away lots of mundane tasks and be incredibly effective at the rest. Should you really have to click a bunch of boxes in the right order and wait for windows to load just to point to the file you want to open? Yay, command line! Yay, tiling window manager!

The downside is that you need to set up a lot by hand, say, automatically mounting USB drives. Here's how to do that in Ubuntu.

  1. Install usbmount

    sudo apt-get install usbmount
    

    usbmount is a neat little script that mounts your usb drives in /media/usbX when you plug them in, giving you equivalent functionality you would be used to using Nautilus, a Mac, or (yikes) Windows Explorer. Make that double yikes, one for Windows itself, and one for Explorer. Heck, make that triple yikes, with one extra for good measure.

  2. Allow users to access usb drives

    sudo sed -i '/\bMOUNTOPTIONS\b/s/\("\?\)$/,user,umask=000\1/' /etc/usbmount/usbmount.conf
    

    Presumably for security reasons, only root can access usbmount-ed drives by default. To change that, go into /etc/usbmount, and add user and umask=000 to the list of mount options.

  3. Get rid of sync mode

    sudo sed -i '/\bMOUNTOPTIONS\b/s/sync,\?//' /etc/usbmount/usbmount.conf
    

    Probably to prevent people from non-safely removing USB drives, sync mode is on by default. Sync mode is hideously slow though and should be disabled. Go into /etc/usbmount again, and remove the sync option.

    No special restarting or similar is necessary after making your changes to /etc/usbmount/usbmount.conf. They go into effect immediately.

  4. Plug in and use

    cd /media/usb
    touch beeblebrox
    
  5. Unmount

    punmount /media/usb
    

    Since we disabled the sync option, it is very good for your data integrity to unmount the USB drive before unplugging. This is done with punmount because we the automounter did so using pmount, which is nice, because we don't need to sudo first.

From now on, you can immediately use USB drives when plugged in, and no longer need fear the dreaded windozy coworker sneakernetting you a bunch of PDFs.