SD Card via USB

I have a new BBB with Debian. I want the SD Card to appear on the USB port (to Host) rather than the internal memory. I find references to uDev.txt and modifying other files related to boot but it seems like it;s more for the pre Debain stuff. I have the card formatted and when I ssh in, I can see it mounted in /media so I am that far. I put a iDev.txt on that card. What else do I change?



You want to use the USB gadget to export the SD Card filesystem. This is similar to something I’m doing for an upcoming DEFCON talk. Here is the script for that talk:


stop the GETTY service if needed

if which ‘systemctl’ ; then
systemctl stop serial-getty@ttyGS0.service >/dev/null

unload current composite gadget

modprobe -r g_multi

these variables are used to export all partitions


unmount the USB drive

for d in $(ls /dev/sd*) ; do
if echo “$d” | egrep ‘[1-9]$’ >/dev/null ; then
umount $d
fstr=${fstr:1} # strip leading comma
rostr=${rostr:1} # strip leading comma
echo “$fstr” >/tmp/usbexports # save for later r/w export

now export it

vend=$(( 0x1337 )) # pick your favorite vid/pid
prod=$(( 0x1337 ))
echo “$vend” >/tmp/usbvend # save vid/pid for r/w export
echo “$prod” >/tmp/usbprod
modprobe g_multi file=$fstr cdrom=0 stall=0 ro=$rostr
removable=1 nofua=1 idVendor=$vend idProduct=$prod

wow Phil, way to over complicate g_multi heh.

nano /etc/modules → add ‘g_multi file=/path/to/sdcard’

No quotes.

The above is persistent, and by its self requires a system restart in order to become ‘active’ However you can also use modprobe to load the module without a restart. Using the exact same parameters. Like this:

$ sudo modprobe g_multi file=/path/to/sdcard

So for the inexperienced. g_multi will load all three USB gadget drivers. Equivalents to g_mass_storage, g_ether, and g_serial. In order to use the other gadgets, they must be configured. Also, for what it is worth, only one gadget driver can be loaded / used at a time. Hence the need for g_multi.

Sorry, I just pasted in my script that does way more so you could see the syntax for creating mass storage device. Shows how to keep other devices from going away. Part of my BBB based writeblocker for defcon.

heh ! No worries Phil I was mostly just giving you a hard time. As I’ve seen some vids you’ve done( reverse engineering, friend had vids ), and they were pretty good :slight_smile:

Oh and right. What D.R.Polstra outlines seems to work with systemd. What I explained will work with sysv for sure, but not so sure for systemd. Even though systemd is supposed to be backwards compatible with sysv blah blah blah . . .

Tried the suggestion below, no working. Perhaps path is /dev/etcetera not mounted drive?

As a code newbie, I guess I need a 1 2 3 type cookbook

The first time you plug in the thumb drive it should be /dev/sda. If you want the SD card its /dev/mmcXXblk where XX is either 00 or 01 depending on what you booted from. The part of my script that unmounts drives is unneeded for SD cards, but you still need to run modprobe -r g_multi to unload the default device which doesn’t export the SD card. Then if you run modprobe g_multi file=/dev/mmcXXblkXX it should show up on the PC.

I am booting from the onboard flash... Currently the drive shows as mounted on /media/volume_name when I say in via Ethernet

Thanks for your help

I am not trying to plug in a thumbdrive.

I want to boot from the BBB’s onboard flash and have the SDcard appear to the host computer as a USB drive.