Page 1 of 1

Linux guest VM cloned from snapshot does not start the first time

Posted: 27. Nov 2022, 01:54
by jtconsol
Hi,

I'm scripting an unattended install of Debian Linux with VirtualBox 7.0.2 - the script does the following:

1. Create VM and storage
2. Do unattended install
3. Start VM
4. Run some commands inside the VM
5. Shut down VM: "VBoxManage.exe controlvm ... acpipowerbutton"
6. Take a snapshot: "VBoxManage.exe snapshot ... take 00fresh"
7. Clone VM from that snapshot: "VBoxManage.exe clonevm ... --basefolder ... --name ... --register --snapshot 00fresh"

Now, when I try to start it, the cloned VM will not boot the first time, but go from "Saved" into "Powered Off" state (quick, in about 4 seconds).
When I try to start the cloned VM again, it will boot normally.

Any ideas where that comes from and how to avoid it?

Cheers,
JT

Re: Linux guest VM cloned from snapshot does not start the first time

Posted: 27. Nov 2022, 12:03
by mpack
What purpose does taking the snapshot serve? The VM is already shut down so I don't know why you wouldn't just clone the base disk, plus the snapshot is just taken and so will be empty.

Re: Linux guest VM cloned from snapshot does not start the first time

Posted: 27. Nov 2022, 12:25
by fth0
I'm wondering why any of the VMs is in the Saved state at all, because I'd expect both VMs to be in the Powered Off state after steps 5, 6 and 7. How does the guest OS react on the ACPI shutdown signal?

Re: Linux guest VM cloned from snapshot does not start the first time

Posted: 27. Nov 2022, 14:17
by jtconsol
Thanks for answering.
mpack wrote:What purpose does taking the snapshot serve? The VM is already shut down so I don't know why you wouldn't just clone the base disk, plus the snapshot is just taken and so will be empty.
My rationale is that maybe later I'd like to continue working on that base VM, but still retain the ability to go back to the "pristine" state from before.
Does that not make sense or is there a better way to do it?
fth0 wrote:I'm wondering why any of the VMs is in the Saved state at all, because I'd expect both VMs to be in the Powered Off state after steps 5, 6 and 7. How does the guest OS react on the ACPI shutdown signal?
I'd thought so as well. The guest OS shuts down fine as far as I can see.

However I think I understand the problem now:
When introducing a delay between steps 5 and 6, the cloned VM will show up with state "Powered Off" (and boot up on the first attempt).
Without the delay, the snapshot gets taken while the base VM is still in the process of shutting down!

Thus, my related follow-up question would be: How to best wait for the shutdown to be completed?
So far the only way I see is to check the VM state with "VBoxManage.exe showvminfo --machinereadable ..." in a loop until I see the "VMState" field is set to "poweroff"...

Cheers,
JT

Re: Linux guest VM cloned from snapshot does not start the first time

Posted: 27. Nov 2022, 16:01
by mpack
If your purpose is simply to make a backup that you can return to, then I'd make a proper backup - not a clone. Simply copy the VM folder to a backup drive - there's no need to mess with snapshots.

Re: Linux guest VM cloned from snapshot does not start the first time

Posted: 27. Nov 2022, 20:05
by scottgus1
jtconsol wrote:the only way I see is to check the VM state with "VBoxManage.exe showvminfo --machinereadable ..." in a loop until I see the "VMState" field is set to "poweroff"...
This is it.