User Tools

Site Tools


public:techstuff:libvirt

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
public:techstuff:libvirt [2012/08/21 13:51] – Deleted by PageMove plugin nathanpublic:techstuff:libvirt [2020/04/25 13:05] (current) – external edit 127.0.0.1
Line 1: Line 1:
 +====== 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 
 +<code>--network=bridge=eth0,model=virtio</code>
 +
 +  * Run install over console
 +
 +<code>--extra-args=console=ttyS0,115200</code>
 +
 +  * Installing to an LVM Pool instead. Replace disk line with this one. You'll end up with a volume called <vmname>.img
 +
 +<code>--disk pool=<pool name>,size=<size in GB>,bus=virtio,cache=none</code>
 +
 +  * If you want a specific name you'll need to create the volume manually first.
 +
 +<code>virsh vol-create-as <pool name> <volume name> <size></code>
 +
 +And then use this line to specify it.
 +
 +<code>--disk vol=<poolname>/<volume name>,bus=virtio,cache=none</code>
 +
 +===== 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.