summaryrefslogtreecommitdiffstats
path: root/libexec/container/start-qemu
diff options
context:
space:
mode:
authorSimon Spöhel <simon@spoehel.ch>2021-04-14 15:30:50 +0000
committerSakirnth Nagarasa <sakirnth@gmail.com>2021-09-01 08:24:59 +0000
commit8f5701860d48977fadbfaa1ca652d76b6cb89759 (patch)
treea7e0c5098e7d6b23bedc73aba1030331aa3dbcb4 /libexec/container/start-qemu
parentStart (dummy commit). (diff)
downloadcompute-tools-8f5701860d48977fadbfaa1ca652d76b6cb89759.tar.xz
compute-tools-8f5701860d48977fadbfaa1ca652d76b6cb89759.zip
Adding basic functionality to start a VM.
Diffstat (limited to 'libexec/container/start-qemu')
-rwxr-xr-xlibexec/container/start-qemu115
1 files changed, 16 insertions, 99 deletions
diff --git a/libexec/container/start-qemu b/libexec/container/start-qemu
index b7953c1..491278c 100755
--- a/libexec/container/start-qemu
+++ b/libexec/container/start-qemu
@@ -125,9 +125,9 @@ case "${NAME}" in
;;
esac
-if [ ! -e "${MACHINES}/${NAME}" ]
+if [ ! -e "${MACHINES}/${NAME}.img" ]
then
- echo "'${NAME}': no such container" >&2
+ echo "'${NAME}': no such vm" >&2
exit 1
fi
@@ -166,7 +166,9 @@ then
fi
HOST_ARCHITECTURE="$(dpkg --print-architecture)"
-MACHINE_ARCHITECTURE="$(chroot ${MACHINES}/${NAME} dpkg --print-architecture)"
+#FIXME
+#MACHINE_ARCHITECTURE="$(chroot ${MACHINES}/${NAME} dpkg --print-architecture)"
+MACHINE_ARCHITECTURE=amd64
case "${HOST_ARCHITECTURE}" in
amd64)
@@ -201,91 +203,6 @@ esac
# config
if [ -e "${CONFIG}/${NAME}.conf" ]
then
- CNT_OVERLAY="$(awk -Fcnt.overlay= '/^cnt.overlay=/ { print $2 }' ${CONFIG}/${NAME}.conf)"
- CNT_OVERLAY_OPTIONS="$(awk -Fcnt.overlay-options= '/^cnt.overlay-options=/ { print $2 }' ${CONFIG}/${NAME}.conf)"
-
- if [ -n "${CNT_OVERLAY}" ]
- then
- CNT_OVERLAYS="$(echo ${CNT_OVERLAY} | sed -e 's|;| |g')"
-
- COUNT="0"
- for CNT_OVERLAY in ${CNT_OVERLAYS}
- do
- DIRECTORY_LOWER="$(echo ${CNT_OVERLAY} | awk -F: '{ print $1 }')"
- DIRECTORY_UPPER="$(echo ${CNT_OVERLAY} | awk -F: '{ print $2 }')"
- DIRECTORY_WORK="$(echo ${CNT_OVERLAY} | awk -F: '{ print $3 }')"
- DIRECTORY_MERGED="$(echo ${CNT_OVERLAY} | awk -F: '{ print $4 }')"
-
- COUNT="$((${COUNT} + 1))"
- CNT_OVERLAY_OPTION="$(echo ${CNT_OVERLAY_OPTIONS} | awk -F ';' "{ print \$${COUNT} }")"
-
- for DIRECTORY in "${DIRECTORY_LOWER}" "${DIRECTORY_UPPER}" "${DIRECTORY_WORK}" "${DIRECTORY_MERGED}"
- do
- mkdir -p "${DIRECTORY}"
- done
-
- if ! findmnt -n -o SOURCE "${DIRECTORY_MERGED}" | grep -qs '^cnt.overlay-'
- then
- if [ -n "${CNT_OVERLAY_OPTION}" ]
- then
- CNT_OVERLAY_OPTION="-o ${CNT_OVERLAY_OPTION}"
- fi
-
- mount cnt.overlay-${NAME} -t overlay ${CNT_OVERLAY_OPTION} -olowerdir="${DIRECTORY_LOWER}",upperdir="${DIRECTORY_UPPER}",workdir="${DIRECTORY_WORK}",default_permissions "${DIRECTORY_MERGED}"
- fi
- done
- fi
-
- BIND="$(awk -Fbind= '/^bind=/ { print $2 }' ${CONFIG}/${NAME}.conf)"
-
- if [ -n "${BIND}" ]
- then
- BINDS="$(echo ${BIND} | sed -e 's|;| |g')"
-
- for BIND in ${BINDS}
- do
- DIRECTORY="$(echo ${BIND} | awk -F: '{ print $1 }')"
-
- if [ ! -e "${DIRECTORY}" ]
- then
- echo "'${DIRECTORY}': creating non-existing directory for bind mounting"
- mkdir -p "${DIRECTORY}"
- fi
- done
-
- BIND=""
-
- for DIRECTORIES in ${BINDS}
- do
- BIND="${BIND} --bind ${DIRECTORIES}"
- done
- fi
-
- BIND_RO="$(awk -Fbind-ro= '/^bind-ro=/ { print $2 }' ${CONFIG}/${NAME}.conf)"
-
- if [ -n "${BIND_RO}" ]
- then
- BINDS_RO="$(echo ${BIND_RO} | sed -e 's|;| |g')"
-
- for BIND_RO in ${BINDS_RO}
- do
- DIRECTORY="$(echo ${BIND_RO} | awk -F: '{ print $1 }')"
-
- if [ ! -e "${DIRECTORY}" ]
- then
- echo "'${DIRECTORY}': creating non-existing directory for bind-ro mounting"
- mkdir -p "${DIRECTORY}"
- fi
- done
-
- BIND_RO=""
-
- for DIRECTORIES in ${BINDS_RO}
- do
- BIND_RO="${BIND_RO} --bind-ro ${DIRECTORIES}"
- done
- fi
-
BOOT="$(awk -Fboot= '/^boot=/ { print $2 }' ${CONFIG}/${NAME}.conf || echo yes)"
case "${BOOT}" in
@@ -311,7 +228,7 @@ then
esac
DIRECTORY="$(awk -Fdirectory= '/^directory=/ { print $2 }' ${CONFIG}/${NAME}.conf || echo ${MACHINES}/${NAMES})"
- DIRECTORY="--directory ${DIRECTORY}"
+ DIRECTORY="-drive file=${DIRECTORY}.img,format=raw,if=virtio"
DROP_CAPABILITY="$(awk -Fdrop-capability= '/^drop-capability=/ { print $2 }' ${CONFIG}/${NAME}.conf)"
@@ -350,9 +267,10 @@ then
*)
for VETH in ${VETHS}
do
- NETWORK_VETH_EXTRA="${NETWORK_VETH_EXTRA} --network-veth-extra=${VETH}"
INTERFACE="$(echo ${VETH} | awk -F: '{ print $1 }')"
+ NETWORK_VETH_EXTRA="${NETWORK_VETH_EXTRA} -netdev tap,id=${INTERFACE},ifname=${INTERFACE},script=no,downscript=no -device virtio-net-pci,netdev=${INTERFACE}"
+
if [ "$(echo ${INTERFACE} | wc -c)" -gt 15 ]
then
echo "'${INTERFACE}': name exceeds maximum of 15 characters, network might be not working."
@@ -452,7 +370,7 @@ fi
case "${SYSTEMCTL}" in
true)
- systemctl start ${PROGRAM}@${NAME}.service
+ systemctl start kvm@${NAME}.service
# Post hooks
for FILE in "${HOOKS}/post-${COMMAND}".* "${HOOKS}/${NAME}.post-${COMMAND}"
@@ -469,12 +387,6 @@ esac
case "${START}" in
true)
-
- case "${SET_PROPERTY}" in
- true)
- systemctl --runtime set-property ${NAME} ${BLOCK_IO_DEVICE_WEIGHT} ${BLOCK_IO_READ_BANDWIDTH} ${BLOCK_IO_WEIGHT} ${BLOCK_IO_WRITE_BANDWIDTH} ${CPU_QUOTA} ${CPU_SHARES} ${MEMORY_LIMIT} ${TASKS_MAX}
- ;;
- esac
;;
*)
@@ -486,8 +398,13 @@ case "${START}" in
;;
esac
- ${SETARCH} systemd-nspawn --keep-unit ${BIND} ${BIND_RO} ${BOOT} ${CAPABILITY} ${DIRECTORY} ${DROP_CAPABILITY} ${MACHINE} ${NETWORK_VETH_EXTRA} ${LINK_JOURNAL} ${REGISTER}
-
+ qemu-system-x86_64 \
+ -machine accel=kvm:tcg \
+ ${DIRECTORY} \
+ -m 4G \
+ -name ${NAME} \
+ ${NETWORK_VETH_EXTRA} \
+ -bios /usr/share/qemu/OVMF.fd
case "${VERBOSE}" in
true)