aboutsummaryrefslogblamecommitdiffhomepage
path: root/content/2021-12-02-toying-with-virtio/Makefile
blob: d4286af22b72cdf3ef0d2383bbcb0ac77018ba32 (plain) (tree)
1
2
3
4
5
6
7
8
9







                                                             
                                                                                          




















                                                                                 


                       










                                                                                              
                                                     








                                        
                      






                                                                                         
VER := 5.15.6

all: kernel init

help:
	@echo "Build targets:"
	@echo "* init       - Build busybox based initramfs."
	@echo "* kernel     - Build minimal linux kernel."
	@echo "  ext2       - Build minimal ext2 fs as virtio blkdev backend (uses sudo)."
	@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

ext2:
	./build_ext2.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=blk.ext2 \
	  -nic user,model=virtio-net-pci

vcon:
	telnet -4 localhost 2222

clean:
	$(RM) initramfs.cpio.gz
	$(RM) -r busybox-*
	$(RM) -r linux-$(VER)*
	$(RM) blk.ext2

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