How To Clone VM with Libguestfs? – POFTUT

How To Clone VM with Libguestfs?

Hi, today we will look disk image tools/library which is very powerful. We will look for now just the tools, not the library but in the future, we can investigate the library in c or python too. With the era of cloud computing things to be done very fast, practical and precise way. In the past system administrators was connecting systems one by one and complete operations. But now in the new era system, admins do not have much time to do all things so new emerging technologies/tools/… is coming. One of them is libguestfs tools which make manipulating and operating virtual machine disk images very easy. A typical scenario is that a system administrator creates a new VM and install some applications on it and we change root pass and then clone a git repository into the system without touching systems console or terminal.

Clone Script

Here is a simple script which I use daily. I create source and dest paths that provide disk images. And then use virt-clone tool to clone existing VM with new disk path and name –auto-clone option makes is very easy. –connect option sets the hyper-visor –original sets source VM domain name. –name option is used new VMS name. and –file option for new VM disk file path.

sudo virt-clone --auto-clone  --connect qemu:///system --original $source_vm --name $dest_vm --file /home/ismail/vms/$2.qcow2

Install Applications To The Image

Now we have a new VM but we have to do a lot of work to complete operation. But with this tool it is easy. Here we use virt-customize command with -d option which means the name of VM nad –install option which specifies the package names that will be installed.

$ sudo virt-customize -d fedora --install httpd,php5,git
[   0.0] Examining the guest ...
[   4.0] Setting a random seed
[   5.0] Installing packages: httpd php5 git
[  97.0] Finishing off

Change Root Password Of Image

Here we change the root password and then run scripts to clone testing repository for git. Now we can give the system to the developers. As you can see it is very easy we write just their line of script and do a lot of thing for little tiny time.

$ sudo virt-customize -d fedora --run-command "git clone"
[   0.0] Examining the guest ...
[   4.0] Setting a random seed
[   4.0] Running: git clone

LEARN MORE  Linux VMware Workstation Not Enough Physical Memory Is Available Error and Solution

Leave a Comment