Run commands and copy files in --dispvm from dom0

I write scripts that make it easier to interact with dispvm. How can I run a command or copy a file to a new dispXXX? And it’s all from dom0
For example:

qvm-copy-to-vm dispXXX id_rsa
qvm-run dispXXX "mv ~/QubesIncoming/dom0/id_rsa ~/.ssh/"
qvm-run dispXXX "xfce4-terminal -e 'bash -c \"ssh user@1.2.3.4\"; bash'"

so I would do if dispXXX is already running. But how do you do that in a dispXXX that doesn’t yet exist?

qvm-run --dispvm=whonix-ws-16 --service qubes.StartApp+"Please copy my keys and connect to the server"

Any ideas?

According to “How to use disposables” (How to use disposables | Qubes OS) you can execute commands in a disposable like this:

$ qvm-run --dispvm=<DISPOSABLE_TEMPLATE> --service qubes.StartApp+xterm

As to the problem of how to direct the following commands to the same dispQube, perhaps using a named disposable (Glossary | Qubes OS) would help, since you could address that one individually?

(Being pretty much a Qubes-newbie I may be wrong, perhaps somebody more experienced can point out better ways of doing this.)

I’m currently using a named disposable, but that’s pretty damn awkward since I have to create hundreds of them, with scripts bound to the names of these named disposables, and I want the names to be variables.

This sounds as an oxymoron. I think it would be helpful to explain why you would want to use a specific, but not any dvm?

Maybe you should look at /usr/lib/qubes/qvm-actions.sh and try to customize it for your purposes. It would be nice to let us know about the final script anyway, since I have a similar need…

what do you mean by “want to use a specific, but not any dvm?” Actually, I want to use any that is generated when you run dispvm, but its name will be random among other such. Editing /usr/lib/qubes/qvm-actions.sh not quite the right solution, because I stick to default settings so as not to depend on crutches. The final script I see is this, at the moment of running dispvm run a loop that parses qvm-ls | grep Transient | awk '{print $1}' and assign a value to the dispvm name variable. rough but works

I have probably misread this as

how do you do that in a dispXXX that hasn’t been already started

Qubes tooling is a bit rigid in how it creates and starts the usual disp1234 DisposableVMs, but you can get full control by creating custom DispVM class VMs:

name=my-dispvm-$RANDOM
template=$(qubes-prefs default_dispvm)
qvm-create --class=DispVM --prop=auto_cleanup=True --label=red --template="$template" "$name"
qvm-copy-to-vm "$name" ...
qvm-run "$name" ...
...
qvm-kill "$name"
1 Like

I apologize wildly, I’m funny and ashamed at the same time. I understand how the system works and am completely unfamiliar with the English language.
Forgive me again and explain in a more accessible way what you mean.
I use a translator)) love<3

That’s the way I was thinking about it. But this creates permanent entries in the table (qvm-ls)
I believe that we should follow the principle of a one-time system, and an entry in the table destroys this idea.

No, that’s the magic of the --prop=auto_cleanup=True parameter: It ensures that whole DisposableVM is removed as soon as it shuts down.

It’s cool. This solved the problem elementarily. I created the vm this way but forgot to check the :slight_smile: However, nothing prevented me from using qvm-remove in the script, but it turned out that there is a special parameter. In either case, the script must include commands to create the vm. Thank you for helping to understand

Hello. Thank you, I still use this but there was another problem.
After close the application in regular dispVM, the dispVM halted automatically. Created by dispVM in our way, does not turn off automatically after closing the application
How can this be done in our case?