#!/bin/bash # 1.3.0 # Script creates QEMU disk VMware HDD and runs QEMU VM with VyOS Installation ISO attached to CDROM qemu_disk='vyos-1.3.0-amd64.vmdk' binary_list=('free' 'awk' 'qemu-img' 'qemu-system-x86_64' 'kvm') image_size='2G' image_port='3355' vyos_iso="$1" function check_iso { [ -z "$vyos_iso" ] && echo -e "\nEnter name of VyOS installation ISO, exiting\n" && exit 1 [ ! -s "$vyos_iso" ] && echo "File '$vyos_iso' doesn't exist or it is zero, exiting" && exit 1 } function check_binaries { for binary in "${binary_list[@]}"; do type -P "$binary" 1>/dev/null [ "$?" != 0 ] && echo -e "\n'$binary' required but not found, exiting!\n" && exit 1 done } function check_ram { free_ram="$(free -m | grep Mem | awk '{print $4}')" free_ram_use=$(("free_ram" - 1000)) } function start_image { qemu-img create -f vmdk "$qemu_disk" "$image_size" [[ $(qemu-system-x86_64 -boot c -cdrom "$vyos_iso" -hda "$qemu_disk" -m "$free_ram_use" -enable-kvm -serial telnet:127.0.0.1:"$image_port",server,nowait 2>/dev/null &) ]] && echo "Qemu succesfully started" || echo "Qemu can't be started, exiting"; exit } check_iso check_binaries check_ram start_image exit 0