User Tools

Site Tools


public:techstuff:libvirt

libvirt

Creating a VM

Creating an KVM VM

virt-install
--name=<VM name>
--ram=<memory in MB>
--location=http://ftp.nz.debian.org/debian/dists/<version>/main/installer-amd64/
--os-type=linux
--os-variant=debiansqueeze
--disk=/img/<vm name>.img,device=disk,bus=virtio,size=<disk size GB>,sparse=true,format=raw

Creating an LXC VM

  • Capped resources at 512mb of ram and 2 cpus
cd /img
mkdir <vmname>
sudo debootstrap wheezy <vmname> http://mirror.byte.net.nz/debian/
sudo virt-install --connect lxc:/// --name cubert --ram 512 --vcpu 2 --filesystem /img/cubert/,/ --noautoconsole -w network=vm
virt-install \
--connect lxc:///
--name httpd_guest
--ram 512
--vcpus 2

Existing KVM image

virt-install
--name <VM name>
--ram <memory>
--disk path=/img/<VM name>.img
--import --noautoconsole --force

Other Useful Options

  • Create VM with a bridge attached to eth0
--network=bridge=eth0,model=virtio
  • Run install over console
--extra-args=console=ttyS0,115200
  • Installing to an LVM Pool instead. Replace disk line with this one. You'll end up with a volume called <vmname>.img
--disk pool=<pool name>,size=<size in GB>,bus=virtio,cache=none
  • If you want a specific name you'll need to create the volume manually first.
virsh vol-create-as <pool name> <volume name> <size>

And then use this line to specify it.

--disk vol=<poolname>/<volume name>,bus=virtio,cache=none

Open Serial Console to VM

virsh console <VM name>

Enable Kernel output over serial

On the VM edit /etc/default/grub and update GRUB_CMDLINE_LINUX

GRUB_CMDLINE_LINUX="text console=tty0 console=ttyS0,115200n8"

Finally run update-grub as root.

public/techstuff/libvirt.txt · Last modified: 2020/04/25 13:05 by 127.0.0.1