diff --git a/elfloader-basic/README.md b/elfloader-basic/README.md index d82f6fed..3e577b88 100644 --- a/elfloader-basic/README.md +++ b/elfloader-basic/README.md @@ -255,3 +255,83 @@ ELFs using require additional configuration of the ELF Loader. You can customize the ELF Loader build debug messages. For that, use the ["Configure" step](#configure) enable the [`ukdebug` library](https://github.com/unikraft/unikraft/tree/staging/lib/ukdebug) and its other options. Then, build and run again. + +### Use a Different Filesystem Type for QEMU + +You can use [`9pfs`](https://github.com/unikraft/unikraft/tree/staging/lib/9pfs) as an alternate filesystem to initrd. +Note that 9pfs does not work with Firecracker. +And it requires re-building Xen to add 9pfs support. +Below find instructions on running Nginx on QEMU with 9pfs support. + +You need to use these contents for the [`Config.uk`](Config.uk) configuration file: + +```text +# Configure ELF loader application, with networking support. + +config APPELFLOADERNET +bool "Configure ELF loader application (for binary compatibility) with networking support" +default y + + # Select app-elfloader component. + select APPELFLOADER_DEPENDENCIES + + # Configurations options for app-elfloader + # (they can't be part of the template atm) + select APPELFLOADER_ARCH_PRCTL + select APPELFLOADER_BRK + select APPELFLOADER_CUSTOMAPPNAME + select APPELFLOADER_STACK_NBPAGES + select APPELFLOADER_VFSEXEC_EXECBIT + select APPELFLOADER_VFSEXEC + select APPELFLOADER_HFS + select APPELFLOADER_HFS_ETCRESOLVCONF + select APPELFLOADER_HFS_ETCHOSTS + select APPELFLOADER_HFS_ETCHOSTNAME + select APPELFLOADER_HFS_REPLACEEXIST + + # Select filesystem implementation: cpio, ramfs, devfs. + select LIBVFSCORE + select LIBVFSCORE_AUTOMOUNT_UP + select LIBUK9P + select LIB9PFS + select LIBDEVFS + select LIBDEVFS_AUTOMOUNT +``` + +This means you replace these two lines in [`Config.uk`](Config.uk): + +```text + select LIBRAMFS + select LIBUKCPIO +``` + +with these lines: + +```text + select LIBUK9P + select LIB9PFS +``` + +Now go through the [configure](#configure) step. + +From the `Library Configuration` tab, select `uk9p` and `Process-related functions` ---> `Multiprocess support`. + +From the `Application Options` tab, select `Multiprocess application` + +Then continue with the [build](#build) step. + +Finally, after configuring networking, use the commands below to run elfloader-basic on QEMU/x86_64 with 9pfs support: + +```console +# Create a copy of the filesystem to be mounted as 9pfs. +rm -fr 9pfs-rootfs +cp -r rootfs 9pfs-rootfs +sudo qemu-system-x86_64 \ + -nographic \ + -m 512 \ + -cpu max \ + -append "elfloader_qemu-x86_64 vfs.fstab=[ \"fs0:/:9pfs:::\" ] -- /hello-c" \ + -kernel workdir/build/elfloader_qemu-x86_64 \ + -fsdev local,id=myid,path=$(pwd)/9pfs-rootfs/,security_model=none \ + -device virtio-9p-pci,fsdev=myid,mount_tag=fs0 +``` diff --git a/elfloader-basic/scripts/README.md b/elfloader-basic/scripts/README.md index 139394d9..0e8850f4 100644 --- a/elfloader-basic/scripts/README.md +++ b/elfloader-basic/scripts/README.md @@ -34,3 +34,15 @@ CC=/usr/bin/clang ./scripts/build/fc.x86_64 ./scripts/run/qemu.x86_64 ./scripts/run/fc.x86_64 ``` + +## Build and Run for / using a different file system + +```console +./scripts/run/.. +``` + +e.g. + +```console +./scripts/run/qemu.x86_64.9pfs +``` diff --git a/elfloader-basic/scripts/build/qemu.x86_64.9pfs b/elfloader-basic/scripts/build/qemu.x86_64.9pfs new file mode 100755 index 00000000..fb974580 --- /dev/null +++ b/elfloader-basic/scripts/build/qemu.x86_64.9pfs @@ -0,0 +1,11 @@ +#!/bin/sh + +make distclean +UK_DEFCONFIG=$(pwd)/scripts/defconfig/qemu.x86_64.9pfs 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-basic/scripts/defconfig/qemu.x86_64.9pfs b/elfloader-basic/scripts/defconfig/qemu.x86_64.9pfs new file mode 100644 index 00000000..a86f9056 --- /dev/null +++ b/elfloader-basic/scripts/defconfig/qemu.x86_64.9pfs @@ -0,0 +1,28 @@ +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_MULTIPROCESS=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_LIBPOSIX_PROCESS_MULTIPROCESS=y +CONFIG_LIBVFSCORE=y +CONFIG_LIBVFSCORE_AUTOMOUNT_UP=y +CONFIG_LIBUK9P=y +CONFIG_LIB9PFS=y +CONFIG_LIBDEVFS=y +CONFIG_LIBDEVFS_AUTOMOUNT=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-basic/scripts/run/qemu.x86_64.9pfs b/elfloader-basic/scripts/run/qemu.x86_64.9pfs new file mode 100755 index 00000000..d16f30a6 --- /dev/null +++ b/elfloader-basic/scripts/run/qemu.x86_64.9pfs @@ -0,0 +1,24 @@ +#!/bin/sh + +if test ! -f "workdir/build/elfloader_qemu-x86_64"; then + echo "No kernel file workdir/build/elfloader_qemu-x86_64." 1>&2 + echo "Did you run ./build.qemu.x86_64 ?" 1>&2 + exit 1 +fi + +# Build ELFs. +make -C rootfs/ + +# Pack filesystem as 9pfs + +rm -fr 9pfs-rootfscd +cp -r rootfs 9pfs-rootfs + +sudo qemu-system-x86_64 \ + -nographic \ + -m 512 \ + -cpu max \ + -append "elfloader_qemu-x86_64 vfs.fstab=[ \"fs0:/:9pfs:::\" ] -- /hello-c" \ + -kernel workdir/build/elfloader_qemu-x86_64 \ + -fsdev local,id=myid,path=$(pwd)/9pfs-rootfs/,security_model=none \ + -device virtio-9p-pci,fsdev=myid,mount_tag=fs0 diff --git a/redis/scripts/README.md b/redis/scripts/README.md index 9f3fb3e5..4dcd3482 100644 --- a/redis/scripts/README.md +++ b/redis/scripts/README.md @@ -54,3 +54,15 @@ e.g. ./scripts/run/fc.x86_64 ./scripts/run/xen.arm64 ``` + +## Build and Run for / using a different file system + +```console +./scripts/run/.. +``` + +e.g. + +```console +./scripts/run/qemu.x86_64.9pfs +``` diff --git a/redis/scripts/build/qemu.arm64.9pfs b/redis/scripts/build/qemu.arm64.9pfs new file mode 100755 index 00000000..b6017c53 --- /dev/null +++ b/redis/scripts/build/qemu.arm64.9pfs @@ -0,0 +1,11 @@ +#!/bin/sh + +make distclean +UK_DEFCONFIG=$(pwd)/scripts/defconfig/qemu.arm64.9pfs 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/redis/scripts/build/qemu.x86_64.9pfs b/redis/scripts/build/qemu.x86_64.9pfs new file mode 100755 index 00000000..fb974580 --- /dev/null +++ b/redis/scripts/build/qemu.x86_64.9pfs @@ -0,0 +1,11 @@ +#!/bin/sh + +make distclean +UK_DEFCONFIG=$(pwd)/scripts/defconfig/qemu.x86_64.9pfs 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/redis/scripts/defconfig/qemu.arm64.9pfs b/redis/scripts/defconfig/qemu.arm64.9pfs new file mode 100644 index 00000000..68ebc3a7 --- /dev/null +++ b/redis/scripts/defconfig/qemu.arm64.9pfs @@ -0,0 +1,14 @@ +CONFIG_PLAT_KVM=y +CONFIG_KVM_VMM_QEMU=y +CONFIG_ARCH_ARM_64=y +CONFIG_LIBVFSCORE=y +CONFIG_LIBVFSCORE_AUTOMOUNT_UP=y +CONFIG_LIBUK9P=y +CONFIG_LIB9PFS=y +CONFIG_LIBDEVFS=y +CONFIG_LIBDEVFS_AUTOMOUNT=y +CONFIG_LIBDEVFS_DEVSTDOUT=y +CONFIG_LIBUKNETDEV_EINFO_LIBPARAM=y +CONFIG_ARM64_ERRATUM_858921=n +CONFIG_ARM64_ERRATUM_835769=n +CONFIG_ARM64_ERRATUM_843419=n diff --git a/redis/scripts/defconfig/qemu.x86_64.9pfs b/redis/scripts/defconfig/qemu.x86_64.9pfs new file mode 100644 index 00000000..6bb1e10a --- /dev/null +++ b/redis/scripts/defconfig/qemu.x86_64.9pfs @@ -0,0 +1,11 @@ +CONFIG_PLAT_KVM=y +CONFIG_KVM_VMM_QEMU=y +CONFIG_ARCH_X86_64=y +CONFIG_LIBVFSCORE=y +CONFIG_LIBVFSCORE_AUTOMOUNT_UP=y +CONFIG_LIBuk9p=y +CONFIG_LIB9pfs=y +CONFIG_LIBDEVFS=y +CONFIG_LIBDEVFS_AUTOMOUNT=y +CONFIG_LIBDEVFS_DEVSTDOUT=y +CONFIG_LIBUKNETDEV_EINFO_LIBPARAM=y diff --git a/redis/scripts/run/qemu.arm64.9pfs b/redis/scripts/run/qemu.arm64.9pfs new file mode 100755 index 00000000..a85204f2 --- /dev/null +++ b/redis/scripts/run/qemu.arm64.9pfs @@ -0,0 +1,35 @@ +#!/bin/sh + +if test ! -f "workdir/build/redis_qemu-arm64"; then + echo "No kernel file workdir/build/redis_qemu-arm64." 1>&2 + echo "Did you run ./build.qemu.arm64 ?" 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 + +# Pack filesystem as an initial ramdisk CPIO file. +rm -fr 9pfs-rootfs +cp -r rootfs 9pfs-rootfs + +sudo qemu-system-aarch64 \ + -nographic \ + -machine virt \ + -m 256 \ + -cpu max \ + -netdev bridge,id=en0,br=virbr0 -device virtio-net-pci,netdev=en0 \ + -append "redis netdev.ip=172.44.0.2/24:172.44.0.1::: vfs.fstab=[ \"fs0:/:9pfs:::\" ] -- /redis.conf" \ + -kernel workdir/build/redis_qemu-arm64 \ + -fsdev local,id=myid,path=$(pwd)/9pfs-rootfs/,security_model=none \ + -device virtio-9p-pci,fsdev=myid,mount_tag=fs0 diff --git a/redis/scripts/run/qemu.x86_64.9pfs b/redis/scripts/run/qemu.x86_64.9pfs new file mode 100755 index 00000000..ba289f4c --- /dev/null +++ b/redis/scripts/run/qemu.x86_64.9pfs @@ -0,0 +1,34 @@ +#!/bin/sh + +if test ! -f "workdir/build/redis_qemu-x86_64"; then + echo "No kernel file workdir/build/redis_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 + +# Pack filesystem as an initial ramdisk CPIO file. +rm -fr 9pfs-rootfs +cp -r rootfs 9pfs-rootfs + +sudo qemu-system-x86_64 \ + -nographic \ + -m 256 \ + -cpu max \ + -netdev bridge,id=en0,br=virbr0 -device virtio-net-pci,netdev=en0 \ + -append "redis netdev.ip=172.44.0.2/24:172.44.0.1::: vfs.fstab=[ \"fs0:/:9pfs:::\" ] -- /redis.conf" \ + -kernel workdir/build/redis_qemu-x86_64 \ + -fsdev local,id=myid,path=$(pwd)/9pfs-rootfs/,security_model=none \ + -device virtio-9p-pci,fsdev=myid,mount_tag=fs0