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 https://wiki.debian.org/BridgeNetworkConnections

#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
address 192.168.1.3
netmask 255.255.255.0
gateway 192.168.1.254

dns-nameservers 192.168.1.1
dns-search home.lan

bridge_fd 9
bridge_hello 2
bridge_maxage 12
bridge_stp off

#------------------------------------------------------
# create bridge
#!/bin/bash
#----------

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 https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Virtualization_Administration_Guide/sect-gracefully-shut-down-guests-libvirt.html

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).
SHUTDOWN_TIMEOUT=45

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

virsh

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
quit


#virsh editor (bashrc)
EDITOR=/usr/bin/nano
export EDITOR


http://wiki.deimos.fr/KVM_:_Mise_en_place_de_KVM#System_performances
/etc/rc.local
# KSM
echo 1 > /sys/kernel/mm/ksm/run

/etc/sysctl.conf
# 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 :
/etc/modules
virtio_blk
virtio_pci
virtio_net

#provisionner une VM debian
iso=/path-to-iso/debian-7.3.0-amd64-netinst.iso
path=/mnt/vol1To/vm
name=testing
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
iso=/mnt/leonard/vol3To/08000.distrib/zz_os.softs/msw/Microsoft/PlateForms/Windows.7/distrib/W7.Ultimate.64.sp1.iso

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
/etc/libvirt/qemu

# 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