VM Clone/Copy/Duplicate


Recommended Posts

Is there a reason that unraid is the only solution out of those it competes with that doesn't have a feature to clone/copy/duplicate a VM easily?

 

Lost in a sea of different "how-to"'s, seeing countless google search result asking the EXACT SAME QUESTION and yet the answers are outdated, over complicated, or changed due to version differences, outdated buggy apps to do so, etc etc etc.

 

I seriously like unraid over the others, but holy crap this is bang head against wall annoying.

Link to comment
  • 1 year later...
  • 1 year later...

I have coded this small bash script that let you clone your VMs. Currently is tested for Ubuntu/Debian.

 

https://github.com/palaueb/unraid-vm-clone/blob/main/clone_vm.sh

 

How to use

Connect to terminal.

Download file

wget https://raw.githubusercontent.com/palaueb/unraid-vm-clone/main/clone_vm.sh

Check the file signature

$shasum clone_vm.sh
2193dcd662ac362c1cd49054ceed440f43a4fc69  clone_vm.sh

Change file permisions

chmod +x clone_vm.sh

Stop VM that you want to clone, then execute script

root@Tower:~# ./clone_vm.sh 
Enter the name of the virtual machine to be cloned: Listing Virtual Machines with their states:
k8s-node-master - shut off
Enter the name of the VM you want to select:
k8s-node-master
You have selected the VM: k8s-node-master
Enter the new name for the cloned virtual machine: k8s-node-cloned
Please choose the cloning method for the VM volume:
1. Full copy (independent clone)
2. Linked clone (using a backing file)
3. Help (explain options)
Enter your choice (1, 2, or 3): 1
You have chosen a full copy. This option will create an independent clone of the VM volume, which is a complete and standalone copy.
[k8s-node-master] to be cloned as [k8s-node-cloned]
sending incremental file list
vdisk1.img
          7.99G 100%  185.48MB/s    0:00:41 (xfr#1, to-chk=0/1)
Cloning NVRAM from /etc/libvirt/qemu/nvram/wwwwwwww-xxxx-yyyy-zzzz-d7a89d8a5218_VARS-pure-efi.fd to /var/lib/libvirt/qemu/nvram/k8s-node-cloned_VARS.fd
Domain 'k8s-node-cloned' defined from /tmp/tmp.ysKuBvXUae

Domain 'k8s-node-cloned' started

Now you have a duplicate, enter to the duplicated server and update hostname and network configuration if needed.

# for example on systemD
hostnamectl set-hostname my-cloned-server

 

The MAC address is regenerated, the UUID is regenerated.

 

I hope it is useful and helpful to you
Please give feedback.

Edited by palaueb
  • Like 1
Link to comment
  • 1 month later...

Thank you for this!, I started writing my own but then came across this :)

 

I made a full copy except at the end I got errors

 

error: Failed to start domain 'Win10Base-3'
error: operation failed: unable to find any master var store for loader: /usr/share/qemu/ovmf-x64/OVMF_CODE-pure-efi.fd

 

to fix it , all I did was to "edit" the vm and changed anything and updated, then it runs fine :)

 

 

I tried it again to compare the before and after of the XML and here are the differences 

 

non-working version

    <nvram>/var/lib/libvirt/qemu/nvram/Win10Base-3-3_VARS.fd</nvram>
 

working version

    <nvram>/etc/libvirt/qemu/nvram/eaf488d4-a3b9-4fdd-bd9c-fedd3ac4dae6_VARS-pure-efi.fd</nvram>
 

 

I have not rebooted unraid to make sure everything got saved to the right places in the config, will let you know if there are any issues after a reboot.

 

great script, except for that one glitch, works awesome.

 

Thank you

Edited by piyper
Link to comment

I got error message 

 

root@UnriadNAS:~# ./clone_vm.sh
./clone_vm.sh: line 1: syntax error near unexpected token `('
./clone_vm.sh: line 1: `{"payload":{"allShortcutsEnabled":false,"fileTree":{"":{"items":[{"name":"LICENSE","path":"LICENSE","contentType":"file"},{"name":"README.md","path":"README.md","contentType":"file"},{"name":"clone_vm.sh","path":"clone_vm.sh","contentType":"file"}],"totalCount":3}},"fileTreeProcessingTime":4.462308,"foldersToFetch":[],"repo":{"id":726783609,"defaultBranch":"main","name":"unraid-vm-clone","ownerLogin":"palaueb","currentUserCanPush":false,"isFork":false,"isEmpty":false,"createdAt":"2023-12-03T11:49:46.000Z","ownerAvatar":"https://avatars.githubusercontent.com/u/368245?v=4","public":true,"private":false,"isOrgOwned":false},"symbolsExpanded":false,"treeExpanded":true,"refInfo":{"name":"main","listCacheKey":"

 

error.txt

Link to comment

Please, open the file clone_vm.sh and ensure that the file is exactly as shown on this URL: https://raw.githubusercontent.com/palaueb/unraid-vm-clone/main/clone_vm.sh

 

Another thing that you can do is to hash the file and compare with the hash that I give you:

 

root@Tower:/tmp# wget https://raw.githubusercontent.com/palaueb/unraid-vm-clone/main/clone_vm.sh

2024-02-07 12:15:00 (47.2 MB/s) - ‘clone_vm.sh’ saved [4540/4540]


root@Tower:/tmp# shasum clone_vm.sh
316c033d2a54facb77babcdaae18c67a12000ca2  clone_vm.sh

shasum 316c033d2a54facb77babcdaae18c67a12000ca2
sha256sum: b0cba826d0045c1990c675cd741fc6e04d75844e7407757ba346f6771e25939e

 

It seems that your file has some json inside.

*: I have upgraded the wget URL to the RAW file.

Edited by palaueb
Link to comment
  • 2 weeks later...
On 2/7/2024 at 12:17 PM, palaueb said:

Please, open the file clone_vm.sh and ensure that the file is exactly as shown on this URL: https://raw.githubusercontent.com/palaueb/unraid-vm-clone/main/clone_vm.sh

 

Another thing that you can do is to hash the file and compare with the hash that I give you:

 

root@Tower:/tmp# wget https://raw.githubusercontent.com/palaueb/unraid-vm-clone/main/clone_vm.sh

2024-02-07 12:15:00 (47.2 MB/s) - ‘clone_vm.sh’ saved [4540/4540]


root@Tower:/tmp# shasum clone_vm.sh
316c033d2a54facb77babcdaae18c67a12000ca2  clone_vm.sh

shasum 316c033d2a54facb77babcdaae18c67a12000ca2
sha256sum: b0cba826d0045c1990c675cd741fc6e04d75844e7407757ba346f6771e25939e

 

It seems that your file has some json inside.

*: I have upgraded the wget URL to the RAW file.

 

I have been experimenting with you clone script, it clones fine.

Problem is that something must be wrong or missing, as I cant delete the cloned VMs.
All I get when trying to delete a clone from the GUI, is red spinning arrows.

Some I could delete by first deleting the disk manually, then deleting the VM from the GUI.

Others wont even delete when disk is removed physically as well as in the config.

Link to comment

I want to clone Windows VM.

I tried your script. It works - new VM is created with new name as expected.

It started automatically into UEFI shell.

I stopped it and looked into the settings of a VM, and found out a setting "Unraid Source Path:" which still points to original appdata folder. I don't know if this is OK. Anyway I created new folder in appdata (using WinSCP with root privilege), and changed this setting to point this new folder.

Started VM again and it was running UEFI shell again. Using "exit" command, I got UEFI settings.

I choose "continue" option, and it started Windows installation process, where I could choose OS version and other installation stuff.

 

I expected cloning VM creates new VM with everything installed (no need to go through installation of windows again).

Probably I don't understand the process.

 

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.