samedi 18 janvier 2014

KVM / libvirt

# verifier si processur compatible...
egrep -c '(vmx|svm)' /proc/cpuinfo

# installer les packages coté serveur
aptitude install kvm qemu-kvm libvirt-bin virtinst colord bridge-utils virt-manager

#---creating bridge

#First step to creating the bridge network
brctl addbr br0

# The name br0 is totally up to you, this is just an example name that I’ve chosen for the wiki article.
# Anyway, now that you have your bridge device, you have to add the interfaces that are gonna be bridged. You # can cross-check the enumeration of your ethernet devices with (eth0, eth1, etc. is common):

ip addr show

#Add both the interface with the second computer, and the interface that leads to the existing network. Do it #with this command:

brctl addif br0 eth0

# Configuring bridging in /etc/network/interfaces
# The loopback network interface

auto lo
iface lo inet loopback

auto br0
iface br0 inet static

bridge_ports eth0

dns-search home.lan

bridge_fd 9
bridge_hello 2
bridge_maxage 12
bridge_stp off

# create bridge

cd /etc/libvirt/qemu/networks

echo '' > /etc/libvirt/qemu/networks/bridge.xml
echo '    bridge' >> /etc/libvirt/qemu/networks/bridge.xml
echo '    ' >> /etc/libvirt/qemu/networks/bridge.xml
echo '    ' >> /etc/libvirt/qemu/networks/bridge.xml
echo '
' >> /etc/libvirt/qemu/networks/bridge.xml

virsh net-define bridge.xml

systemctl restart libvirtd.service; systemctl status libvirtd.service

#pol-edit defaut
nano -w /etc/libvirt/storage/default.xml
service libvirt-bin restart

#Changing the libvirt-guests service parameters to allow for the graceful shutdown of guests
# source

nano /etc/default/libvirt-guests
# Number of seconds we're willing to wait for a guest to shut down. If parallel
# shutdown is enabled, this timeout applies as a timeout for shutting down all
# guests on a single URI defined in the variable URIS. If this is 0, then there
# is no time out (use with caution, as guests might not respond to a shutdown
# request). The default value is 300 seconds (5 minutes).

#howto fix default storage pool location for virt-manager (and libvirt)


pool-destroy default
pool-undefine default
pool-define-as --name default --type dir --target /storage/local/images
pool-autostart default
pool-build default
pool-start default
pool-destroy local
pool-undefine local
pool-define-as --name local-iso --type dir --target /storage/local/iso
pool-autostart local-iso
pool-build local-iso
pool-start local-iso

#virsh editor (bashrc)
export EDITOR
echo 1 > /sys/kernel/mm/ksm/run

# Swapiness
vm.swappiness = 0

#For security and performances issues, you should disable ipv6
#on bridged interfaces by adding those 3 lines :
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0

#If you want to always enable VirtIO, to get maximum performances, load those modules :

#provisionner une VM debian
virt-install --ram=256 --name=$name --disk path=$path/$name/$name.img,bus=virtio,size=4 --cdrom=$iso --hvm --vnc --noautoconsole --accelerate --network=bridge:br0,model=virtio

# Detacher l'image ISO

#provisionner W7

virt-install --ram=2024 --name=W7 --disk path=/mnt/vm/kvm/W7/W7.img,bus=virtio,size=4 -cdrom=$iso --hvm --vnc --noautoconsole --os-type windows --os-variant win7 --accelerate

#cloner une VM
virt-clone --original=testing --auto-clone

#voir les VM
virsh list --all

#répertoire contenant les confs

# problème de perf dans une VM...
ethtool -K [interface] gro off tso off

LVM KVM to Virtualbox
dd if=/dev/Volume01/Disk of=/tmp/image.raw
qemu-img convert -O vdi /tmp/image.raw test.vdi
rm /tmp/image.raw

Aucun commentaire:

Enregistrer un commentaire