From 6059b8d8c6085426fce1a6e638af069750c9dd54 Mon Sep 17 00:00:00 2001 From: Johannes Stoelp Date: Sat, 4 Dec 2021 18:30:54 +0100 Subject: added virtio post --- content/2021-12-02-toying-with-virtio/Makefile | 57 ++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 content/2021-12-02-toying-with-virtio/Makefile (limited to 'content/2021-12-02-toying-with-virtio/Makefile') diff --git a/content/2021-12-02-toying-with-virtio/Makefile b/content/2021-12-02-toying-with-virtio/Makefile new file mode 100644 index 0000000..4009862 --- /dev/null +++ b/content/2021-12-02-toying-with-virtio/Makefile @@ -0,0 +1,57 @@ +VER := 5.15.6 + +all: kernel init + +help: + @echo "Build targets:" + @echo "* init - Build busybox based initramfs." + @echo "* kernel - Build minimal linux kernel." + @echo " clean - Cleanup downloads & builds." + @echo "" + @echo "Run targets:" + @echo " run - Boot into the initramfs (qemu)." + @echo " vcon - Attach to guest virtio console." + @echo " This needs an already running guest VM and must be" + @echo " executed in the same domain as the 'run' target" + @echo " (docker or host)." + @echo " Login as 'root' user, no passwd required." + @echo "" + @echo "Docker targets:" + @echo " docker - Build and start the docker container." + @echo " attach - Start an additional bash in the container." + @echo " This needs an already running container." + +kernel: + ./build_kernel.sh + +init: + ./build_initramfs.sh + +run: + qemu-system-x86_64 \ + -nographic \ + -cpu host \ + -enable-kvm \ + -kernel ./linux-$(VER)/arch/x86/boot/bzImage \ + -append "earlyprintk=ttyS0 console=ttyS0 root=/dev/ram0 ro" \ + -initrd ./initramfs.cpio.gz \ + -device virtio-serial-pci \ + -device virtconsole,chardev=vcon,name=console.0 \ + -chardev socket,id=vcon,ipv4=on,host=localhost,port=2222,server,telnet=on,wait=off \ + -drive format=raw,if=virtio,file=rootfs.ext2 \ + -nic user,model=virtio-net-pci + +vcon: + telnet -4 localhost 2222 + +clean: + $(RM) initramfs.cpio.gz + $(RM) -r busybox-* + $(RM) -r linux-$(VER)* + +docker: + DOCKER_BUILDKIT=1 docker build --build-arg UID=$(shell id -u) -t virtio-dev . + docker run --name virtio -it --rm -v $(PWD):/develop --device /dev/kvm virtio-dev + +attach: + docker exec -it virtio bash -- cgit v1.2.3