Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions elfloader-basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ For Firecracker, the `fc.x86_64.json` file needs to be updated similarly.
For other ELFs, you need to follow the steps:

1. Add / Build ELF in the `rootfs/` directory.

1. Update the start command as above with the command to run the ELF.
The command can also have arguments, similar to any other Linux command.

Expand All @@ -252,6 +253,94 @@ ELFs using require additional configuration of the ELF Loader.

### Enable Debug Messages


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
```

You would use a similar command for QEMU/ARM64.
12 changes: 12 additions & 0 deletions elfloader-basic/scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <plat> / <arch> using a different file system

```console
./scripts/run/<plat>.<arch>.<file_system>
```

e.g.

```console
./scripts/run/qemu.x86_64.9pfs
```
11 changes: 11 additions & 0 deletions elfloader-basic/scripts/build/qemu.x86_64.9pfs
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions elfloader-basic/scripts/defconfig/qemu.x86_64.9pfs
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions elfloader-basic/scripts/run/qemu.x86_64.9pfs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/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
.
1 change: 1 addition & 0 deletions elfloader-basic/scripts/test/all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ test_build_run()
test -d ./scripts/test/log || mkdir ./scripts/test/log
test_build_run qemu.x86_64
test_build_run fc.x86_64
test_build_run qemu.x86_64.9pfs
5 changes: 2 additions & 3 deletions redis/Config.uk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Enable extendeded information for configuring network parameters.

config APPREDIS
bool "Configure Redis server application with initrd as rootfs"
bool "Configure Redis server application with 9pfs as rootfs"
default y

# Select application library (Redis). Use the server main function the
Expand All @@ -19,9 +19,8 @@ default y
# each select corresponding features. The other core components are
# selected as dependencies of Redis.
select LIBVFSCORE
select LIBVFSCORE_AUTOMOUNT_UP
select LIBRAMFS
select LIBUKCPIO
select LIBUKCPIO
select LIBDEVFS
select LIBDEVFS_AUTOMOUNT
select LIBDEVFS_DEVSTDOUT
Expand Down
12 changes: 12 additions & 0 deletions redis/scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,15 @@ e.g.
./scripts/run/fc.x86_64
./scripts/run/xen.arm64
```

## Build and Run for <plat> / <arch> using a different file system

```console
./scripts/run/<plat>.<arch>.<file_system>
```

e.g.

```console
./scripts/run/qemu.x86_64.9pfs
```
2 changes: 1 addition & 1 deletion redis/scripts/build/fc.x86_64
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

make distclean
UK_DEFCONFIG=$(pwd)/scripts/defconfig/fc.x86_64 make defconfig
UK_DEFCONFIG=$(pwd)/scripts/defconfig/fc.x86_64.cpio make defconfig
touch Makefile.uk
make prepare
if test -z "$CC"; then
Expand Down
11 changes: 11 additions & 0 deletions redis/scripts/build/qemu.arm64.9pfs
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion redis/scripts/build/qemu.x86_64
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

make distclean
UK_DEFCONFIG=$(pwd)/scripts/defconfig/qemu.x86_64 make defconfig
UK_DEFCONFIG=$(pwd)/scripts/defconfig/qemu.x86_64.cpio make defconfig
touch Makefile.uk
make prepare
if test -z "$CC"; then
Expand Down
11 changes: 11 additions & 0 deletions redis/scripts/build/qemu.x86_64.9pfs
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions redis/scripts/defconfig/qemu.arm64.9pfs
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions redis/scripts/defconfig/qemu.x86_64.9pfs
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions redis/scripts/run/qemu.arm64.9pfs
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions redis/scripts/run/qemu.x86_64.9pfs
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions redis/scripts/test/all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ test_build_run()
./setup.sh
test -d ./scripts/test/log || mkdir ./scripts/test/log
test_build_run qemu.x86_64
test_build_run qemu.x86_64.9pfs
test_build_run qemu.arm64
test_build_run qemu.arm64.9pfs
test_build_run fc.x86_64
test_build fc.arm64
test_build xen.x86_64
Expand Down