4

I have an external hard drive (WB My Passport), connected via a USB port. My OS is Elementary OS Freya on a Dell Vostro 1510.

Currently, in order to mount the drive, I have to open the file manager, and then click on its icon.

However, I would like this external hard drive to be mounted automatically when plugged in or when booting up.

1

2 Answers 2

2

Most of the modern Window Manager include an option in the File Manager (nautilus, caja, etc) to automatically mount the external hard drives.

In my example (Linux Mint with MATE) going to the System Preferences, File Manager, there is a section called "Removable Drives and Media" where you can enable / disable automatic mounting of external devices.

Also, you can do it this manually by editing /etc/fstab file and adding a line to automount the disk based on the UUID or LABEL of the filesystem. I can provide details if you're interested, but your Windows manager should be able to provide you a simple way of doing this.

Best regards,

7
  • With regard to Elementary OS (Freya) the File Manager doesn't have any option (at least no GUI access to such options). So an alternative would b welcome. Thanks. Commented Apr 19, 2015 at 18:38
  • Then mount your external filesystem and use (as root) the "blkid" command to get the UUID of your external disk. Then you can edit the /etc/fstab file and add an entry like "UUID=the-uuid-of-your-fs /your/mount/point ntfs auto,defaults,user 0 0" Commented Apr 19, 2015 at 18:59
  • Added to /etc/fstab entry: UUID=4E1AEA7B1AEA6007 /dev/sdb1 ntfs auto,defaults,user 0 0 but then the drive isn't detected at all. Commented Apr 22, 2015 at 16:58
  • Hi. The second parameter in your line is wrong, instead of /dev/sdb1 you have to put there the mount point (example: /mnt/mydrive). Create the directory first with mkdir -p /mnt/mydrive. Your drive is already identified by the UUID string, you don't need to identify it with the device filename /dev/sdX (and that device name will change to sdc if you plug another usb device first)... This fstab line is used when the system boots to automount the drive. If you want to automount it when you plug in while the system is started, then check "udev" / "automount". Commented Apr 22, 2015 at 21:25
  • 1
    If your Window manager does not provide the facility to automount any new drive present in the system (as does GNOME, KDE, MATE, XFCE, etc), you can use systems like udev and automount (they are not Xorg apps, they are "system services") to automatically mount drives. With udev, you edit a file in /etc/udev/rules.d/ and place there "rules" that define which kind of drives should be mounted and how. Check axllent.org/docs/view/auto-mounting-usb-storage for mor information. Commented Apr 23, 2015 at 13:47
1

Taking inspiration from this Ask Ubuntu answer, and after lot of tinkering, here's what I settled on: a udev rule that spawns a systemd (user) unit file to mount the volume using udisksctl.

Create this file under your own user account, first making intermediate directories as necessary (mkdir -p ~/.config/systemd/user):

# ~/.config/systemd/user/mount-backup-volume.service [Unit] Description=Mount backup volume on external USB drive [Service] Type=oneshot ExecStart=/usr/bin/udisksctl mount -b /dev/disk/by-id/usb-MFR_MODEL_SERIAL-0:0-partN 

You can get the actual /dev/disk/by-id/usb-MFR_MODEL_SERIAL-0:0-partN for your own device and partition from the output of udiskctl dump. You don't want to use something like /dev/sdb1, because that could change next reboot, depending on what other devices you have plugged in, in what order.

As root, using sudo vi or whatever is your preference:

# /etc/udev/rules.d/98-automount-backup.rules ACTION=="add", SUBSYSTEM=="block", ENV{ID_FS_UUID}=="THE-FILE-SYSTEMS-UUID", ENV{SYSTEMD_USER_WANTS}="mount-backup-volume.service" 

Get THE-FILE-SYSTEMS-UUID from the output of blkid /dev/sdXY when your device is mounted (e.g., sudo blkid /dev/sdb1), or search for IdUUID: in the output of udisksctl dump, associated with the desired device and partition.

The names mount-backup-volume.service and 98-automount-backup.rules are up to you; just make sure ENV{SYSTEMD_USER_WANTS} matches whatever you named the unit file. I didn't find that there was any need to "enable" the systemd unit file, or udevadm control --reload, as you might see suggested in some places; udev picks up on the changes as soon as you save the file in /etc/udev/rules.d.


Caveats

  • relies on systemd; probably somewhat Debian/Ubuntu specific in where the config files go exactly
  • is tedious if you want to do this for multiple volumes, or multiple partitions on a single device

You may want to look into using a mount helper like udiskie or udevil if you're doing this more than a couple times. That seems to be how the minimalist / tiling window manager crowd gets by.

Details

This rigmarole seems to be necessary because udev rules alone don't run with the permissions of the user. You might think that it'd be possible with su -c or something like that, but that was the very first thing I tried and didn't have any luck. I also didn't want to mess with /etc/fstab; this isn't a server. I'm the only user of the machine, and I want the device to be mounted on hotplug, not at boot-time.

Too bad this isn't simpler—more elementary-like. The only issue I'm aware of where this was proposed as a feature for Pantheon Files was eventually closed as WONTFIX without much out-in-the-open discussion.

I wanted something near to how Time Machine works on macOS, in that a backup would start soon after the device with the backups on it was plugged in. Back In Time got me pretty close, and it even has a "When drive get [sic] connected (udev)" option, but that doesn't actually mount the device for you. It assumes the desktop environment mounts it automatically, I guess. And as you know, elementary OS doesn't.

This is probably OK, because other operating systems' tendencies to mount everything mountable when you plug a device in—or nag you about it every time—is less preferable than elementary OS's default behavior.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.