Skip to content

Instantly share code, notes, and snippets.

@drygdryg
Last active March 15, 2025 07:53
Show Gist options
  • 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
@strongHunter
Copy link

If someone want to share the device using USBIP utility, make sure to add the stall=false flag to the command

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment