vagrant box to libvirtd (QEMU) VM

Like ova images, you can use box images as well with Qemu. After all, both have the disk images, so here is the script to do that. Just put the script somewhere in your path and run with ova or box image name :

 

#!/bin/bash - 
#===============================================================================
#
#          FILE: ova2vm.sh
# 
#         USAGE: ./ova2vm.sh 
# 
#   DESCRIPTION: 
# 
#       OPTIONS: ---
#  REQUIREMENTS: ---
#          BUGS: ---
#         NOTES: ---
#        AUTHOR: Amit Agarwal (aka),
#  ORGANIZATION: Mobileum
#       CREATED: 12/28/2017 13:59
# Last modified: Sun Mar 11, 2018  12:01PM
#      REVISION:  ---
#===============================================================================

set -o nounset                              # Treat unset variables as an error
dest='/mnt/Backup/VM'
ORIG=${PWD}

if [[ $# == 0 ]]
then
    echo "You need to provide ova/vmdk filename"
    exit
fi
if [[ $1 == *ova || $1 == *box ]]
then
    tmp=$(mktemp -d /tmp/amitXXXXXXX)
    cd  $tmp
    tar xvf $ORIG/$1
    file=$(echo $PWD/*vmdk)
else
    file=$1
    echo "Not a OVA file"
fi
dfile="$dest/$(basename $file)"

read -p "Enter the name for VM :: " vmname
qemu-img convert $file $dfile -p -c -O qcow2
virt-install --disk $dfile --ram 512 \
    --virt-type kvm --vcpus 1 --name "$vmname" --import

mv command with progress

When moving large files/directories, I would like to see the progress.

Idea for this is to use rsync with progress and remove source files. But that option does not remove the empty directories left behind so find command to delete that.

So, here is function for that:

mv-progress () 
{ 
    rsync -ah --progress --remove-source-files "$1" "$2";
    find "$1" -empty -delete
}

Highest disk usage of directory in subdirectories

I find myself doing this lot of times so thought will share this with you all. Basically, once I want to clear out the directory, I first want to find out the sub-directory using the maximum disk space so I wrote a function for that and here it is:

 

disk_usage_dirs () 
{ 
    find . -maxdepth 1 -type d -not -name '.' | while read line; do
        du -s "$line";
    done | sort -n | tail -${1:-5}
}

Some other posts you might find useful on this :

Disk usage by file type

Color disk usage on Fedora

Get disk usage for all the containers with python script