#!/bin/bash # Copyright 2015 Canonical, Ltd. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . ARCH=${ARCH-"`uname -m`"} MEM=${MEM-"1024"} INSTALLER=${INSTALLER-"installer.img"} UEFI=${UEFI-"1"} TARGET=${TARGET-"target.img"} GRAPHIC="-serial stdio" SPORT=2445 QEMU=`which qemu-system-$ARCH`; case $ARCH in i386|x86_64) PKG="ovmf qemu-system-x86" if [ "${UEFI}" == "1" ]; then UEFI=" -bios /usr/share/ovmf/OVMF.fd" else UEFI="" fi ;; arm*) PKG=qemu-system-arm ;; ppc*) PKG=qemu-system-ppc ;; *) echo "Unsupported arch: $ARCH"; exit 1; ;; esac if [ -z $QEMU ]; then echo "Installing required packages: $PKG" sudo apt-get install $PKG || { echo "Failed to install qemu-system package(s) $PKG"; if echo $PKG | grep -q ovmf; then echo "ovmf package is only available in multiverse." echo "You can enable multiverse and try again:" echo "sudo add-apt-repository multiverse" fi exit 1; } fi # don't spawn sdl if we're headless if [ -z $DISPLAY ]; then GRAPHIC="-nographic" fi # always recreate the target image echo "Creating dummy target image: ${TARGET}" qemu-img create -f raw ${TARGET} 10G # TODO, curses should work, make serial|nographic optional echo "Launching Installer VM" sudo qemu-system-$ARCH -smp 2 -m $MEM -enable-kvm $UEFI\ -drive format=raw,cache=unsafe,if=ide,file=$INSTALLER,serial=QM_INSTALL_01 \ -drive format=raw,cache=unsafe,if=ide,file=$TARGET,serial=QM_TARGET_01 \ -global isa-fdc.driveA= -net user \ -net nic,model=e1000 \ -net nic,model=virtio \ -net nic,model=i82559er \ -monitor telnet:127.0.0.1:2446,server,nowait \ ${GRAPHIC} exit $?