Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question
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. –  martin-mystere Dec 6 '12 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. –  Nicolas Delvaux Dec 6 '12 at 15:57
add comment

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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