Linked clone with qemu-img

2018-04-09 244 words 2 mins read

As you would have seen in Virtualbox or vmware, there is option to create a linked clone. I wanted to use the same feature as “Snapshot” feature anyway does not look/work so great with virt-manager. So, I created a script to create a linked clone VM and here it is :

 

#!/bin/bash - 
#===============================================================================
#
#          FILE: qcow2-linked-clone.sh
# 
#         USAGE: ./qcow2-linked-clone.sh 
# 
#   DESCRIPTION: 
# 
#       OPTIONS: ---
#  REQUIREMENTS: ---
#          BUGS: ---
#         NOTES: ---
#        AUTHOR: Amit Agarwal (aka)
#  ORGANIZATION: Mobileum
#       CREATED: 01/05/2018 09:54
# Last modified: Wed Feb 28, 2018  04:39PM
#      REVISION:  ---
#===============================================================================

set -o nounset                              # Treat unset variables as an error
UP="amitag:amitag" #Here you need to put your username and group.

if [[ $# == 0 ]]
then
    read -p "Enter the source path :: " spath
    read -p "Enter the source disk :: " sdisk
    read -p "Enter the destin path :: " dpath
    read -p "Enter the destin disk :: " ddisk
    read -p "Enter new VMName :: " vmname
else
    spath=$(dirname $1)
    dpath=$spath
    sdisk=$(basename $1)
    ddisk=$2.qcow2
    vmname=$2
fi


sudo chown $UP "$spath/$sdisk"
qemu-img create -f qcow2 -b "$spath/$sdisk" "$dpath/$ddisk"

virt-install --disk $dpath/$ddisk --ram 512 \
    --virt-type kvm --vcpus 1 --name "$vmname" --import

The script will create a linked qcow2 and then create a VM with that image. Running it is simple, either provide command line options or just run and it will ask you for details.

 

Hope it is useful.


author

Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it