Linked clone with qemu-img

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.

Battery life on laptops

To improve your laptop battery life, just do the following:

sudo dnf install tlp tlp-rdw
systemctl start tlp
systemctl enable tlp

Fix weird flux menu

Some distro’s just add all the items under single menu and thus the menu itself becomes unusable because of the number of items in the submenu and this I did not like and hence ceated this simply python script to fix that. For using the script, back up you “menu” file, redirect the output of this script to ‘menu’ file again.

 

#!/bin/python

F = open("~/.fluxbox/menu", "r")
count=0
mkc=1
started=0

for line in F:
    print line.rstrip()

    if '[submenu]' in line.lower() and started == 1:
        print '[end]'

    if '[end]'  in line.lower():
        count=0
        mkc=1
        if started > 0:
             started=0
             # print "Count is {}".format(count)
             # print "Started is {}".format(started)
             print '[end]'
    if '[exec]'  in line.lower():
        if count > 15 :
            if started > 0:
                started=0
                print '[end]'
                # print "Count is {}".format(count)
                # print "Started is {}".format(started)
            print '[submenu] ({})'.format(mkc)
            started=1
            mkc+=1
            count=0
        # print count
        count+=1