From a7f08ee111ba048558bf0e85946b2488f7b12ecc Mon Sep 17 00:00:00 2001 From: Razvan Deaconescu Date: Sun, 13 Oct 2024 12:26:10 +0300 Subject: [PATCH] elfloader-net: Add scripts Use scripts as quick actions for building and running the Unikraft ELF Loader. - `defconfig..`: default configs, used by build scripts - `build..`: scripts for building Unikraft images - `run..`: scripts for running Unikraft images - `README.scripts.md`: companion README with instructions Signed-off-by: Razvan Deaconescu --- elfloader-net/README.scripts.md | 34 +++++++++++++++++++++++++++ elfloader-net/build.fc.x86_64 | 16 +++++++++++++ elfloader-net/build.qemu.x86_64 | 16 +++++++++++++ elfloader-net/defconfig.fc.x86_64 | 29 +++++++++++++++++++++++ elfloader-net/defconfig.qemu.x86_64 | 29 +++++++++++++++++++++++ elfloader-net/run.fc.x86_64 | 34 +++++++++++++++++++++++++++ elfloader-net/run.qemu.x86_64 | 36 +++++++++++++++++++++++++++++ 7 files changed, 194 insertions(+) create mode 100644 elfloader-net/README.scripts.md create mode 100755 elfloader-net/build.fc.x86_64 create mode 100755 elfloader-net/build.qemu.x86_64 create mode 100644 elfloader-net/defconfig.fc.x86_64 create mode 100644 elfloader-net/defconfig.qemu.x86_64 create mode 100755 elfloader-net/run.fc.x86_64 create mode 100755 elfloader-net/run.qemu.x86_64 diff --git a/elfloader-net/README.scripts.md b/elfloader-net/README.scripts.md new file mode 100644 index 0000000..fcb3771 --- /dev/null +++ b/elfloader-net/README.scripts.md @@ -0,0 +1,34 @@ +# Scripts for the Unikraft ELF Loader with Networking Support + +These are companions instruction to the main instructions in the [`README`](README.md). + +Use scripts as quick actions for building and running the Unikraft ELF Loader: + +## Build for platform of choice + +```console +./build.qemu.x86_64 +./build.fc.x86_64 +``` + +## Build for platform of choice using a different compiler + +```console +CC=/path/to/compiler ./build..x86_64 +``` + +e.g. + +```console +CC=/usr/bin/gcc-12 ./build.qemu.x86_64 +CC=/usr/bin/clang ./build.qemu.x86_64 +CC=/usr/bin/gcc-12 ./build.fc.x86_64 +CC=/usr/bin/clang ./build.fc.x86_64 +``` + +## Run on platform of choice + +```console +./run.qemu.x86_64 +./run.fc.x86_64 +``` diff --git a/elfloader-net/build.fc.x86_64 b/elfloader-net/build.fc.x86_64 new file mode 100755 index 0000000..2cab43c --- /dev/null +++ b/elfloader-net/build.fc.x86_64 @@ -0,0 +1,16 @@ +#!/bin/sh + +test -d "../repos/unikraft" || git clone https://github.com/unikraft/unikraft ../repos/unikraft +test -d "../repos/apps/elfloader" || git clone https://github.com/unikraft/app-elfloader ../repos/apps/elfloader +test -d "../repos/libs/libelf" || git clone https://github.com/unikraft/lib-libelf ../repos/libs/libelf +test -d "../repos/libs/lwip" || git clone https://github.com/unikraft/lib-lwip ../repos/libs/lwip + +make distclean +UK_DEFCONFIG=$(pwd)/defconfig.fc.x86_64 make defconfig +touch Makefile.uk +make prepare +if test -z "$CC"; then + make -j $(nproc) +else + make CC="$CC" -j $(nproc) +fi diff --git a/elfloader-net/build.qemu.x86_64 b/elfloader-net/build.qemu.x86_64 new file mode 100755 index 0000000..92b2410 --- /dev/null +++ b/elfloader-net/build.qemu.x86_64 @@ -0,0 +1,16 @@ +#!/bin/sh + +test -d "../repos/unikraft" || git clone https://github.com/unikraft/unikraft ../repos/unikraft +test -d "../repos/apps/elfloader" || git clone https://github.com/unikraft/app-elfloader ../repos/apps/elfloader +test -d "../repos/libs/libelf" || git clone https://github.com/unikraft/lib-libelf ../repos/libs/libelf +test -d "../repos/libs/lwip" || git clone https://github.com/unikraft/lib-lwip ../repos/libs/lwip + +make distclean +UK_DEFCONFIG=$(pwd)/defconfig.qemu.x86_64 make defconfig +touch Makefile.uk +make prepare +if test -z "$CC"; then + make -j $(nproc) +else + make CC="$CC" -j $(nproc) +fi diff --git a/elfloader-net/defconfig.fc.x86_64 b/elfloader-net/defconfig.fc.x86_64 new file mode 100644 index 0000000..0a40bc4 --- /dev/null +++ b/elfloader-net/defconfig.fc.x86_64 @@ -0,0 +1,29 @@ +CONFIG_PLAT_KVM=y +CONFIG_KVM_VMM_FIRECRACKER=y +CONFIG_ARCH_X86_64=y +CONFIG_APPELFLOADER_DEPENDENCIES=y +CONFIG_APPELFLOADER_ARCH_PRCTL=y +CONFIG_APPELFLOADER_BRK=y +CONFIG_APPELFLOADER_CUSTOMAPPNAME=y +CONFIG_APPELFLOADER_STACK_NBPAGES=128 +CONFIG_APPELFLOADER_VFSEXEC_EXECBIT=n +CONFIG_APPELFLOADER_VFSEXEC=y +CONFIG_APPELFLOADER_HFS=y +CONFIG_APPELFLOADER_HFS_ETCRESOLVCONF=y +CONFIG_APPELFLOADER_HFS_ETCHOSTS=y +CONFIG_APPELFLOADER_HFS_ETCHOSTNAME=y +CONFIG_APPELFLOADER_HFS_REPLACEEXIST=y +CONFIG_LIBVFSCORE=y +CONFIG_LIBVFSCORE_AUTOMOUNT_UP=y +CONFIG_LIBRAMFS=y +CONFIG_LIBUKCPIO=y +CONFIG_LIBDEVFS=y +CONFIG_LIBDEVFS_AUTOMOUNT=y +# Networking support +CONFIG_LIBLWIP=y +CONFIG_LIBUKNETDEV_EINFO_LIBPARAM=y +# Uncomment for debugging. +#CONFIG_LIBUKDEBUG_PRINTD=y +#CONFIG_LIBUKDEBUG_PRINTK_INFO=y +#CONFIG_LIBSYSCALL_SHIM_STRACE=y +#CONFIG_LIBSYSCALL_SHIM_DEBUG=y diff --git a/elfloader-net/defconfig.qemu.x86_64 b/elfloader-net/defconfig.qemu.x86_64 new file mode 100644 index 0000000..41d29e0 --- /dev/null +++ b/elfloader-net/defconfig.qemu.x86_64 @@ -0,0 +1,29 @@ +CONFIG_PLAT_KVM=y +CONFIG_KVM_VMM_QEMU=y +CONFIG_ARCH_X86_64=y +CONFIG_APPELFLOADER_DEPENDENCIES=y +CONFIG_APPELFLOADER_ARCH_PRCTL=y +CONFIG_APPELFLOADER_BRK=y +CONFIG_APPELFLOADER_CUSTOMAPPNAME=y +CONFIG_APPELFLOADER_STACK_NBPAGES=128 +CONFIG_APPELFLOADER_VFSEXEC_EXECBIT=n +CONFIG_APPELFLOADER_VFSEXEC=y +CONFIG_APPELFLOADER_HFS=y +CONFIG_APPELFLOADER_HFS_ETCRESOLVCONF=y +CONFIG_APPELFLOADER_HFS_ETCHOSTS=y +CONFIG_APPELFLOADER_HFS_ETCHOSTNAME=y +CONFIG_APPELFLOADER_HFS_REPLACEEXIST=y +CONFIG_LIBVFSCORE=y +CONFIG_LIBVFSCORE_AUTOMOUNT_UP=y +CONFIG_LIBRAMFS=y +CONFIG_LIBUKCPIO=y +CONFIG_LIBDEVFS=y +CONFIG_LIBDEVFS_AUTOMOUNT=y +# Networking support +CONFIG_LIBLWIP=y +CONFIG_LIBUKNETDEV_EINFO_LIBPARAM=y +# Uncomment for debugging. +#CONFIG_LIBUKDEBUG_PRINTD=y +#CONFIG_LIBUKDEBUG_PRINTK_INFO=y +#CONFIG_LIBSYSCALL_SHIM_STRACE=y +#CONFIG_LIBSYSCALL_SHIM_DEBUG=y diff --git a/elfloader-net/run.fc.x86_64 b/elfloader-net/run.fc.x86_64 new file mode 100755 index 0000000..78eacb2 --- /dev/null +++ b/elfloader-net/run.fc.x86_64 @@ -0,0 +1,34 @@ +#!/bin/sh + +if test ! -f "out/elfloader_fc-x86_64"; then + echo "No kernel file out/elfloader_fc-x86_64." 1>&2 + echo "Did you run ./build.fc.x86_64 ?" 1>&2 + exit 1 +fi + +{ +# Remove previously created network interfaces. +sudo ip link set dev virbr0 down +sudo ip link del dev virbr0 +sudo ip link set dev tap0 down +sudo ip link del dev tap0 +} > /dev/null 2>&1 + +# Create tap interface for Firecracker networking. +sudo ip tuntap add dev tap0 mode tap +sudo ip address add 172.44.0.1/24 dev tap0 +sudo ip link set dev tap0 up + +# Build ELFs. +make -C rootfs/ + +# Pack filesystem as an initial ramdisk CPIO file. +rm -f initrd.cpio +../repos/unikraft/support/scripts/mkcpio initrd.cpio ./rootfs/ + +# Remove previously created files. +rm -f firecracker.socket + +firecracker-x86_64 \ + --api-sock firecracker.socket \ + --config-file fc.x86_64.json diff --git a/elfloader-net/run.qemu.x86_64 b/elfloader-net/run.qemu.x86_64 new file mode 100755 index 0000000..4b19f92 --- /dev/null +++ b/elfloader-net/run.qemu.x86_64 @@ -0,0 +1,36 @@ +#!/bin/sh + +if test ! -f "out/elfloader_qemu-x86_64"; then + echo "No kernel file out/elfloader_qemu-x86_64." 1>&2 + echo "Did you run ./build.qemu.x86_64 ?" 1>&2 + exit 1 +fi + +{ +# Remove previously created network interface. +sudo ip link set dev virbr0 down +sudo ip link del dev virbr0 +sudo ip link set dev tap0 down +sudo ip link del dev tap0 +} > /dev/null 2>&1 + +# Create bridge interface for QEMU networking. +sudo ip link add dev virbr0 type bridge +sudo ip address add 172.44.0.1/24 dev virbr0 +sudo ip link set dev virbr0 up + +# Build ELFs. +make -C rootfs/ + +# Pack filesystem as an initial ramdisk CPIO file. +rm -f initrd.cpio +../repos/unikraft/support/scripts/mkcpio initrd.cpio ./rootfs/ + +sudo qemu-system-x86_64 \ + -nographic \ + -m 64 \ + -cpu max \ + -netdev bridge,id=en0,br=virbr0 -device virtio-net-pci,netdev=en0 \ + -append "elfloader_qemu-x86_64 netdev.ip=172.44.0.2/24:172.44.0.1::: vfs.fstab=[ \"initrd0:/:extract::ramfs=1:\" ] -- /c-server" \ + -kernel out/elfloader_qemu-x86_64 \ + -initrd ./initrd.cpio