Skip to content

Instantly share code, notes, and snippets.

@srics
Created December 23, 2014 21:33
Show Gist options
  • Save srics/85d003153d95cbca9c46 to your computer and use it in GitHub Desktop.
Save srics/85d003153d95cbca9c46 to your computer and use it in GitHub Desktop.
Create KVM Ubuntu VM using backing qcow2 disk
#!/bin/bash -x
# CHANGE-ME: replace VM_NAME as appropriate
VM_NAME="ubuntu-dhcp-template"
VM_MEM=2048
VM_VCPUS=2
VM_DISK_ISO=/var/lib/libvirt/images/ubuntu-14.04.1-server-amd64.iso
VM_NETWORK="bridge=br-int"
VM_PATH=/opt/vms/${VM_NAME}
VM_DISK=${VM_PATH}/${VM_NAME}_disk.qcow2
BASE_QCOW2=/opt/vms/_base_trusty64_openstack_dhcp/_base_trusty64_openstack_dhcp_disk.qcow2
mkdir -p $VM_PATH
rm -f ${VM_DISK}
qemu-img create -f qcow2 -b ${BASE_QCOW2} ${VM_DISK}
virt-install --virt-type=kvm --hvm --cpu host \
--name=$VM_NAME \
--ram=$VM_MEM --vcpus=$VM_VCPUS \
--disk path=$VM_DISK,format=qcow2 \
--network $VM_NETWORK \
--graphics vnc,listen=127.0.0.1 --noautoconsole \
--os-type=linux --os-variant=ubuntutrusty \
--import
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment