Created
March 22, 2026 18:21
-
-
Save seidler2547/93604a1d3a0b6c4185baa6974c783e3b to your computer and use it in GitHub Desktop.
How to make an SBC appear as USB storage device and have access to the files via Samba
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| while : | |
| do | |
| sleep 1 | |
| if [ -e /mnt/write ] | |
| then | |
| if grep -q usb /sys/kernel/config/usb_gadget/g1/UDC | |
| then | |
| sync | |
| echo '' > /sys/kernel/config/usb_gadget/g1/UDC | |
| sync | |
| umount /mnt/usb | |
| fsck -y /dev/loop0p1 | |
| mount -o rw /mnt/usb | |
| fi | |
| else | |
| if ! grep -q . /sys/kernel/config/usb_gadget/g1/UDC | |
| then | |
| sync | |
| mount -o remount,ro /mnt/usb | |
| sync | |
| echo musb-hdrc.1.auto > /sys/kernel/config/usb_gadget/g1/UDC | |
| fi | |
| fi | |
| done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| modprobe libcomposite | |
| modprobe usb_f_mass_storage | |
| mkdir /sys/kernel/config/usb_gadget/g1 | |
| cd /sys/kernel/config/usb_gadget/g1 | |
| echo 0xabcd > idVendor | |
| echo 0x1234 > idProduct | |
| mkdir strings/0x409 | |
| echo myserial > strings/0x409/serialnumber | |
| echo mymfg > strings/0x409/manufacturer | |
| echo myproduct > strings/0x409/product | |
| mkdir configs/c.1 | |
| echo 120 > configs/c.1/MaxPower | |
| mkdir functions/mass_storage.0 | |
| echo /dev/mmcblk0p3 > functions/mass_storage.0/lun.0/file | |
| ln -s functions/mass_storage.0 configs/c.1 | |
| echo musb-hdrc.1.auto > UDC | |
| cd | |
| losetup --partscan /dev/loop0 /dev/mmcblk0p3 | |
| mount -o ro /mnt/usb | |
| mount -o remount,sync / | |
| echo 100 > /proc/sys/vm/dirty_expire_centisecs | |
| bash -c 'cd /sys/kernel/config/usb_gadget/g1/functions/mass_storage.0/lun.0/ ; while :; do sleep 1 ; grep -q /dev/mmcblk0p3 file || echo /dev/mmcblk0p3 > file ; echo 1 > /proc/sys/vm/drop_caches ; done &' & | |
| bash -c '/root/auto-switch.sh &' & |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment