QEMU Virtualization
Commands
show all VMs
virsh list --allstop VM
virsh shutdown myhost1start VM
virsh autostart myhost1reboot VM
virsh reboot myhost1reset VM (hard reset - not safe)
virsh reset myhost1delete VM
virsh shutdown myhost1
virsh undefine myhost1
virsh pool-destroy myhost1
rm -ri /path/to/images/myhost1
Get VM info
virsh dominfo vmName
virsh dominfo centos7-vm1
show VM images
virt-builder --list
build an Ubuntu VM
virt-builder ubuntu-16.04 \--size=20G --format qcow2 -o /var/lib/libvirt/images/ncbz01-disk01.qcow2 \--hostname ncbz01--network --timezone Asia/Kolkata \--firstboot-command "dpkg-reconfigure openssh-server" \--edit '/etc/default/grub:s/^GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=ttyS0,115200n8"/' \--run-command update-grub
Install Win10 VM on a Centos7 host
check if virtualization enabled in BIOS
egrep '(vmx|svm)' /proc/cpuinfoif above output shows VMX or SVM, then virt is supported
disable SELinux
sudo setenforce 0install Xwindow for Virt Manager GUI
yum install "@X Window System" xorg-x11-xauth xorg-x11-fonts-* xorg-x11-utils -y
check if kvm module is loaded
lsmod | grep kvm (reboot if now loaded)
install virt pkgs
yum install qemu-kvm libvirt libvirt-python libguestfs-tools virt-installsystemctl enable libvirtdsystemctl start libvirtdConfigure bridged networking
By default dhcpd based network bridge configured by libvirtd. You can verify that with the following commands:
{root@centos-7:~ }# brctl show{root@centos-7:~ }# virsh net-listAll VMs (guest machine) only have network access to other VMs on the same server. A private network 192.168.122.0/24 created for you. Verify it:
{root@centos-7:~ }# virsh net-dumpxml defaultIf you want your VMs avilable to other servers on your LAN, setup a a network bridge on the server that connected to the your LAN. Update your nic config file such as ifcfg-enp3s0 or em1:
{root@centos-7:~ }# vi /etc/sysconfig/network-scripts/enp3s0
Add line:
Edit /etc/sysconfig/network-scripts/ifcfg-br0 and add:
{root@centos-7:~ }# vi /etc/sysconfig/network-scripts/ifcfg-br0Append the following:
DEVICE="br0"
# I am getting ip from DHCP server #
BOOTPROTO="dhcp"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
ONBOOT="yes"
TYPE="Bridge"
DELAY="0"
Restart the networking service (warning ssh command will disconnect, it is better to reboot the box):
{root@centos-7:~ }# systemctl restart NetworkManager
Verify it with brctl command:
Create VM
copy Win10 ISO to Centos7 host (/mnt/hc/iso)
create Virtual Disk Image
qemu-img create -f qcow2 windows10.qcow2 40GInstall VM
virt-install \
--name windows10 \
--ram 32768 \
--vcpus 4 \
--os-type windows \
--os-variant win10 \
--virt-type kvm \
--graphics spice \
--disk path=windows10.qcow2,format=qcow2 \
--cdrom /path/to/Win10.iso