Skip to content

Instantly share code, notes, and snippets.

@drygdryg
Last active December 17, 2023 20:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drygdryg/26795b9e454e08659248c8ef20e9be45 to your computer and use it in GitHub Desktop.
Save drygdryg/26795b9e454e08659248c8ef20e9be45 to your computer and use it in GitHub Desktop.
How to emulate USB flash drive in Linux

Emulating mass storage USB flash devices in Linux

Create a new disk image with space pre-allocation (4000 MBytes):

fallocate -l 4000M virtual_usb.img

Create Ext4 file system:

mkfs -t ext4 virtual_usb.img

Load the necessary modules:

sudo modprobe dummy_hcd
sudo modprobe g_mass_storage file=virtual_usb.img idVendor=0x8564 idProduct=0x1000 iSerialNumber=C71FFD58CDF9 iManufacturer="JetFlash" iProduct="Mass Storage Device" removable=true cdrom=false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment