opnsense-tools/build/boot.sh

93 lines
2.6 KiB
Bash
Raw Permalink Normal View History

2016-05-23 23:07:39 +02:00
#!/bin/sh
# 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
. ./common.sh
2016-05-23 23:07:39 +02:00
if [ -z "${1}" ]; then
echo ">>> No image given."
exit 1
2016-05-23 23:07:39 +02:00
fi
IMAGE=$(find_image "${1}")
2016-05-23 23:07:39 +02:00
if [ ! -f "${IMAGE}" ]; then
echo ">>> No image found."
exit 1
fi
AHCI=ahci-hd; if [ "${1}" = "dvd" ]; then AHCI=ahci-cd;fi
2021-04-16 10:41:17 +02:00
setup_stage ${STAGEDIR}
TARGET=${STAGEDIR}/image.img
2022-02-16 16:41:22 +01:00
SPARE=${STAGEDIR}/disk.img
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}
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
echo ">>> Booting image ${IMAGE}:"
2016-05-23 23:07:39 +02:00
BRGDEV=bridge0
TAPLAN=tap0
TAPWAN=tap1
PHYDEV=em0
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
2016-05-23 23:07:39 +02:00
kldstat -qm vmm || kldload vmm
bhyveload -m ${MEM} -d ${TARGET} vm0
2021-12-13 12:20:44 +01:00
while bhyve -c 1 -m ${MEM} -AHP \
-s 0,hostbridge \
-s 1:0,virtio-net,${TAPLAN} \
-s 1:1,virtio-net,${TAPWAN} \
-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