Sunday, October 5, 2014

Creating virtual machines with KVM

I was pretty confused when I first started creating virtual machines. Between Xen, VirtualBox, VMWare, LXC, Docker there are a ton of technologies for virtualization.

I decided to go with KVM. A library called libvirt helps a lot in creating virtual machines (aka domains). Libvirt has a tool called virsh which is what we will be using.

virsh uses xml files for the configuration of the domains. To create one easily you can use the virt-install command. The files are stored are in /etc/libvirt/qemu/

virt-install \
  --name moloko \
  --vcpus=1 \
  --disk /var/kvm/moloko,size=32 \
  --ram 1024 \
  --graphics vnc,password=password,listen=,port=5910 \
  --accelerate \
  --cdrom /var/kvm/ubuntu-14.04.1-server-amd64.iso \
  --os-type=linux \
  --noautoconsole \
  --boot cdrom,fd,hd,network,menu=on

To delete the domain:

virsh destroy moloko
virsh undefine moloko

No comments: