Cloning a VM


Recommended Posts

If the VM is stored on a BTRFS-formatted device, you can use the cp command to create reflink copies which are essentially the best of snapshots and clones in a single method:


cp --reflink /path/to/vdisk.img /path/to/snapshotorclone.img


The only catch is that both the source and destination file must exist in the same BTRFS volume.  This can be inside a btrfs pool or a single btrfs device.  An example of an INVALID use of the command:


cp --reflink /mnt/disk1/domains/domain1/domain1.img /mnt/disk2/domains/domain2/domain2.img


This won't work even if both disk1 and disk2 are btrfs because they will be separate volumes.


Also, you cannot use this command through the user share file system (/mnt/user).  Instead, always path through the device itself (e.g. /mnt/disk or /mnt/cache).

  • Thanks 1
Link to comment

I just tried that but its giving me an error:


cp: failed to clone ‘/mnt/cache/VM/UbuntuNew/vdisk1.img’ from ‘/mnt/cache/VM/UbuntuBase/vdisk1.img’: Invalid argument


What I ran was:


cp --reflink /mnt/cache/VM/UbuntuBase/vdisk1.img /mnt/cache/VM/UbuntuNew/vdisk1.img


Both source and destination are on my SSD, which is BTRFS formatted


A file shows up at the destination but its size is 0, so at least the paths are correct

Link to comment
  • 3 months later...

Figured out the soloution. Two things seem to create the problem you mentioned about invalid argument and 0KB.


1. If COW (Copy on Write) settings are disabled then this happens - this setting is in the share settings and you have to set it to "Auto" instead of "disabled" when creating the share


2. If you create your VM disk folders through the network/SAMBA I.e. You access it from my network places and you create subdirectories via that in Windows then try to cf reflink to there. The way around this is is, go to your VM, create a vdisk through the settings panel in a new folder of your choice, going via usershares to navigate to the folder of your choice.. Then delete the vdisk1.img and use the standard instructions posted above and being aware of not doing from 1 disk to another or going via user shares.


This seems to do the trick, I'm new to UNRAID but that worked for me. Hope it helps!

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

Also, figured out that you can only reflink to the exact same folder. So in the case of @Nem, if he had done the above, to not get the error he got, he would need to have done:


cp --reflink /mnt/cache/VM/UbuntuBase/vdisk1.img /mnt/cache/VM/UbuntuBase/disk1.img


You can then copy the image to another folder however you cannot reflink from e.g. UbuntuBase to UbuntuNew, it has to the same folder it appears.

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.

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.