These days I created Xen Hypervisor as a VM for studying. I choosed Ubuntu as a Dom0 distro, followed the Wiki.
To use HVM DomU, I have to set host cpu emulation explicitly because Dom0 VM needs Hardware-Assisted Virtualizaton of the host cpu.
# ensure host machine cpu support assisted virtualization # in my case it's intel, in case amd that's smx $ cat /proc/cpuinfo | grep vmx flags ... vmx ... # qemu command for start xen vm for nested vmx # "-cpu host" or "qemu64,+vmx" $ qemu-system-x86_64 -cpu host -m 4G -enable-kvm -drive -hda=/data/xen.img -boot order=c \ -device virtio-net,netdev=tap0 -netdev tap,id=tap0,ifname=tap0,script=no,downscript=no # in Xen VM, ensure HVM is supported $ xl dmesg | grep -i hvm ... (XEN) HVM: VMX enabled ...
Besides, in xen config file I have to comment out the following line otherwise the HVM doesn’t start.
# /etc/xen/ubuntu-hvm.cfg # HVM doesn't start by the error such as # libxl: error: libxl_dm.c:2426:device_model_spawn_outcome: Domain 2:domain 2 device model: spawn failed (rc=-3) # xen_version : 4.11.4-pre ... sdl = 1 ...
# /etc/xen/ubuntu-hvm.cfg # comment out the line ... # sdl = 1 ..
Appendix
# create tap device and bridge for Xen VM $ tunctl -t tap0 $ brctl addbr br0 $ brctl addif br0 tap0 $ ip a add dev br0 192.168.0.90/24 $ ifconfig br0 up $ ifconfig tap0 up $ ip a show br0 $ ip l show master br0 # fire wall rules for ip forwarding and NAT from Xen # ensure ip fowarding is enabled $ sysctl net.ipv4.ip_forward net.ipv4.ip_forward = 1 $ iptables -t filter -I FORWARD -i br0 -j ACCEPT $ iptables -t filter -I FORWARD -o br0 -j ACCEPT $ iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE # or $ firewall-cmd --zone=public --add-masquerade --permanent