我有一部 Alcatel One Touch 4045D 安卓手机。
直到我将 ID 添加到 后,它才在 Ubuntu 中安装/lib/udev/rules.d/69-libmtp.rules
。
但手机会以带有“USB 驱动程序”的 CD 形式安装。如果我弹出该 CD,手机就会正常安装。
看起来手机固件正在尝试检测是否安装了某些驱动程序,如果没有,则将其作为带有驱动程序的磁盘安装。
udev 规则中是否有自动弹出该磁盘的选项?
lsusb; lsusb -t & udevadm monitor -u
当我插入手机时的输出:
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
这是我弹出 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)
答案1
创建新的规则文件:
sudo nano /etc/udev/rules.d/99-eject-virtual-cd.rules
添加此规则
ACTION=="add", KERNEL=="sr[0-9]*", ATTRS{idVendor}=="1bbb", ATTRS{idProduct}=="af00", RUN+="/bin/sh -c 'eject /dev/%k'"
重新加载规则
sudo udevadm control -R
重新插上手机进行检查