How to rename qube via command line?

Is there a way to rename an existent qube via command-line only?

For existing qube test (test2 does not exist), I tried:

qvm-prefs test name test2

, got

qvm-prefs: error: Got empty response from qubesd. See journalctl in dom0 for details.

A different property like vcpus did work:

qvm-prefs test vcpus 1

Journalctl error:

AttributeError: property ‘name’ is write-once and already set

[duplicate…how did that happen?]

I believe that the “rename” option in the gui-based manager actually does a clone to the new name, then goes through and moves all dependencies to the new qube (i.e, if it’s a template, anything that uses that template gets reassigned to the new qube, likewise with default disposable VMs if that applies). Then the old qube is deleted. If you do a rename in the GUI-based manager, you can actually see a qube with your new name is created immediately, and for a while both qubes exist.

So if you want to do it on the command line, you have to reproduce that process. The clone (to new name) and delete (of the qube with the old name) is easy; reassigning dependencies on your old qube to the new one is trickier to automate (but obviously, it’s possible).

Caveat: I could be wrong about this, but it sure looks like it’s clone,-reassign-and-delete when I watch it happening. And sometimes, the last delete doesn’t happen because the system missed a dependency that needed to be switched [typically, a qube using itself as its dispvm], so you have qubes by both the old and new names for a while until you manually set things right.

1 Like

Very helpful, thanks @SteveC!

Concerning the manual solution: ouch… that probably would be a good feature request, as the solution should already be implemented for the GUI?

I’m actually thinking about generating a script that will go through the entire list of qubes and point all dependencies on to .

I’d be using it for recreating an existing template qube. I’d have to run it twice, once, where qube-A is the qube you want to recreate, and qube-B is some dummy qube you don’t use for anything else. Then delete qube-A and recreate it, Then run the script again, moving dependencies on the dummy qube back to the new version of the original qube.

Clearly you could use such a script on the command line. Clone your old qube. Run the script to point dependencies to the new clone. Delete the old clone. All three of those would be easy command line things.

That would at least give you a relatively easy command line way of doing what so far you can only do via the gui.

Again, I have to issue a caution: I’ve been using qubes for a whole month and a half. I could be totally off base. I hope that if I am someone will correct me.

You need to clone the vm and then remove the old one.
That’s how rename works in Qube Settings:
https://github.com/QubesOS/qubes-manager/blob/master/qubesmanager/settings.py#L59

2 Likes

@tzwcfg Much appreciate the code reference.

Looking at settings.py , qvm-clone seems to automatically carry over all qube properties to the new qube.

I guess something like following should then be sufficient (please correct otherwise):

qvm-clone old-appvm new-appvm
qvm-remove old-appvm

Yes, that’s how you should do it.
But don’t forget to check if the qube is cloned successfully before you remove the old one.

1 Like