How to attach and mount USB sticks to disposable template in dom0 terminal?

I think it’s implemented in Qubes 4.2, because I could do this by GUI(just right-click the usb-stick tray icon). However, I don’t know the exact command of this in the dom0 CLI environment.

I already know qvm-run --dispvm = %Disposable template name% --service qubes.StartApp, but this doens’t help in this case…

So I would like to ask the exact command to attach an USB stick to instantly created disposable VM from the designated diposable template.

Not clear to me - do you want to attach device to disposable at start or
to attach to existing started disposable?
What do you want to do, and why?

I never presume to speak for the Qubes team. When I comment in the Forum I speak for myself.

There’s no such command, but it could be done with the qubesadmin Python module. Here’s the GUI implementation as a starting point:

Actually, the only tricky part is getting the disp1234 name of a new disposable.

Using Python:

# instead of None for the default, a disposable template could be specified in double quotes
disp=$(python3 -c 'import qubesadmin; d = qubesadmin.vm.DispVM.from_appvm(qubesadmin.Qubes(), None); d.start(); print(d.name)')

Or using qubesd-query:

disp_template=dom0  # dom0 means use the default disposable template
readarray -d '' -s 1 disp < <(qubesd-query --empty --fail dom0 admin.vm.CreateDisposable "$disp_template")
wait $!
qvm-start "$disp"

Then the rest can be done with qvm-block:

qvm-block attach "$disp" ...
1 Like

Oh, the former one. The reason why : I have many disposable templates and sometimes some of them are not displayed in GUI panel(especially usb). In that case, I need to use CLI to execute them.