Jump to content
drdobsg

How to Clone a VM? How Do I Install More VM Tools?

14 posts in this topic Last Reply

Recommended Posts

Does anyone know of a tool installed on unRaid that will clone a VM?  I am new to KVM, but I am used to cloning VMs on esxi via the command line.  I have read a few suggestions of just copying the .img file, but that will essentially convert the thin provisioned disk to a thick one.

 

Through some googling i have found some packages that may be what i am looking for:  virtinst, which contains a virt-clone command; or libguestfs-tools which contains a virt-sparsify command which shrinks a thick provisioned disk to a thin one.  I found this slack package, but I don't know if its compatible with unRaid or how to install it.

 

Ideally what i really want to do is create a template and deploy from that, but I will settle for being able to clone a VM.

Share this post


Link to post

I'm also interested now that I have a w10 and OSX vm running.

 

Gus

Share this post


Link to post

I asked about this a while back and never got a response so I did some testing of my own.

 

I created a VM -- installed Windows 7 + drivers etc. Then I just copied the vdisk and created a new VM except that I selected the copy of the vdisk that I made. Boot up the VM and it worked.

 

So as far as I can tell this is all that is required. I'm pretty new to VMs so I could be wrong but it worked fine for me.

 

Share this post


Link to post

Hi i was just wondering the same so i googled it :D

 

This method uses the power of BTRFS filesystem: we create one basevm and make snapshots for our Clone VM's. This wil not use any additional space on your harddrive. Except for changes made in the clone.

 

So if you create one Windows 10 machine (around 17 GB) you can make for example 15 clones of it and still only use 17 GB of disk space.

 

BEFORE YOU START: Im not sure if this is the best way to to this but it works !

 

Download putty and ssh to your Unraid server.

 

Make sure u are using btrfs filesystem (https://lime-technology.com/forum/index.php?topic=33806.0) and cd to your btrfs location!

 

For me this is:

# cd /mnt/disk1/

 

Do the following with commandline (ssh to your unraid server):

 

Step 1 --make te initial (sub)volume (this wil create an folder: /mnt/disk1/btrfs)

# btrfs subvolume create btrfs

 

Now you can make your folder tree within this folder with subvolumes (Volumes for basevm folder and its clones folders)

 

Step2 --So next we will create a base folder for our vm disk image

# btrfs subvolume create btrfs/basevm

 

Step 3 --Now copy your vm disk image to this folder you just created. I created an Windows 10 vm called win10, and copied the vdisk1.img to my basevm subvolume (vdisk1.img is the Virtual harddisk of VM.)

# cp win10/vdisk1.img btrfs/basevm/vdisk1.img

 

Step 4 --Once done copying or configuring your vm (Make sure its shutdown) execute the follow from the commandline (ssh)

# btrfs subvolume snapshot btrfs/basevm btrfs/cloneofbasevm1

 

Step 5 --Now you can make a second vm within the Unraid webgui. In the "Primary vDisk Location:" field make sure you are pointing to the cloneofbasevm1 folder.

Also make sure you leave the "OS Install ISO:" empty, as the OS is already installed.

 

Now if you want to create a second VM just repeat Step 4.

 

Example:

 

Second VM Clone:

# btrfs subvolume snapshot btrfs/basevm btrfs/cloneofbasevm2

 

Third VM Clone:

# btrfs subvolume snapshot btrfs/basevm btrfs/cloneofbasevm3

 

Good Luck !!

 

Source: https://www.linux.com/learn/how-create-and-manage-btrfs-snapshots-and-rollbacks-linux-part-2

 

 

Share this post


Link to post

I asked about this a while back and never got a response so I did some testing of my own.

 

I created a VM -- installed Windows 7 + drivers etc. Then I just copied the vdisk and created a new VM except that I selected the copy of the vdisk that I made. Boot up the VM and it worked.

 

So as far as I can tell this is all that is required. I'm pretty new to VMs so I could be wrong but it worked fine for me.

 

Yes that will work, but the problem is that it increases the disk space required by the VDisk.  For example if a VM has a 30GB virtual hard drive but is only using 13GB of it.  It actually only takes up 13GB on the cache drive.  The copy will take up the 30GB on the cache drive.  The same is true in vmware esxi, if you just try to copy the thin disk it will expand its size.

 

Note that ls -l will show you it takes up 30GB, but du will show you what it really uses.

Share this post


Link to post

I did not know it was possible to make VMs in unraid with thin provisioning.

 

Share this post


Link to post

Hi i was just wondering the same so i googled it :D

 

This method uses the power of BTRFS filesystem: we create one basevm and make snapshots for our Clone VM's. This wil not use any additional space on your harddrive. Except for changes made in the clone.

 

So if you create one Windows 10 machine (around 17 GB) you can make for example 15 clones of it and still only use 17 GB of disk space.

 

BEFORE YOU START: Im not sure if this is the best way to to this but it works !

 

Before any one else tries this, I am pretty sure the answer is no this is not the best way.  Maybe someone with more experience can chime in, but that sounds like a bad way to do it.

 

What you are describing is making snapshots of the BTRFS file system.  Essentially each "clone" you make is a diff of the base sub file system.  And in the end it will probably end up being a full copy of the original disk, since the .img file will change enough from the original where it will be a copy instead of a diff.  I don't know enough about BTRFS, but i suspect there will be a performance hit there. 

 

The first few references from googling "BTRFS snapshots KVM" all pretty much say the same thing: Don't use BTRFS for VM storage.  Or at least don't enable copy on write for storing the image files because they are essentially one giant file.

Share this post


Link to post

I did not know it was possible to make VMs in unraid with thin provisioning.

 

From what i see it is the default.  Compare ls -l vs du and see what you get.

Share this post


Link to post

I asked about this a while back and never got a response so I did some testing of my own.

 

I created a VM -- installed Windows 7 + drivers etc. Then I just copied the vdisk and created a new VM except that I selected the copy of the vdisk that I made. Boot up the VM and it worked.

 

So as far as I can tell this is all that is required. I'm pretty new to VMs so I could be wrong but it worked fine for me.

 

Yes that will work, but the problem is that it increases the disk space required by the VDisk.  For example if a VM has a 30GB virtual hard drive but is only using 13GB of it.  It actually only takes up 13GB on the cache drive.  The copy will take up the 30GB on the cache drive.  The same is true in vmware esxi, if you just try to copy the thin disk it will expand its size.

 

Note that ls -l will show you it takes up 30GB, but du will show you what it really uses.

 

Easiest way to copy a vdisk with it taking up more space is to install libguestfs-tools to a ubuntu vm mount your shared vm folder to the vm. open terminal. cd to the mounted vm share and run

 

virt-sparsify --format raw --convert qcow2 --compress vdisk1.img vdiskcopy.qcow2

 

This will sparsify convert raw to qcow2 then compress the image so your copy is correct size

 

You will need as much space in your ubuntu vm as the raw image is as it uses a temp file to do this.

Share this post


Link to post

I asked about this a while back and never got a response so I did some testing of my own.

 

I created a VM -- installed Windows 7 + drivers etc. Then I just copied the vdisk and created a new VM except that I selected the copy of the vdisk that I made. Boot up the VM and it worked.

 

So as far as I can tell this is all that is required. I'm pretty new to VMs so I could be wrong but it worked fine for me.

 

I'm with you on this. I have been keeping full size backups and making clone VMs simply by making copies of my initial vdisk inside mc from the get go. Since my VMs are only 60GB, I don't feel like I am using too much space that I even bother with compression, etc. Especially when it takes less than 5 mins to make a copy. I think I have like 15 full backups on the array since I sorted out all of my unRAID VM issues, and have found copying to be the quickest solution for me. Most important thing is keeping a copy of those XMLs, especially if you've unlocked a free Win10 upgrade for that VM's specific uuid. After that, it's just copy and paste and you can restore a backup, make a cloned VM, whatever.

Share this post


Link to post

Just thought I'd chime in here with an even easier method that doesn't require using btrfs subvolumes or btrfs snapshots:

 

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

 

The --reflink command to cp instructs CP to use the COW features of BTRFS to create a "reflink" copy of the file, which is essentially a file-level snapshot.  You can even delete the underlying base image and the snapshot will continue to work since btrfs remembers the dependencies that reflinks have on underlying block-level data.

Share this post


Link to post

I know this is an ancient thread, but thought I'd share that while I've used the cp --reflink command before successfully, it's now failing. Apparently this is a known bug in the newer OS:

 

https://bugs.centos.org/view.php?id=14228

 

Curious if anyone has any new methods for backing up VMs or any other kind of snapshot method within unRaid.

Share this post


Link to post

So I did it in a easy way, I made one VM booted, working; I installed the KRUSADER app docker and copied the vm file to a new location, I created a new VM and did not specify windows.iso location kept empty and pointed to the new location for the copy VM, and it boots and runs :D

 

 

Share this post


Link to post
On 5/17/2016 at 10:05 AM, Naldinho said:

I asked about this a while back and never got a response so I did some testing of my own.

 

I created a VM -- installed Windows 7 + drivers etc. Then I just copied the vdisk and created a new VM except that I selected the copy of the vdisk that I made. Boot up the VM and it worked.

 

So as far as I can tell this is all that is required. I'm pretty new to VMs so I could be wrong but it worked fine for me.

 

this worked really well and straight forward. 

Share this post


Link to post

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.