2015-06-15 19:12:26 +00:00
|
|
|
#!/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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
2015-06-17 18:09:52 +00:00
|
|
|
ARCH=${ARCH-"`uname -m`"}
|
2015-06-15 19:12:26 +00:00
|
|
|
MEM=${MEM-"1024"}
|
|
|
|
INSTALLER=${INSTALLER-"installer.img"}
|
2015-09-22 18:37:51 +00:00
|
|
|
UEFI=${UEFI-"1"}
|
2015-06-15 19:12:26 +00:00
|
|
|
TARGET=${TARGET-"target.img"}
|
2015-09-29 20:55:07 +00:00
|
|
|
GRAPHIC="-serial stdio"
|
2015-06-15 19:12:26 +00:00
|
|
|
SPORT=2445
|
|
|
|
|
2015-06-17 18:09:52 +00:00
|
|
|
QEMU=`which qemu-system-$ARCH`;
|
2015-09-29 20:55:07 +00:00
|
|
|
case $ARCH in
|
|
|
|
i386|x86_64)
|
2015-09-30 17:49:06 +00:00
|
|
|
PKG="ovmf qemu-system-x86"
|
2015-09-29 20:55:07 +00:00
|
|
|
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
|
2015-06-17 18:09:52 +00:00
|
|
|
if [ -z $QEMU ]; then
|
2015-09-29 20:55:07 +00:00
|
|
|
echo "Installing required packages: $PKG"
|
2015-06-17 18:09:52 +00:00
|
|
|
sudo apt-get install $PKG || {
|
2015-09-29 20:55:07 +00:00
|
|
|
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;
|
2015-06-17 18:09:52 +00:00
|
|
|
}
|
|
|
|
fi
|
2015-09-29 20:55:07 +00:00
|
|
|
# don't spawn sdl if we're headless
|
|
|
|
if [ -z $DISPLAY ]; then
|
|
|
|
GRAPHIC="-nographic"
|
2015-09-22 18:37:51 +00:00
|
|
|
fi
|
|
|
|
|
2015-07-06 15:55:49 +00:00
|
|
|
# always recreate the target image
|
2015-09-29 20:55:07 +00:00
|
|
|
echo "Creating dummy target image: ${TARGET}"
|
2015-10-26 14:57:19 +00:00
|
|
|
qemu-img create -f raw ${TARGET}_1 5G
|
|
|
|
qemu-img create -f raw ${TARGET}_2 1G
|
|
|
|
qemu-img create -f raw ${TARGET}_3 1G
|
2015-12-04 15:01:19 +00:00
|
|
|
qemu-img create -f raw ${TARGET}_4 1G
|
2015-07-06 15:55:49 +00:00
|
|
|
|
2015-09-29 20:55:07 +00:00
|
|
|
# TODO, curses should work, make serial|nographic optional
|
|
|
|
echo "Launching Installer VM"
|
2015-09-22 18:37:51 +00:00
|
|
|
sudo qemu-system-$ARCH -smp 2 -m $MEM -enable-kvm $UEFI\
|
2015-10-26 14:57:19 +00:00
|
|
|
-drive snapshot=on,format=raw,cache=unsafe,if=ide,file=$INSTALLER,serial=QM_INSTALL_01 \
|
|
|
|
-drive format=raw,cache=unsafe,if=ide,file=${TARGET}_1,serial=QM_TARGET_01 \
|
2015-12-04 15:01:19 +00:00
|
|
|
-drive format=raw,cache=unsafe,if=virtio,file=${TARGET}_2,serial=QM_TARGET_02 \
|
|
|
|
-drive format=raw,cache=unsafe,if=virtio,file=${TARGET}_3,serial=QM_TARGET_03 \
|
|
|
|
-drive format=raw,cache=unsafe,if=virtio,file=${TARGET}_4,serial=QM_TARGET_04 \
|
2015-07-06 18:55:42 +00:00
|
|
|
-global isa-fdc.driveA= -net user \
|
2015-06-25 21:50:13 +00:00
|
|
|
-net nic,model=e1000 \
|
|
|
|
-net nic,model=virtio \
|
|
|
|
-net nic,model=i82559er \
|
2015-09-29 20:55:07 +00:00
|
|
|
-monitor telnet:127.0.0.1:2446,server,nowait \
|
|
|
|
${GRAPHIC}
|
2015-06-15 19:12:26 +00:00
|
|
|
|
|
|
|
exit $?
|