{{ :qemu:qemu_128x128.png?nolink&96|}} ====== libvirt and qemu ====== If, for some reason, our virtual solutions VirtualBox and Level2 cloud image do not meet your needs, you can use the qemu and/or Libvirt emulator. Please note that the images used in qemu and/or Libvirt are slightly different from those available for download in the corresponding section. You can get the image by contacting us and specifying the version you need In this short guide, we assume that you already have **qemu** installed (**qemu-system-x86_64** as well as the related **qemu-img**), **util-linux**, **kvm_intel/kvm_amd** module is loaded and **virt-manager** (with daemons up and running) if desired. Also, any network related configurations will not be covered here. The example **will use a bridge** as the easiest way to get the system accessible. Network settings are individual and left to your discretion, all documentation is [[https://www.qemu.org/docs/master/index.html|available online]] We'll cover both options, but the commonality between the two is the acquisition and preparation of disk images for data and system. Put this script next to the image file, the script will automatically select the latest version and create two image files for the data and the system. You can also specify the desired size of the data disk by adding the size as an argument to the script ''./mkdisks.sh 16G'' You will need **sudo** privileges to execute this script, so use it as superuser or set the appropriate bits to related executables #!/bin/bash IMG=$(find . -regextype posix-extended -regex "\./[0-9]+\.[0-9]+\.[0-9]+\.[0-9]{4,5}\.img" | sort -t. -k1,1n -k2,2n -k3,3n -k4,4n | tail -n 1) TARGET_IMG_DISK="./root.img" TARGET_DATA_DISK="./data.img" TARGET_DATA_DISK_SIZE="8G" if [ ! -z $1 ]; then TARGET_DATA_DISK_SIZE=$1 fi qemu-img create -f raw $TARGET_DATA_DISK $TARGET_DATA_DISK_SIZE fdisk $TARGET_DATA_DISK < and we're ready to go ===== Qemu native ===== Here is a starting point to run WebHMI in qemu #!/bin/bash BR="virbr0" if [ ! -z $1 ]; then BR=$1 fi qemu-system-x86_64 -m 128M -smp 1 -enable-kvm \ -device ide-hd,drive=d0,bus=ide.0 \ -device ide-hd,drive=d1,bus=ide.1 \ -drive file=root.img,id=d0,if=none,bus=0,unit=0,format=raw \ -drive file=data.img,id=d1,if=none,bus=1,unit=0,format=qcow2 \ -netdev bridge,id=net0,br="$BR" \ -device virtio-net-pci,netdev=net0 \ -netdev bridge,id=net1,br="$BR" \ -device virtio-net-pci,netdev=net1 \ -nographic In this example, ''virbr0'' is a bridge that is usually pre configured by virt-manager. You may use your own or pass it as an argument while running. For the first launch, it is recommended to use two interfaces in the WebHMI, since **the first one will always be assigned as 192.168.1.1**, regardless of the configuration of the dhcp server. But the second interface is configured as a dhcp client and receives the address according to the settings of your server. Make sure that your ''/etc/qemu/bridge.conf'' file contains the line **allow virbr0** or **allow all** We also recommend running WebHMI from terminal emulators like tmux or in the background once you are confident with the address settings {{ :qemu:qemu-native-kvm.mp4?912x570}} ===== Qemu via libvirt ===== Virt-manager is a user-friendly graphical shell for managing virtual machines. The process of creating and launching is shown in the video, here are the key points to pay attention to: * The pool is created once, you can place your images in any folder * Architecture, as in the previous case, is x86_64 (usually it is the default) * All disks connected to the virtual machine must be SATA * Make sure, that boot order is correct (root.img) {{ :qemu:qemu-virt-manager.mp4?912x570 }} Once you have access to the web interface, configure your interfaces properly and remove redundant ones if necessary For reboot persistent you can create a shell script that will run an instance in tmux #!/bin/bash tmux new -d -s wh 'cd /path/to/your/folder/ && ./qemu.sh' and place it to your crontab ''@reboot sleep 5 && /path/to/your/script.sh'' or ''rc.local'' or create a systemd/sysv service