Instal KVM (Kernel-based Virtual Machine)

Install

#!/bin/bash

# configure locale
wget -q http://www.panticz.de/sites/default/files/scripts/configure_locale.sh -O - | bash -

# update repository
apt-get update
 
# install debian xen kernel
apt-get install -y kvm libvirt-bin virtinst
 
# configure network bridge
virsh net-autostart default
 
# configure LVM
mkdir /etc/libvirt/storage
cat < /etc/libvirt/storage/vg0.xml
vg0/dev/vg0
EOF

virsh pool-define /etc/libvirt/storage/vg0.xml
virsh pool-autostart vg0
>
# configure locale
wget -q http://www.panticz.de/sites/default/files/scripts/configure_locale.sh -O - | bash -
 
# install on ubuntu
sudo apt install -y qemu-kvm
# apt-get install -y qemu kvm ubuntu-vm-builder
 
# install on debian
apt-get install -y kvm
apt-get install -y libvirt-bin
apt-get install -y virtinst
 
/etc/init.d/libvirt-bin restart
 
# net
virsh net-start default
virsh net-autostart default
 
# vg
mkdir /etc/libvirt/storage
cat <<EOF> /etc/libvirt/storage/vg0.xml
<pool type='logical'>
  <name>vg0</name>
  <target>
    <path>/dev/vg0</path>
  </target>
</pool>
EOF
 
virsh pool-define /etc/libvirt/storage/vg0.xml
virsh pool-autostart vg0
virsh pool-start vg0
 
# check CPU virtualization supports 
sudo kvm-ok
or
egrep '^flags.* (vmx|svm)' /proc/cpuinfo
 
# install PXE boot ROM
# http://mirrors.kernel.org/ubuntu/pool/main/i/ipxe/ipxe-qemu_1.0.0+git-20131111.c3d1e78-2ubuntu1.1_all.deb
apt-get install kvm-ipxe
http://rom-o-matic.net/etherboot/etherboot-git/etherboot.git/contrib/rom-o-matic/
1. NIC/ROM type: e1000:e1000-0x1026-82545gm-copper -- [8086,1026]
2. ROM output format: Binary ROM Image(.zrom)
3. Configure, ASK_BOOT: -1
4. Get ROM
 
# copy rom to kvm directory
mv ~/eb-git-e1000.zrom /usr/share/kvm/pxe-e1000.bin
 
# EXAMPLES
 
# boot from phisical harddisc
kvm -m 1024 -hda /dev/sda -net nic -net user
 
# livecd boot
kvm -m 256 -cdrom cd.iso -boot d disk.img -soundhw es1370 -usb -usbdevice tablet  -net nic,model=virtio -net user
# -net nic,model=rtl8139 -net user
 
# pxe network boot
kvm -net nic,model=e1000,macaddr=00:22:22:22:22:22 -net tap -boot n
 
kvm -net nic,model=virtio,macaddr=00:22:22:22:22:22 -net tap -boot n -vnc :0
kvm -net nic,model=e1000,macaddr=00:22:22:22:22:22 -net tap -boot n -vnc 0.0.0.0:1 -k en-us
 
vncviewer 192.168.254.225:1
 
ubuntu-vm-builder kvm hardy \
--mem 256 \
--domain test \
--dest kvmhost \
--arch i386 \
--hostname kvmhost \
--user test \
--pass test \
--mirror http://archive.ubuntu.com/ubuntu \
--components main,universe \
--addpkg vim \
--libvirt qemu:///system 
 
 
virt-install \
--name ubuntu1804 \
--ram 4096 \
--disk path=/var/kvm/images/ubuntu1804.img,size=30 \
--vcpus 2 \
--os-type linux \
--os-variant ubuntu17.10 \
--network bridge=br0 \
--graphics none \
--console pty,target_type=serial \
--location 'http://jp.archive.ubuntu.com/ubuntu/dists/bionic/main/installer-amd64/' \
--extra-args 'console=ttyS0,115200n8 serial'
 
virsh shutdown ubuntu1804
guestmount -d ubuntu1804 -i /mnt
 
# optional: chroot
mount /proc /mnt/proc --bind
mount /dev /mnt/dev --bind
mount /sys /mnt/sys --bind
chroot /mnt
mount -t devpts none /dev/pts/
 
exit
umount  -R /mnt
 
 
ln -s /mnt/lib/systemd/system/getty@.service /mnt/etc/systemd/system/getty.target.wants/getty@ttyS0.service
umount /mnt
virsh start ubuntu1804 --console
# Ctrl + ] key
 
 
# windows xp installation
qemu-iumount  -R /mntmg create winxp.img -f qcow2 8G
kvm -m 1024 -cpu host -smp 2 -cdrom xppro_sp3.iso -boot d  winxp.img -usb -usbdevice tablet -net nic,model=rtl8139 -net user  -vga qxl 
 
# windows xp run
kvm -m 1024 kvm_xp.img -usb -usbdevice tablet -net nic,model=virtio -net user
 
# resize image
qemu-img resize /var/lib/libvirt/images/vm1.qcow2 +10GB
 
# manual autostart all vms
cd /etc/libvirt/qemu/autostart
for i in *.xml; do
    virsh start ${i%.*}
done
 
# test
-pcidevice host=bus:dev.func

Ubuntu cloud images
https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img

Enabling nested virtualization in KVM
https://docs.fedoraproject.org/en-US/quick-docs/using-nested-virtualization-in-kvm/

cat <<EOF>>umount  -R /mnt /etc/modprobe.d/kvm.conf
options kvm_intel nested=1
options kvm_amd nested=1
EOF

VirtIO driver
https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.173-2/

UI

sudo apt install aqemu

Links
https://linux.die.net/man/1/qemu-kvm
https://help.ubuntu.com/community/KVM/Installation
https://help.ubuntu.com/community/KVM
http://www.linux-kvm.com/content/tip-how-setup-windows-guest-paravirtual-network-drivers
http://www.linux-kvm.com/content/preview-redhat-54-windows-virtio-drivers-part-1
http://kvm.qumranet.com/kvmwiki/Front_Page
http://alien.slackbook.org/dokuwiki/doku.php?id=slackware:qemu
http://www.h7.dion.ne.jp/~qemu-win/HowToNetwork-en.html