2016-05-23 23:07:39 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2021-07-05 10:26:52 +02:00
|
|
|
# Copyright (c) 2016-2021 Franco Fichtner <franco@opnsense.org>
|
2016-05-23 23:07:39 +02:00
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
|
|
|
#
|
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
#
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
# SUCH DAMAGE.
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2021-04-16 10:41:17 +02:00
|
|
|
MEM=2048
|
2016-05-23 23:07:39 +02:00
|
|
|
SELF=boot
|
|
|
|
|
2017-04-27 19:14:36 +02:00
|
|
|
. ./common.sh
|
2016-05-23 23:07:39 +02:00
|
|
|
|
|
|
|
if [ -z "${1}" ]; then
|
2021-07-08 12:43:04 +02:00
|
|
|
echo ">>> No image given."
|
2020-07-21 17:50:04 +02:00
|
|
|
exit 1
|
2016-05-23 23:07:39 +02:00
|
|
|
fi
|
|
|
|
|
2021-07-08 12:43:04 +02:00
|
|
|
IMAGE=$(find_image "${1}")
|
2016-05-23 23:07:39 +02:00
|
|
|
|
2020-07-21 17:50:04 +02:00
|
|
|
if [ ! -f "${IMAGE}" ]; then
|
2021-07-08 12:43:04 +02:00
|
|
|
echo ">>> No image found."
|
2020-07-21 17:50:04 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-04-19 10:05:35 +02:00
|
|
|
AHCI=ahci-hd; if [ "${1}" = "dvd" ]; then AHCI=ahci-cd;fi
|
|
|
|
|
2021-04-16 10:41:17 +02:00
|
|
|
setup_stage ${STAGEDIR}
|
|
|
|
|
2021-07-05 10:26:52 +02:00
|
|
|
TARGET=${STAGEDIR}/image.img
|
2022-02-16 16:41:22 +01:00
|
|
|
SPARE=${STAGEDIR}/disk.img
|
2021-07-05 10:26:52 +02:00
|
|
|
|
|
|
|
if [ -z "${IMAGE%%*.bz2}" ]; then
|
|
|
|
echo -n ">>> Uncompressing image ${IMAGE}... "
|
|
|
|
bunzip2 -c ${IMAGE} > ${TARGET}
|
|
|
|
echo "done"
|
|
|
|
else
|
2022-02-16 16:41:22 +01:00
|
|
|
cp ${IMAGE} ${TARGET}
|
2021-07-05 10:26:52 +02:00
|
|
|
fi
|
|
|
|
|
2022-02-16 16:41:22 +01:00
|
|
|
truncate -s +5G ${TARGET}
|
|
|
|
truncate -s 10G ${SPARE}
|
2021-04-16 10:41:17 +02:00
|
|
|
|
2021-07-05 10:26:52 +02:00
|
|
|
echo ">>> Booting image ${IMAGE}:"
|
2016-05-23 23:07:39 +02:00
|
|
|
|
2021-04-19 10:05:35 +02:00
|
|
|
BRGDEV=bridge0
|
|
|
|
TAPLAN=tap0
|
|
|
|
TAPWAN=tap1
|
|
|
|
PHYDEV=em0
|
2020-07-21 17:50:04 +02:00
|
|
|
|
2021-04-19 10:05:35 +02:00
|
|
|
if ! ifconfig ${BRGDEV}; then BRGDEV=$(ifconfig bridge create); fi
|
|
|
|
if ! ifconfig ${TAPLAN}; then TAPLAN=$(ifconfig tap create); fi
|
|
|
|
if ! ifconfig ${TAPWAN}; then TAPWAN=$(ifconfig tap create); fi
|
|
|
|
|
|
|
|
ifconfig ${BRGDEV} addm ${TAPWAN} addm ${PHYDEV} up || true
|
|
|
|
ifconfig ${TAPWAN} up
|
2020-07-21 17:50:04 +02:00
|
|
|
|
2016-05-23 23:07:39 +02:00
|
|
|
kldstat -qm vmm || kldload vmm
|
2021-07-05 10:26:52 +02:00
|
|
|
bhyveload -m ${MEM} -d ${TARGET} vm0
|
2021-12-13 12:20:44 +01:00
|
|
|
while bhyve -c 1 -m ${MEM} -AHP \
|
2021-04-19 10:05:35 +02:00
|
|
|
-s 0,hostbridge \
|
|
|
|
-s 1:0,virtio-net,${TAPLAN} \
|
|
|
|
-s 1:1,virtio-net,${TAPWAN} \
|
2021-07-05 10:26:52 +02:00
|
|
|
-s 2:0,${AHCI},${TARGET} \
|
2022-02-16 16:41:22 +01:00
|
|
|
-s 3:0,ahci-hd,${SPARE} \
|
2016-05-23 23:07:39 +02:00
|
|
|
-s 31,lpc -l com1,stdio \
|
2021-12-13 12:20:44 +01:00
|
|
|
vm0; do
|
|
|
|
bhyvectl --destroy --vm=vm0
|
|
|
|
bhyveload -m ${MEM} -d ${TARGET} vm0
|
|
|
|
done
|
2016-05-23 23:07:39 +02:00
|
|
|
bhyvectl --destroy --vm=vm0
|