aboutsummaryrefslogtreecommitdiffhomepage
path: root/content/2021-12-02-toying-with-virtio/Makefile
blob: d4286af22b72cdf3ef0d2383bbcb0ac77018ba32 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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