Skip to content

Instantly share code, notes, and snippets.

@jsomara
Created March 19, 2012 19:41
Show Gist options
  • Save jsomara/2125558 to your computer and use it in GitHub Desktop.
Save jsomara/2125558 to your computer and use it in GitHub Desktop.
use virt-clone & virt-edit to clone a qemu vm
#!/bin/sh
# clonio
# replace /home/jsomara/images with where you're copying your image from
# usage sudo sh clonio.sh rhel-6.2-base zoidberg
# rhel-6-2-base.img is in /home/jsomara/images/rhel-6-2-base.img
# zoidberg.img ends up in /home/jsomara/images
# thanks to jeckersb
virt-clone -o $1 -n $2 -f /home/jsomara/images/$2.img
MAC=$(cat /etc/libvirt/qemu/$2.xml | grep 'mac address' | sed -r "s/^[^']+'([^']+)'.*/\1/")
virt-edit -d $2 /etc/sysconfig/network-scripts/ifcfg-eth0 -e 's/^HWADDR.*/HWADDR="'$MAC'"/'
virt-edit -d $2 /etc/sysconfig/network -e 's/^HOSTNAME=.*/HOSTNAME="'$2'"/'
guestfish -d $2 -i rm /etc/udev/rules.d/*persistent-net*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment