19

I want to stop a USB device from automounting in Ubuntu 13.04. For example, when I connect my iPhone 5 to my desktop I am consistently prompted for what I want to do (whether or not I want to erase the "iPod" connected to my machine, etc). Since I don't use the computer as anything more than a way to charge the device, is there a way to prevent the device from mounting and still allow the device to draw current from the machine?

Anwar
  • 76,649
Mark D
  • 755

2 Answers2

16

Using the terminal and gedit

First find the ID for your device from a terminal using lsusb when your device is connected (eg 0951:1692). Also you should to find what is the name of your device with lsblk. Let say the name is /dev/sdb1.

Create a new script, let say unmount.sh in /lib/udev with sudo -H gedit /lib/udev/unmount.sh and put next lines inside:

#!/bin/bash

udisks --unmount /dev/sdb1
udisks --detach /dev/sdb

Save the file, close it and make it executable with:

chmod +x /lib/udev/unmount.sh

Now, you must to make a new rule file in /etc/udev/rules.d/ with sudo -H gedit /etc/udev/rules.d/100-unmount-iphone.rulesand put a new rule in there like this:

ACTION=="add", ATTRS{idVendor}=="0951", ATTRS{idProduct}=="1692", RUN+="/lib/udev/unmount.sh"

enter image description here enter image description here enter image description here

To reload udev rules without restart, use next command:

sudo udevadm control --reload-rules

Using Cuttlefish

Or, another way is to install and use Cuttlefish Install comixcursors-lefthanded - a simple tool that realises reflexes on your computer.

Radu Rădeanu
  • 169,590
  • Oh well, looks like Cuttlefish is no longer available – Antony Sep 25 '14 at 02:29
  • I have installed Cuttlefisth just now on Ubuntu 14.04 – Anwar Jan 31 '15 at 15:05
  • used udisksctl in unmount.sh to unmount a Windows partition from a USB flash drive: udisksctl unmount --block-device /dev/sr1. for reference: http://udisks.freedesktop.org/docs/latest/udisksctl.1.html – Martin Zeitler Nov 09 '15 at 03:17
  • 1
    For those without udisks, you can also use umount /dev/sdb1 to unmount the drive and eject /dev/sdb to detach it (it will no longer show up on the sidebar of the file browser). This can also be done by UUID instead (umount /dev/disk/by-uuid/<UUID>), in case having other USB devices plugged in changes the device name (i.e. /dev/sdb becomes /dev/sdc) – Brandon Miller Sep 20 '20 at 04:35
  • Came here to do this for my iPhone. In that case a one-liner rules.d seems to work. Create the file: sudo -H gedit /etc/udev/rules.d/100-unmount-iphone.rules. Add this line: SUBSYSTEM=="usb", ACTION=="remove", ENV{ID_MODEL}=="iPhone", RUN+="/usr/bin/killall -s SIGINT /usr/lib/gvfs/gvfsd-afc". Source: https://askubuntu.com/questions/581810/iphone-does-not-unmount-properly-when-unplugged – Stiin Sep 19 '22 at 16:13
0

To control which programs automatically start when you plug in a device, go to

System-Settings - Details - Removable Media

enter image description here

Source: Ubuntu Documentation - Mount/USB

Sergio
  • 121