aboutsummaryrefslogtreecommitdiffhomepage
path: root/content/2021-12-02-toying-with-virtio/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'content/2021-12-02-toying-with-virtio/Makefile')
-rw-r--r--content/2021-12-02-toying-with-virtio/Makefile57
1 files changed, 57 insertions, 0 deletions
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