[Unit]
Description=Trigger USB mass storage
After=usb-gadget.target
[Service]
Type=oneshot
ExecStart=/root/g_usb.sh
[Install]
WantedBy=usb-gadget.target
然后,将这个配置文件保存为 /etc/systemd/system/lzyor-gusb.service
,并运行 sudo systemctl daemon-reload
和 sudo systemctl enable lzyor-gusb.service
来启用这个服务。
#!/bin/sh
modprobe libcomposite
# mount -t configfs none /sys/kernel/config
cd /sys/kernel/config/
cd usb_gadget
mkdir g1
cd g1
echo "0x04D8" > idVendor
echo "0x1234" > idProduct
mkdir strings/0x409
echo "0123456789" > strings/0x409/serialnumber
echo "Microchip Technology, Inc." > strings/0x409/manufacturer
echo "Linux USB Gadget" > strings/0x409/product
mkdir functions/mass_storage.usb0
echo "/dev/mmcblk0p1" > functions/mass_storage.usb0/lun.0/file
mkdir configs/c.1
mkdir configs/c.1/strings/0x409
echo "Lzyor USB mass storage" > configs/c.1/strings/0x409/configuration
ln -s functions/mass_storage.usb0 configs/c.1
# ll /sys/class/udc/
echo "fcc00000.usb" > UDC