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.
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"
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.