3

Is it possible to format a Raspberry Pi Zero to automatically mount as a hard drive when plugged into a computer via USB? If so, are there any available tutorials or resources to help me achieve this?

3
  • Stephan, welcome to the RPi flavored corner of Stack Exchange. As is, your question is way too broad to be reasonably answered in this format. I suggest you take the tour and take a look at what kind of questions work well here.
    – Jacobm001
    Commented May 8, 2017 at 20:25
  • Your project has a ton of moving parts. If you need help from us, you'll need to break it down into much, much smaller and more manageable pieces. Presenting as a mountable device, being powered by a battery, and interfacing with Dropbox are all completely separate projects and can be rather involved in their own right.
    – Jacobm001
    Commented May 8, 2017 at 20:26
  • Thanks for the advice! I'll try moving forward with just one part at a time. Commented May 8, 2017 at 20:33

1 Answer 1

3

I used this to create a 1.5 MB Pi USB memory stick:

g_mass_storage - To have your Pi Zero appear as a mass storage device (flash drive), first create a mini filesystem in a file on your Pi with:

    dd if=/dev/zero of=./piusb.bin bs=512 count=2880

and set it up as a fat32 filesystem with

    mkdosfs ./piusb.bin

Then load the drive use:

    sudo modprobe g_mass_storage file=./piusb.bin stall=0

Of course you can make the piusb.bin file as large as you want your USB file system to be. 512 bytes * 2880 = 1.5 MB

Thanks to this Raspberry Pi forum posting I found that if you use g_multi instead of g_mass_storage (or in fact g_serial and g_ether) you can use all of the USB gadgets!!!

Therefore you want the following in your /etc/rc.local:

    /bin/sleep 5
    /sbin/modprobe g_multi file=/home/pi/piusb.bin

As an added plus you can now also use screen to get to the console of your Pi using the command:

    screen /dev/ttyACM0 115200

You may need to enable serial console using the command:

    sudo systemctl enable [email protected]
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.