2

I have an app that implements some automations when an USB key is plugged.

While developing, I have to test it in a specific environment (derivative from Debian Squeeze).
The app subscribe to HAL events via DBUS.
The problem is: my desk is on the third floor while my test machines are in the basement.

I would really like to have a way to simulate a USB plug.

  • usbip does not work on Ubuntu.
  • I can't manage to use the g_mass_storage module on Ubuntu (I lack the dummy_hcd module) and in Debian.

Maybe it is possible to simulate a dbus call?

My work station is on Ubuntu 12.04.

2
  • 2
    If you don't need that key to be plugged in this particular hardware, you could use virtualbox (with the extension pack) !? It use it very often. Dec 6, 2012 at 15:48
  • @martin-mystere: this is indeed a simple solution (it also works with Qemu) but, for testing purposes, I would prefer using the dedicated systems. These machines in the basements are connected with other systems (it's the pre-production platforms) and it's really hard to fully replicate it with virtual machines. Thanks anyway, this is what I will use for now until I find something better. Dec 6, 2012 at 15:57

1 Answer 1

2

I found another solution that suited me. In fact I realised that I did not really need to simulate an USB drive, but rather any type of storage device (my app watches HAL or UDisks for "DeviceAdded" events).

So I did the following:

  • create a filesytem image, for example with the "virt-make-fs" command
    sudo virt-make-fs --type=ntfs -- fs.tar.gz fs-test.img

  • upload the img file on the test machine

  • setup the image as a loop device: sudo losetup /dev/loop0 fs-test.img

And that's it, UDisks just triggered the "DeviceAdded" DBus event!
(however, HAL does not trigger anything in this case, so it's a good opportunity to drop it since it is deprecated)

If you want, you can manually mount the image with something like sudo mount /dev/loop0 /mnt/fs.

If you need to use pmount, don't forget to add /dev/loop0 to /etc/pmount.allow.

To unset the loop device, just use sudo losetup -d /dev/loop0.

1
  • 1
    While this is an answer that worked for you in this particular instance, the answer itself has nothing to do with the original question. Google lead me here while trying to find out how to simulate a USB mass storage device. What I'm saying is that you probably should not have marked your own answer as the correct solution. :)
    – holmb
    Oct 21, 2016 at 9:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .