Differences

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

Link to this comparison view

Next revision
Previous revision
kvm [2010/03/29 23:53]
a created
kvm [2012/04/14 14:25] (current)
stojan
Line 1: Line 1:
 ====== KVM ====== ====== KVM ======
 +**
 +Creating VMs from Debian repositories**
  
 +How to create a new VM with 2GB of memory and 15GB disk image directly from Debian repo:
  
 +<code>
 +virt-install -n vmserver -r 2048 --os-type=linux --os-variant=debiansqueeze \
 +--disk /vmdisk/vmserver.raw,device=disk,bus=virtio,size=15,sparse=true,format=raw -w bridge=br0,model=virtio \
 +--vnc --noautoconsole --location  http://cdn.debian.net/debian/dists/stable/main/installer-amd64/
 +</code>
 +
 +use VNC to connect to the VM console after creating it.
 +
 +**Some useful commands for handling VMs**
 +
 +List existing VMs:
 +<code>
 +virsh list
 +</code>
 +
 +Shutdown an existing VM:
 +<code>
 +virsh shutdown vmname
 +</code>
 +
 +Destroy (hard shutdown) an existing VM:
 +<code>
 +virsh destroy vmname
 +</code>
 +
 +Start an existing VM:
 +<code>
 +virsh start vmname
 +</code>
 +
 +Set the 'autostart' flag on the existing VM:
 +<code>
 +virsh autostart vmname
 +</code>
 +
 +Clone an existing VM. Make sure you update the udev settings after cloning if you want your network to work:
 +<code>
 +virt-clone -o OldVM -n NewVM -f /disk/NewVmImage.img
 +</code>
 +
 +Remove a VM from the system 'registry':
 +<code>
 +virsh undefine vmname
 +</code>
 +
 +**KVM performance boost**
 +
 +[[http://www.linux-kvm.com/content/get-performance-boost-backing-your-kvm-guest-hugetlbfs|Get a performance boost by backing your KVM guest with hugetlbfs]]
 +
 +<code>
 +# grep HUGETLB /boot/config-`uname -r`
 +CONFIG_HUGETLBFS=y
 +CONFIG_HUGETLB_PAGE=y
 +</code>
 +
 +   mkdir /hugepages
 +
 +Next add an entry to your /etc/fstab so that when you reboot your computer, your hugetlbfs will mount automatically. Your entry should look like the following.
 +
 +   hugetlbfs       /hugepages  hugetlbfs       defaults        0 0
 +
 +<note tip>**Calculate the number of huge pages you require**
 +
 +On x86, large pages are 2MB in size so you need to find out how many 2MB pages you need to back your kvm guest. Let’s say you want to use 512 MB for your guest machine then divide 512 by 2 to get 256 pages. Add a few extra pages for additional memory requirements, lets say 40 pages to give a total of 296 pages. Record this value as you’ll need it later on.</note>
 +
 +   echo 296 >  /proc/sys/vm/nr_hugepages
 +
 +If you want this to be a permanent setup , you can also add it to your /etc/rc.local script so that it is always reserved on startup. To verify that you have large pages reserved inspect the contents of the /proc/meminfo file as follows.
 +<code>
 +# tail -n 5 /proc/meminfo 
 +HugePages_Total:   296
 +HugePages_Free:    296
 +HugePages_Rsvd:      0
 +HugePages_Surp:      0
 +Hugepagesize:     2048 kB
 +</code>
 +
 +   qemu-system-x86_64 –hda windows.img –m 512 –mem-path /hugepages
 +
 +You will probably notice a performance increase in your virtual machine. You can check that you’re actually using huge pages by inspecting the /proc/meminfo file again. For example, this is what mine looked like while running a kvm guest backed with the values in this post.
 +<code>
 +# tail -n 5 /proc/meminfo 
 +HugePages_Total:   296
 +HugePages_Free:     39
 +HugePages_Rsvd:      0
 +HugePages_Surp:      0
 +Hugepagesize:     2048 kB
 +</code>
  
kvm.1269899637.txt.gz · Last modified: 2010/03/29 23:53 by a
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0 ipv6 ready