Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A Raspberry Pi Zero can appear to a computer as a removable USB drive: the Pi exports a disk-image file stored on its microSD card through USB device mode. Create and format the image, add the files, then load the USB mass-storage gadget driver. For a safer read-only drive, use the command shown below with ro=1.

What you need and where to plug in

  • A Raspberry Pi Zero, Zero W, or Zero 2 W running Raspberry Pi OS.
  • A microSD card with enough free space for the disk image and operating system.
  • A micro-USB data cable. Connect it to the micro-USB port closest to the HDMI connector; that is the OTG/device port. The separate PWR IN connector is not the gadget port.

Raspberry Pi’s USB gadget-mode guidance says the OTG port is dedicated to gadget networking and device functions while gadget mode is active. It cannot simultaneously operate as a regular USB host port.

Create and prepare the virtual drive

The drive is a file on the Pi, not a separate physical USB stick. The host computer sees that file as a removable disk when the mass-storage gadget driver exports it. Raspberry Pi’s official virtual USB flash-drive tutorial uses a 2GB image as an example; choose a size that fits your card’s available space.

  1. Create the image: sudo dd bs=1M if=/dev/zero of=/piusb.bin count=2048. This example creates a 2GB file; it is not a universal capacity limit.
  2. Format it as FAT32: sudo mkdosfs /piusb.bin -F 32 -I.
  3. Mount the image locally and copy files into it. Follow the tutorial’s mount-and-copy workflow; ensure the mount point exists before mounting. When finished, unmount the image and flush pending writes with sync.
  4. Export the image: sudo modprobe g_mass_storage file=/piusb.bin stall=0 ro=1. Connect the Pi to the host using the OTG port and a data-capable cable. With ro=1, the host can read the virtual drive but cannot write to it.
  5. Stop exporting it: when the host is finished, safely eject the disk on the host, then run sudo modprobe -r g_mass_storage on the Pi.

Choose read-only or writable access

Mode What it means Best fit Care required
Read-only (ro=1) The host can read files but cannot change the image. Appliances or other hosts that only need to consume files. To update files, stop the gadget first and make changes from the Pi.
Writable (omit ro=1) The host can write to the exported filesystem. Cases where the host needs to add or modify files. Only one system should write to the filesystem at a time. Eject it on the host and stop the gadget before accessing the image locally.

Do not let the Pi and host access or write the same filesystem at the same time. While exported, treat the image as owned by the host. Concurrent access risks filesystem corruption.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
SANOOV Raspberry Pi Zero 2W Kit
  • Powerful Performance: Equipped with a quad-core 64-bit ARM Cortex-A53 processor, the Raspberry Pi Zero 2 W delivers a significant performance boost compared to its predecessor. And built-in Wi-Fi and Bluetooth support enable easy wireless communication and Internet access for your projects, five Times Faster.
  • SANOOV Basic Starter Kit for Pi Zero 2 W Include: 1. Raspberry Pi Zero 2 W Board 2.Mini HDMI to Standard HDMI adapter 3.Micro-USB to Standard USB OTG Adapter 4.Aluminum Heatsink 5.40 Pin Header.NOTICE: The kit does NOT include , supply power, case, SD card, keyboard, mouse or monitor.
  • SANOOV for Raspberry Pi Zero 2 W features: 1GHz quad-core, 64-bit ARM Cortex-A53 CPU VideoCore IV GPU 512MB LPDDR2 DRAM 802.11b/g/n wireless LAN Bluetooth 4.2 / Bluetooth Low Energy (BLE) MicroSD card slot Mini HDMI and USB 2.0 OTG ports Micro USB power HAT-compatible 40-pin header Composite video and reset pins via solder test points CSI camera connector.
  • Video Output & Efficient Cooling: Supports 1080p30 video output via the mini HDMI port, making it ideal for multimedia applications and streaming.The aluminum heatsink helps dissipate heat, ensuring stable performance even under heavy workloads.
  • Compact Size: The tiny size of the Raspberry Pi Zero 2 W makes it perfect for space-constrained projects and embedded applications.Ideal for a variety of uses, including IoT projects, home automation, media centers, educational tools, and more.

Set the capacity and understand the limits

The virtual stick’s capacity is the size of its backing image, limited by free space on the Pi’s microSD card. The tutorial’s 2GB image is an example, not a stated maximum. The cited Raspberry Pi sources do not provide a general USB-throughput benchmark for the Pi Zero family, so no reliable MB/s figure can be promised here.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When to use configfs instead

The single g_mass_storage command is the simpler option when exporting one image. For more explicit LUN configuration or a composite gadget that combines mass storage with other USB functions, Raspberry Pi’s OTG application note describes configuring a backing file such as /home/pi/drive.bin through configfs.

Rank #2
CanaKit Raspberry Pi 4 4GB Starter PRO Kit - 4GB RAM
  • Includes Raspberry Pi 4 4GB Model B with 1.5GHz 64-bit quad-core CPU (4GB RAM)
  • Includes Pre-Loaded 32GB EVO+ Micro SD Card (Class 10), USB MicroSD Card Reader
  • CanaKit Premium High-Gloss Raspberry Pi 4 Case with Integrated Fan Mount, CanaKit Low Noise Bearing System Fan
  • CanaKit 3.5A USB-C Raspberry Pi 4 Power Supply (US Plug) with Noise Filter, Set of Heat Sinks, Display Cable - 6 foot (Supports up to 4K60p)
  • CanaKit USB-C PiSwitch (On/Off Power Switch for Raspberry Pi 4)

Pi Zero or Zero 2 W?

Raspberry Pi’s gadget-mode guidance covers the Zero, Zero W, and Zero 2 W, and the USB-gadget approach is the same across those boards. The Zero 2 W is the newer platform; the cited guidance does not establish a distinct mass-storage setup or throughput figure for it.

Quick Recap

Bestseller No. 1
Bestseller No. 2
CanaKit Raspberry Pi 4 4GB Starter PRO Kit - 4GB RAM
CanaKit Raspberry Pi 4 4GB Starter PRO Kit - 4GB RAM
Includes Raspberry Pi 4 4GB Model B with 1.5GHz 64-bit quad-core CPU (4GB RAM); Includes Pre-Loaded 32GB EVO+ Micro SD Card (Class 10), USB MicroSD Card Reader
$159.99

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.