A way to autoattach an external drive when a appvm starts up?

Is there a way to setup an external usb drive, that is always plugged in, to attach and mount to a specific appvm when that appvm is started?
I have a use case for one of my appvms where I need a fair amount of disk space but its only that appvm, so it would be great to have, when that appvm is started, for the ext drive attached and mounted automatically, that should be possible right? If so any pointers on how would really be appreciated.
PS I am assuming its relevant to mention that I am using a sys-usb vm


Thanks, yeah I guess I should have mentioned that I saw that post and looked over his blog - but its more complicated (and I think a bit more in terms of what it can do) than I need (or can understand).
It was my hope that I could add a line to my a .desktop file that would attach the device and then I think i could add a mount Hardware block device ID?
Maybe that not possible but I was hoping for something that might be a bit simpler (and admittedly less flexible) for me to understand

I did set up a way for a qube to request that a USB block device be attached to it…but it also involved writing a service on dom0 called by that qube. In my case it’s a bit more complex because there may be multiple devices attached; so my qube first gets a list of devices from dom0 (via a service call), then lets you select one if there is more than one (I use a zenity popup for this). If there’s only one, it just goes ahead and asks dom0 to attach that one. I also preferentially attach the first sub-device of the usb drive (sda1 instead of sda) if there is one because most thumbdrives are formatted that way. (I have a few that just have nothing but a single ext4 partition on them…most systems won’t read that automatically.)

What I didn’t do was set it up to happen automatically on startup, but I did put a shortcut on my desktop to send the request. Clicking on that starts the qube (if it’s not already running) and sends the request, so it’s virtually the same as setting the qube up to do it on startup.

1 Like

You can do this with libxl hook:

I was talking about starting up the qube that the device was supposed to attach to, not sys-usb itself. I guess I wasn’t clear.

The services I wrote do assume sys-usb is running (on my system it will be), but it would be easy to tweak them to instead look for devices managed by dom0. It really doesn’t matter because dom0 does the re-assigning in either case. Someone not using sys-usb could use something similar.

The script in my link is doing exactly this: it’ll start a qube myvmname when sys-usb is started and USB device my-usb-device-name-or-id is available to be attached.

I guess @stumpi can use this hook to attach USB device on appvm startup as well.


Maybe you should write a guide/article on this, looks interesting.