Ubuntu – How to automatically eject drivers disk when mounting Android phone

alcatelandroidautomount

I have an Alcatel One Touch 4045D android phone.

It did not mount in Ubuntu until I added the IDs to /lib/udev/rules.d/69-libmtp.rules.

But the phone mounts as a CD with "USB Driver". If I eject that CD, then the phone mounts normally.

It looks like the phone firmware is trying to detect if some driver is installed and if not mounts as a disk with the driver.

Is there an option in udev rules to automatically eject this disk?

Output of lsusb; lsusb -t & udevadm monitor -u when I plug in the phone:

Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 002: ID 048d:1336 Integrated Technology Express, Inc. SD/MMC Cardreader
Bus 002 Device 003: ID 1bbb:af00 T & A Mobile Phones 
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 002: ID 04b8:0898 Seiko Epson Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 002: ID 046d:c05a Logitech, Inc. M90/M100 Optical Mouse
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
[1] 10998
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing

/:  Bus 07.Port 1: Dev 1, Class=root_hub, Driver=ohci-pci/2p, 12M
/:  Bus 06.Port 1: Dev 1, Class=root_hub, Driver=ohci-pci/3p, 12M
/:  Bus 05.Port 1: Dev 1, Class=root_hub, Driver=ohci-pci/3p, 12M
/:  Bus 04.Port 1: Dev 1, Class=root_hub, Driver=ohci-pci/3p, 12M
    |__ Port 1: Dev 2, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
/:  Bus 03.Port 1: Dev 1, Class=root_hub, Driver=ohci-pci/3p, 12M
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M
    |__ Port 1: Dev 3, If 0, Class=Mass Storage, Driver=usb-storage, 480M
    |__ Port 3: Dev 2, If 0, Class=Mass Storage, Driver=usb-storage, 480M
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M
    |__ Port 2: Dev 2, If 0, Class=Vendor Specific Class, Driver=, 480M
    |__ Port 2: Dev 2, If 1, Class=Printer, Driver=usblp, 480M
    |__ Port 2: Dev 2, If 2, Class=Mass Storage, Driver=usb-storage, 480M

This is the output when I eject the CD:

UDEV  [44405.211303] remove   /devices/pci0000:00/0000:00:13.2/usb2/2-1/2-1:1.0/host10/target10:0:0/10:0:0:0/bsg/10:0:0:0 (bsg)
UDEV  [44405.212494] remove   /devices/pci0000:00/0000:00:13.2/usb2/2-1/2-1:1.0/host10/target10:0:0/10:0:0:0/scsi_device/10:0:0:0 (scsi_device)
UDEV  [44405.212539] remove   /devices/virtual/bdi/8:64 (bdi)
UDEV  [44405.212817] remove   /devices/pci0000:00/0000:00:13.2/usb2/2-1/2-1:1.0/host10/target10:0:0/10:0:0:0/scsi_disk/10:0:0:0 (scsi_disk)
UDEV  [44405.214150] remove   /devices/pci0000:00/0000:00:13.2/usb2/2-1/2-1:1.0/host10/target10:0:0/10:0:0:0/scsi_generic/sg5 (scsi_generic)
UDEV  [44405.214811] remove   /devices/pci0000:00/0000:00:13.2/usb2/2-1/2-1:1.0/host10/target10:0:0/10:0:0:0/block/sde (block)
UDEV  [44405.216890] remove   /devices/pci0000:00/0000:00:13.2/usb2/2-1/2-1:1.0/host10/target10:0:0/10:0:0:0 (scsi)
UDEV  [44405.232937] remove   /devices/pci0000:00/0000:00:13.2/usb2/2-1/2-1:1.0/host10/target10:0:0/10:0:0:1/bsg/10:0:0:1 (bsg)
UDEV  [44405.233453] remove   /devices/pci0000:00/0000:00:13.2/usb2/2-1/2-1:1.0/host10/target10:0:0/10:0:0:1/scsi_generic/sg6 (scsi_generic)
UDEV  [44405.234138] remove   /devices/pci0000:00/0000:00:13.2/usb2/2-1/2-1:1.0/host10/target10:0:0/10:0:0:1/block/sr1 (block)
UDEV  [44405.235900] remove   /devices/virtual/bdi/11:1 (bdi)
UDEV  [44405.236151] remove   /devices/pci0000:00/0000:00:13.2/usb2/2-1/2-1:1.0/host10/target10:0:0/10:0:0:1/scsi_device/10:0:0:1 (scsi_device)
UDEV  [44405.237304] remove   /devices/pci0000:00/0000:00:13.2/usb2/2-1/2-1:1.0/host10/target10:0:0/10:0:0:1 (scsi)
UDEV  [44405.238416] remove   /devices/pci0000:00/0000:00:13.2/usb2/2-1/2-1:1.0/host10/target10:0:0 (scsi)
UDEV  [44405.260852] remove   /devices/pci0000:00/0000:00:13.2/usb2/2-1/2-1:1.0/host10/scsi_host/host10 (scsi_host)
UDEV  [44405.261862] remove   /devices/pci0000:00/0000:00:13.2/usb2/2-1/2-1:1.0/host10 (scsi)
UDEV  [44405.262597] remove   /devices/pci0000:00/0000:00:13.2/usb2/2-1/2-1:1.0 (usb)
UDEV  [44405.267755] remove   /devices/pci0000:00/0000:00:13.2/usb2/2-1 (usb)
UDEV  [44405.650792] add      /devices/pci0000:00/0000:00:13.2/usb2/2-1 (usb)
UDEV  [44405.652229] add      /devices/pci0000:00/0000:00:13.2/usb2/2-1/2-1:1.0 (usb)

Best Answer

  1. Create new rules file:

    sudo nano /etc/udev/rules.d/99-eject-virtual-cd.rules
    
  2. Add this rule

    ACTION=="add", KERNEL=="sr[0-9]*", ATTRS{idVendor}=="1bbb", ATTRS{idProduct}=="af00", RUN+="/bin/sh -c 'eject /dev/%k'"
    
  3. Reload the rules

    sudo udevadm control -R
    
  4. Replug the phone to check

Related Question