Sunday, May 28, 2017

KVM (Kernel Virtual Machine)


 
check whether virtualization extensions is enabled in BIOS.
 
intel based processor 
[root@server ~]# grep -e 'vmx' /proc/cpuinfo



amd based

[root@server ~]# grep -e 'svm' /proc/cpuinfo

The output should contains kvm_intel for intel-based hosts or kvm_amd for amd-based hosts.






Virt-manager : gui tools
libvirt-client : CL Tool
virt-install : create virtual machines
libvirt : server and host side libaries

required packages

install qemu-kvm libvirt-bin virtinst bridge-utils









root@dlp:~#
echo vhost_net >> /etc/modules


nano /etc/network/interface

before add bridge eth0 must be manual. Otherwise network collution if setup eth0 as static.

Auto eth0
iface eth0 inet manual
















ifup bro







ip addr



install image


trouble






solution





trouble :



solution
move iso file into different partition







add root user to kvm group
adduser root kvm





add root to libvirt

















update group membership






You should then be able to list your domains:
# virsh list --all
libvirt defaults to qemu:///session for non-root. So from you'll need to do:
$ virsh --connect qemu:///system list –all

convert vmdk to img

 
 
 
 
 
 
$ qemu-img convert -f vmdk -O raw image.vmdk image.img 20GB
$ qemu-img convert -f vmdk -O qcow2 image.vmdk image.qcow2
$ qemu-img convert -f vmdk -O qed image.vmdk image.qed
VBoxManage clonehd --format RAW vm.vdi vm.img

create virtual image

virt-install --name debian --ram 2048 --disk path=/media/data/virtual-envirnments/kvm/debian.img,device=disk,bus=virtio,sparse=true,format=raw,size=10 --vcpus 2 --os-type linux --network bridge=br0 --graphics none --console pty,target_type=serial -c '/media/kolwin/A/os/debian/debian-8.6.0-amd64-xfce-CD-1.iso'

above not working remove –graphics none then it' will work

basic operations
virsh start debian
virsh start debian –console
virsh shutdown debian
virsh destroy debian
virsh autostart debian
virsh autostart –disable debian
virsh list
virsh list –all
virsh console debian (cannot run without start debian)

Management tools
install libguestfs-tools virt-top

virt-ls -l -d debian /home

virt-cat -d debian /etc/passwd
virt-edit -d debian /etc/fstab
virt-df -d debian
virt-top

mount a disk for a virtual machine
guestmount -d debian -i /mnt
ll /mnt

spice server
virsh edit debian




















spice client
install virt-viewer


Network













login to virsh shell

virsh –connect qemu:///system

commands
virsh list

shutdown debian









































get host machine information

virsh help host

































add physical harddisk



virsh edit debian







This will make the host’s /dev/md/storage available in the guest as /dev/vdb. After changing a domain’s config by hand, you have to reload the config by hand. Log in to your host and issue this command:










# virsh attach-disk Guest1 --persistent /dev/sdc1 vdb --type cdrom --mode readonly





--type hdd
--type floppy

if using externel. Xml file
virsh update-device  guest-device.xml
Device updated successfully

install openedx
VBoxManage clonehd --format RAW vm.vdi vm.img

$ qemu-img convert -f vmdk -O raw image.vmdk image.img 20GB

virt-install -n openedx3 -r 3072 --vcpus 2 --os-type linux --disk /media/data/virtual-envirnments/kvm/openedx3.img,device=disk,bus=virtio -w bridge=br1,model=virtio -w bridge=br0,model=virtio --vnc --noautoconsol --import

delete

# virsh undefine VM_NAME

its working

get network info
virsh domiflist openedx3








attach-interface

virsh attach-interface --domain openedx3 --type bridge --source wlan0 --target eth1 --model virtio --persistent
box-disk3.img (eth0 192.168.2.106, eth1 192.168.1.211)
1. attach-interface --domain openedx3 --type bridge --source br1 --target vnet0 --model virtio --persistent
2. attach-interface --domain openedx3 --type bridge --source br0 --target vnet1 --model virtio –persistent

first 1 and 2 otherwide network not working. Openedx eth0=br1 eth1=br0


nano /etc/libvirt/qemu/openedx3.xml


add autostart

systemctl enable libvirtd

virsh autostart vmName
virsh autostart debianlenny1
virsh autostart VMNameHere --disable



No comments:

Post a Comment