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

Discussions related to using VirtualBox on Windows hosts.
Post Reply
jtconsol
Posts: 3
Joined: 3. Nov 2022, 22:58

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

Post 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
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

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

Post 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.
fth0
Volunteer
Posts: 5668
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

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

Post 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?
jtconsol
Posts: 3
Joined: 3. Nov 2022, 22:58

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

Post 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
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

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

Post 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.
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

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

Post 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.
Post Reply