Skip to content

Instantly share code, notes, and snippets.

@muhamadazmy
Last active March 11, 2024 13:40
Show Gist options
  • Save muhamadazmy/a10bfb0cc77084c9b09dea5e49ec528e to your computer and use it in GitHub Desktop.
Save muhamadazmy/a10bfb0cc77084c9b09dea5e49ec528e to your computer and use it in GitHub Desktop.
Test a bootable tarball with cloud-hypervisor
#!env bash
socket="/tmp/virtiofs.sock"
# override this as well if u wanna change
# the vm entry point
init=/sbin/init
# pass to extracted tarball
dir=$1
kernel=$dir/boot/vmlinuz
initram=$dir/boot/initrd.img
fail() {
echo $1 >&2
exit 1
}
which virtiofsd-rs &>/dev/null || fail "virtiofsd-rs not found in PATH"
which cloud-hypervisor &>/dev/null || fail "cloud-hypervior not found in path"
if [ ! -f "${kernel}" ]; then
fail "kernel file not found"
fi
if [ ! -f "${initram}" ]; then
fail "kernel file not found"
fi
# start virtiofsd-rs in the background
sudo virtiofsd-rs --socket-path=/tmp/virtiofs.sock --shared-dir=$dir &
fspid=$!
cleanup() {
kill $fspid &>/dev/null || true
}
trap cleanup EXIT
sudo cloud-hypervisor \
--memory size=1024M,shared=on \
--kernel ${kernel} \
--initramfs ${initram} \
--fs tag=vroot,socket=${socket} \
--cmdline "rw console=ttyS0 reboot=k panic=1 root=vroot rootfstype=virtiofs rootdelay=30 init=${init}" \
--serial tty \
--console off
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment