I'm currently trying to write a couple of systemd/udev configuration files that will allow me to automount/unmount MTP Android devices on my Archlinux laptop. It took me some time, but so far it works pretty well.
Now, I would like for any user with fuse permissions to be able to unmount the device. So far, it's only possible for the same user as the one go-mtpfs was started as.
I'm well aware that MTP is designed so that you can just unplug the device without consequences, but having an error message pop up when clicking "Eject" in Nautilus is kind of unexpected and not really nice.
I tried the following, but failed :
- Add myself to the
fusegroup, startgo-mtpfsasrootand try to unmount as myself - Start
go-mtpfsas thefuseuser and group, and try to unmount as myself, also in thefusegroup
Any idea? Also, if you have an elegant way to achieve the same thing without having to rely on the fuse group, I'd love to hear about it!
systemd service (/etc/systemd/system/android-mtp.service) :
[Service]
Type=forking
ExecStartPre=/bin/mkdir -p /media/Android
ExecStart=/usr/sbin/daemonize -l /var/lock/go-mtpfs.lock /usr/bin/go-mtpfs -allow-other=true /media/Android
ExecStop=/bin/umount /media/Android
ExecStopPost=/bin/rmdir /media/Android
udev rule (/etc/udev/rules.d/99-android-mtp.rules) :
# Google Nexus 7 16 Gb Bootloader & recovery mode
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e40", MODE="0666" # Bootloader
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="d001", MODE="0666" # Recovery
# Google Nexus 7 16 Gb PTP mode (camera)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e43", MODE="0666" # PTP media
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e44", MODE="0666" # PTP media with USB debug on
# Google Nexus 7 16 Gb MTP mode (multimedia device)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e41", MODE="0666" # MTP media
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e42", MODE="0666" # MTP media with USB debug on
# Google Nexus 7 MTP mode : automatic unmount when unplugged (all android versions)
ENV{ID_MODEL}=="Nexus", ENV{ID_MODEL_ID}=="4e41", ACTION=="remove", RUN+="/usr/bin/systemctl stop android-mtp.service"
ENV{ID_MODEL}=="Nexus", ENV{ID_MODEL_ID}=="4e42", ACTION=="remove", RUN+="/usr/bin/systemctl stop android-mtp.service"
ENV{ID_MODEL}=="Nexus_7", ENV{ID_MODEL_ID}=="4e41", ACTION=="remove", RUN+="/usr/bin/systemctl stop android-mtp.service"
ENV{ID_MODEL}=="Nexus_7", ENV{ID_MODEL_ID}=="4e42", ACTION=="remove", RUN+="/usr/bin/systemctl stop android-mtp.service"
# Google Nexus 7 MTP mode : automatic mount when plugged (all android versions)
ENV{ID_MODEL}=="Nexus", ENV{ID_MODEL_ID}=="4e41", ACTION=="add", TAG+="systemd", ENV{SYSTEMD_WANTS}="android-mtp.service"
ENV{ID_MODEL}=="Nexus", ENV{ID_MODEL_ID}=="4e42", ACTION=="add", TAG+="systemd", ENV{SYSTEMD_WANTS}="android-mtp.service"
ENV{ID_MODEL}=="Nexus_7", ENV{ID_MODEL_ID}=="4e41", ACTION=="add", TAG+="systemd", ENV{SYSTEMD_WANTS}="android-mtp.service"
ENV{ID_MODEL}=="Nexus_7", ENV{ID_MODEL_ID}=="4e42", ACTION=="add", TAG+="systemd", ENV{SYSTEMD_WANTS}="android-mtp.service"
