#!/bin/bash
#
# Boot up subhost as if a vitual machine.
+# Allow CONFIG given as environment
#
-# There is already an existing network namespace of the right name,
-# and there are one or more disks at /opt/subhost/$NAME/disk$i
#set -x
: ${NSNAME=$NAME}
: ${SUBHOST=/opt/subhost/$NAME}
: ${TARGET=$SUBHOST/live}
-: ${INITRD=$SUBHOST/initrd.gz}
: ${CONFIG=$SUBHOST/config}
+# sets DISKS=( ... ) and BRIDGES=( ... )
[ -r "$CONFIG" ] && . $CONFIG
+if [ -z "$DISKS" ] ; then
+ echo "Missing CONFIG" >&2
+ exit 1
+fi
+
# Generate a mac address for given arguments pass through 40-bit b2sum
# and with 02: prefix.
macaddr() {
ln -s $(tty) $CONSOLE
}
+####################
+# Pretend boot
+
setup_cables
setup_rootfs
-setup_console || exit 1
-
-# Install the current subhost-init startup script
-cp -p $(realpath $(dirname $0))/subhost-init startup $TARGET/
+setup_console
######################################################################
-# Run the subhost
+# Run the subhost init
ip netns exec $NSNAME unshare --fork --pid --mount-proc --kill-child \
- --uts --ipc --mount --cgroup chroot $TARGET /startup
+ --uts --ipc --mount --cgroup chroot $TARGET /sbin/init
######################################################################
# Cleanup on exit