Skip to content

Commit da46844

Browse files
committed
qemu/9pfs : Add 9pfs support for elfloader-basic
Signed-off-by: Neagu Dragos-Ionut <dragosneagu28@gmail.com>
1 parent 42d988e commit da46844

File tree

6 files changed

+166
-0
lines changed

6 files changed

+166
-0
lines changed

elfloader-basic/README.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ For Firecracker, the `fc.x86_64.json` file needs to be updated similarly.
243243
For other ELFs, you need to follow the steps:
244244

245245
1. Add / Build ELF in the `rootfs/` directory.
246+
246247
1. Update the start command as above with the command to run the ELF.
247248
The command can also have arguments, similar to any other Linux command.
248249

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

253254
### Enable Debug Messages
254255

256+
255257
You can customize the ELF Loader build debug messages.
258+
256259
For that, use the ["Configure" step](#configure) enable the [`ukdebug` library](https://github.com/unikraft/unikraft/tree/staging/lib/ukdebug) and its other options.
260+
257261
Then, build and run again.
262+
263+
### Use a Different Filesystem Type for QEMU
264+
265+
You can use [`9pfs`](https://github.com/unikraft/unikraft/tree/staging/lib/9pfs) as an alternate filesystem to initrd.
266+
267+
Note that 9pfs does not work with Firecracker.
268+
269+
And it requires re-building Xen to add 9pfs support.
270+
271+
Below find instructions on running Nginx on QEMU with 9pfs support.
272+
273+
You need to use these contents for the [`Config.uk`](Config.uk) configuration file:
274+
275+
```text
276+
# Configure ELF loader application, with networking support.
277+
278+
config APPELFLOADERNET
279+
bool "Configure ELF loader application (for binary compatibility) with networking support"
280+
default y
281+
282+
# Select app-elfloader component.
283+
select APPELFLOADER_DEPENDENCIES
284+
285+
# Configurations options for app-elfloader
286+
# (they can't be part of the template atm)
287+
select APPELFLOADER_ARCH_PRCTL
288+
select APPELFLOADER_BRK
289+
select APPELFLOADER_CUSTOMAPPNAME
290+
select APPELFLOADER_STACK_NBPAGES
291+
select APPELFLOADER_VFSEXEC_EXECBIT
292+
select APPELFLOADER_VFSEXEC
293+
select APPELFLOADER_HFS
294+
select APPELFLOADER_HFS_ETCRESOLVCONF
295+
select APPELFLOADER_HFS_ETCHOSTS
296+
select APPELFLOADER_HFS_ETCHOSTNAME
297+
select APPELFLOADER_HFS_REPLACEEXIST
298+
299+
# Select filesystem implementation: cpio, ramfs, devfs.
300+
select LIBVFSCORE
301+
select LIBVFSCORE_AUTOMOUNT_UP
302+
select LIBUK9P
303+
select LIB9PFS
304+
select LIBDEVFS
305+
select LIBDEVFS_AUTOMOUNT
306+
```
307+
308+
This means you replace these two lines in [`Config.uk`](Config.uk):
309+
310+
```text
311+
select LIBRAMFS
312+
select LIBUKCPIO
313+
```
314+
315+
with these lines:
316+
317+
```text
318+
select LIBUK9P
319+
select LIB9PFS
320+
```
321+
322+
Now go through the [configure](#configure) step.
323+
324+
From the `Library Configuration` tab, select `uk9p` and `Process-related functions` ---> `Multiprocess support`.
325+
326+
From the `Application Options` tab, select `Multiprocess application`
327+
328+
Then continue with the [build](#build) step.
329+
330+
Finally, after configuring networking, use the commands below to run elfloader-basic on QEMU/x86_64 with 9pfs support:
331+
332+
```console
333+
# Create a copy of the filesystem to be mounted as 9pfs.
334+
rm -fr 9pfs-rootfs
335+
cp -r rootfs 9pfs-rootfs
336+
sudo qemu-system-x86_64 \
337+
-nographic \
338+
-m 512 \
339+
-cpu max \
340+
-append "elfloader_qemu-x86_64 vfs.fstab=[ \"fs0:/:9pfs:::\" ] -- /hello-c" \
341+
-kernel workdir/build/elfloader_qemu-x86_64 \
342+
-fsdev local,id=myid,path=$(pwd)/9pfs-rootfs/,security_model=none \
343+
-device virtio-9p-pci,fsdev=myid,mount_tag=fs0
344+
```
345+
346+
You would use a similar command for QEMU/ARM64.

elfloader-basic/scripts/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,15 @@ CC=/usr/bin/clang ./scripts/build/fc.x86_64
3434
./scripts/run/qemu.x86_64
3535
./scripts/run/fc.x86_64
3636
```
37+
38+
## Build and Run for <plat> / <arch> using a different file system
39+
40+
```console
41+
./scripts/run/<plat>.<arch>.<file_system>
42+
```
43+
44+
e.g.
45+
46+
```console
47+
./scripts/run/qemu.x86_64.9pfs
48+
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
3+
make distclean
4+
UK_DEFCONFIG=$(pwd)/scripts/defconfig/qemu.x86_64.9pfs make defconfig
5+
touch Makefile.uk
6+
make prepare
7+
if test -z "$CC"; then
8+
make -j $(nproc)
9+
else
10+
make CC="$CC" -j $(nproc)
11+
fi
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
CONFIG_PLAT_KVM=y
2+
CONFIG_KVM_VMM_QEMU=y
3+
CONFIG_ARCH_X86_64=y
4+
CONFIG_APPELFLOADER_DEPENDENCIES=y
5+
CONFIG_APPELFLOADER_ARCH_PRCTL=y
6+
CONFIG_APPELFLOADER_BRK=y
7+
CONFIG_APPELFLOADER_MULTIPROCESS=y
8+
CONFIG_APPELFLOADER_CUSTOMAPPNAME=y
9+
CONFIG_APPELFLOADER_STACK_NBPAGES=128
10+
CONFIG_APPELFLOADER_VFSEXEC_EXECBIT=n
11+
CONFIG_APPELFLOADER_VFSEXEC=y
12+
CONFIG_APPELFLOADER_HFS=y
13+
CONFIG_APPELFLOADER_HFS_ETCRESOLVCONF=y
14+
CONFIG_APPELFLOADER_HFS_ETCHOSTS=y
15+
CONFIG_APPELFLOADER_HFS_ETCHOSTNAME=y
16+
CONFIG_APPELFLOADER_HFS_REPLACEEXIST=y
17+
CONFIG_LIBPOSIX_PROCESS_MULTIPROCESS=y
18+
CONFIG_LIBVFSCORE=y
19+
CONFIG_LIBVFSCORE_AUTOMOUNT_UP=y
20+
CONFIG_LIBUK9P=y
21+
CONFIG_LIB9PFS=y
22+
CONFIG_LIBDEVFS=y
23+
CONFIG_LIBDEVFS_AUTOMOUNT=y
24+
# Uncomment for debugging.
25+
#CONFIG_LIBUKDEBUG_PRINTD=y
26+
#CONFIG_LIBUKDEBUG_PRINTK_INFO=y
27+
#CONFIG_LIBSYSCALL_SHIM_STRACE=y
28+
#CONFIG_LIBSYSCALL_SHIM_DEBUG=y
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/sh
2+
3+
if test ! -f "workdir/build/elfloader_qemu-x86_64"; then
4+
echo "No kernel file workdir/build/elfloader_qemu-x86_64." 1>&2
5+
echo "Did you run ./build.qemu.x86_64 ?" 1>&2
6+
exit 1
7+
fi
8+
9+
# Build ELFs.
10+
make -C rootfs/
11+
12+
# Pack filesystem as 9pfs
13+
14+
rm -fr 9pfs-rootfscd
15+
cp -r rootfs 9pfs-rootfs
16+
17+
sudo qemu-system-x86_64 \
18+
-nographic \
19+
-m 512 \
20+
-cpu max \
21+
-append "elfloader_qemu-x86_64 vfs.fstab=[ \"fs0:/:9pfs:::\" ] -- /hello-c" \
22+
-kernel workdir/build/elfloader_qemu-x86_64 \
23+
-fsdev local,id=myid,path=$(pwd)/9pfs-rootfs/,security_model=none \
24+
-device virtio-9p-pci,fsdev=myid,mount_tag=fs0
25+
.

elfloader-basic/scripts/test/all.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ test_build_run()
2929
test -d ./scripts/test/log || mkdir ./scripts/test/log
3030
test_build_run qemu.x86_64
3131
test_build_run fc.x86_64
32+
test_build_run qemu.x86_64.9pfs

0 commit comments

Comments
 (0)