linked clone does not work anymore via cli

This is for discussing general topics about how to use VirtualBox.
Post Reply
Ooiba
Posts: 3
Joined: 26. Aug 2025, 20:46
Primary OS: Linux other
VBox Version: OSE other
Guest OSses: archlinux

linked clone does not work anymore via cli

Post by Ooiba »

Code: Select all

vboxmanage clonevm myvm  --register --options=Link
VBoxManage: error: Linked clone can only be created from a snapshot
VBoxManage: error: Details: code NS_ERROR_INVALID_ARG (0x80070057), component MachineWrap, interface IMachine, callee nsISupports
VBoxManage: error: Context: "CloneTo(trgMachine, mode, ComSafeArrayAsInParam(options), progress.asOutParam())" at line 757 of file VBoxManageMisc.cpp
The GUI version works: Right click on the VM -> Clone -> linked clone

Code: Select all

vboxmanage clonevm myvm '--name=myvm2' --register '--snapshot=mysnapshot' --options=Link
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Machine has been successfully cloned as "myvm2"
The GUI equivalent works the same: Right click on the snapshot -> Clone -> linked clone

BUT:
The latter doesnt produce a correct linked clone based off the snapshot. "mysnapshot" contains a Win11 Guest with desktop shortcuts - but the cloned snapshot tries to install Win11 from scratch (GUI as well as CLI). The correct linked clone is created with the GUI Version of 1.

Code: Select all

vboxmanage -v
7.2.6r172322
klaus
Oracle Corporation
Posts: 2013
Joined: 10. May 2007, 14:57

Re: linked clone does not work anymore via cli

Post by klaus »

Your finding is correct, but not new at all. If you want to use VBoxManage to create a linked clone of a VM without snapshots, or of the "current state" of a VM which has snapshots, then you first need to create a snapshot using the appropriate command.

That it 'works' using the GUI is purely because the GUI implicitly creates the necessary snapshot before creating the linked clone. Nothing magic whatsoever.

Your observation that creating a linked clone of a certain snapshot isn't giving you the latest state of that VM should be obvious: the snapshot was created some time back, and it doesn't change. The VM's "current state" does, and if you want a linked clone of that, create a new snapshot so that you get the intended state.

The CLI is sometimes simply more basic, and then you need several VBoxManage commands to reach the target.

To repeat: this is the VBoxManage behavior for many years.
Ooiba
Posts: 3
Joined: 26. Aug 2025, 20:46
Primary OS: Linux other
VBox Version: OSE other
Guest OSses: archlinux

Re: linked clone does not work anymore via cli

Post by Ooiba »

Ok, there is an existing snapshot - i did that in my script instinctively right

Code: Select all

vboxmanage snapshot myvm take "thesnapshot"
vboxmanage clonevm myvm --name="myvm2" --register --snapshot="thesnapshot" --options=Link
The script worked until I tried it last week again. I guess the only difference is a vbox update?

Restoring to "thesnapshot" and booting it results in a desktop with icons and such - the linked myvm2 tries to reinstall windows.

I just tested again: creating a new snapshot actually works.
So we have this:

Code: Select all

SnapshotName="initial
SnapshotName-1="thesnapshot
CurrentSnapshotName="thesnapshot
CurrentSnapshotNode="SnapshotName-1

Code: Select all

vboxmanage clonevm myvm --name="myvm2" --register --snapshot="thesnapshot" --options=Link
does not work (installs windows)
while "restore" to that snapshot does not (!)

Code: Select all

vboxmanage snapshot myvm restore thesnapshot
vboxmanage snapshot myvm take test
vboxmanage clonevm myvm --name="myvm2" --register --snapshot="test" --options=Link
works

Code: Select all

SnapshotName="initial
SnapshotName-1="thesnapshot
SnapshotName-1-1="test"
CurrentSnapshotName="test"
CurrentSnapshotNode="SnapshotName-1-1"
What is the difference? I would expect "test" and "thesnapshot" to be same-ish?

This workarounds my problem nontheless - I just dont understand why that happens
klaus
Oracle Corporation
Posts: 2013
Joined: 10. May 2007, 14:57

Re: linked clone does not work anymore via cli

Post by klaus »

Very odd - what you describe does sound like a behavior difference at the API level, but I can't find a related modification "recently".
Galactic
Posts: 83
Joined: 28. Apr 2016, 04:52

Re: linked clone does not work anymore via cli

Post by Galactic »

If your script actually does give every snapshot the same name, then when you create the clone, it will be linked to the very first snapshot it finds with that name rather than the most recent one. I'm not sure if this behavior has ever been different. I'm only just testing it now.

If that is the cause, it also explains why using a new snapshot name (e.g. "test") works fine.
Ooiba
Posts: 3
Joined: 26. Aug 2025, 20:46
Primary OS: Linux other
VBox Version: OSE other
Guest OSses: archlinux

Re: linked clone does not work anymore via cli

Post by Ooiba »

What do you mean "give every snapshot the same name" there are 2 snapshots
"initial" and "thesnapshot".
When reverting back to "thesnapshot" - icons appear on desktop
When cloning the snapshot - windows wants to be installed
When reverting back to "thesnapshot", creating a new snapshot "test" and cloning "test" - icons appear on desktop

Indeed I change the script some time ago by adding a second snapshot (before "thesnapshot") - I'll investigate, if that might cause the problem (and also if use of UUIDs would fix that)
Galactic
Posts: 83
Joined: 28. Apr 2016, 04:52

Re: linked clone does not work anymore via cli

Post by Galactic »

You never said anything about removing snapshots, so I assumed it was possible you are running that script, or these other troubleshooting steps, with the same name multiple times.

Regardless, the clone's disk is not linked to the expected parent disk. So anything that might tease out the circumstances in what that happens would be helpful. That means trying a different snapshot name, trying the UUID instead, etc.

It would also be helpful to look at the Virtual media Manager and see which disk/snapshot the clone is actually a child of.
Post Reply