I have a service that manages a USB key (format, mount/umount, read/write, check space) coded in Python 2. This service call system to manage the device (mount/umount, mkfs, state) and monitor /proc/mounts to check mounting status.

There are some tests to check the service behaviour, but I am unable to test the service without a real USB key but it's an issue for Jenkins slaves.

I tried to mount the loop device, but this technic require to modify the service to manage this specific device.

  • Do you know some technics to create a virtual device that behaves as a USB key?
  • Do you know a way to test this kind of service ?

Reading an artcle about Linux-USB Gadget API Framework, I found a way to mount a device as if it was a USB key using loop device (here):

  1. create a virtual drive :

    fallocate -l 128M /tmp/virtual_drive.img
  2. attach this as loop device:

    sudo losetup -o512 /tmp/virtual_drive.img /dev/loop0

Then this virtual device is used as-is by the service.

  • USB Gadgets and losetup aren't really related... From your question, I'd suggest that losetup alone doesn't achieve what you're after - emulating a USB mass storage device.
    – Attie
    Feb 21 '19 at 12:25
  • 1
    @Attie I am agree with you: what I meant was that by reading an article on USB gadget, I realized that losetup was enough. I was able to simplify the procedure without going as far as emulating the USB key.
    – chepseskaf
    Feb 22 '19 at 7:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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