VM cloning when VM is ON

This is for discussing general topics about how to use VirtualBox.
Post Reply
gg75
Posts: 2
Joined: 3. Feb 2020, 18:19

VM cloning when VM is ON

Post by gg75 »

Hello All,

I have an issue: i would like to clone a VM (Debian 9) while it is running.
Is it possible ?

My case:
I have no acess to this machine (root password is lost)
This VM holds production softwares and i am afraid that if i stop it (for cloning) not all services will reboot afterwards.
So i need to clone it, to try safely to find root password (with linux safe reboot techniques) without touching the main VM

Thanks for advices,

GG.
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: VM cloning when VM is ON

Post by mpack »

Practically speaking, no, you cannot clone a VM while it is running, at least not from the outside. Attempting that would leave potentially corrupted hard disk and config settings, and the guest OS in a crashed state if you're lucky.

Also, not a "Windows Hosts" question. I'll move this topic to "Using VirtualBox".
fth0
Volunteer
Posts: 5677
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: VM cloning when VM is ON

Post by fth0 »

You can simply copy the virtual disk image alone (in the Virtual Media Manager), create a new VM with the same settings as the existing VM, and attach the virtual disk image to it. The copied virtual disk image may have some file system corruption, but the guest OS can probably repair it.
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: VM cloning when VM is ON

Post by scottgus1 »

Trying fth0's idea, I started an XP guest on a Windows 10 host, selected the running guest's disk file in Virtual Media Manager, and hit 'Copy', and got this:
Failed to create the virtual disk image storage F:\VirtualboxGuests\XP\XP_copy.vdi.

Failed to lock source media 'F:\VirtualboxGuests\XP\XP.vdi'.

Result Code: VBOX_E_INVALID_OBJECT_STATE (0x80BB0007)
Component: MediumWrap
Interface: IMedium {ad47ad09-787b-44ab-b343-a082a3f2dfb1}
However, I was successful copying the running disk in Explorer. I then shut down the guest and released, removed & kept the the old disk file from Virtual Media Manager. I then attached the live copy, and the guest started again just fine. A disk scan might happen one day, but the guest did boot from the Explorer-started copy. I don't know what other host OS's will do.
gg75 wrote:try safely to find root password
Are you sure getting the existing root password is possible? There's plenty about resetting the root password, not so much about discovering what the old password was.
gg75
Posts: 2
Joined: 3. Feb 2020, 18:19

Re: VM cloning when VM is ON

Post by gg75 »

Thanks for your help !!

yes when i said "finding the password" i meant reseting it.

I tried to use the copy of the VDI and create a new VM on it. This VM starts well, i also managed to change passwords (by booting the GRUB in safemode..), but i have the feeling that when i tried to connect with the very user that is logged on the first VM, his session is corrupted on my copied VM. And i cant access this session.
I think the copy is in a unstable state for this very user which makes sens since it is the user who is logged while i copy the VDI, no?

GG.
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: VM cloning when VM is ON

Post by mpack »

I'll note that the OP asked about cloning the VM, not about cloning a disk. If you haven't addressed how it would cope with (say) live snapshots then you haven't answered the question asked.
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: VM cloning when VM is ON

Post by scottgus1 »

mpack wrote:If you haven't addressed how it would cope with (say) live snapshots then you haven't answered the question asked.
You have an extremely excellent point there! No snapshots in my test guest...
Post Reply