[elbe-devel] [PATCH 1/3] init Makefile.mako: Add COW logic for initvm

Torben Hohn torben.hohn at linutronix.de
Mon Jun 15 11:11:49 CEST 2020


On Mon, Jun 08, 2020 at 11:18:29PM -0400, Olivier Dion wrote:
> Rewrote the rules and dependencies and added support for COW images.
> Also moved the generation of the initvm-tree into Python.
> 
> The 'all' rule depends on the initvm image 'initvm.img'.  This image
> depends on the base image 'initvm-base.img' which in turn depends on
> 'initrd-preseeded.gz'.
> 
> The latter is the merge of the base initrd 'initrd.gz' and the
> 'initrd-tree' generated in Python.
> 
> Signed-off-by: Olivier Dion <dion at linutronix.de>
> ---
>  elbepack/init/Makefile.mako | 89 ++++++++++++++++++-------------------
>  1 file changed, 44 insertions(+), 45 deletions(-)
> 
> diff --git a/elbepack/init/Makefile.mako b/elbepack/init/Makefile.mako
> index 87ec10ad..ee41fcf0 100644
> --- a/elbepack/init/Makefile.mako
> +++ b/elbepack/init/Makefile.mako
> @@ -49,55 +49,42 @@ interpreter_v_minor = int(prj.text('interpreterversion',
>                                     key='interpreterversion').split('.')[1])
>  fwd = ""
>  if prj.has("portforwarding"):
> -	for f in prj.node("portforwarding"):
> -		fwd += ",hostfwd=%s::%s-:%s" % (f.text("proto"),
> -																		f.text("host"),
> -																		f.text("buildenv"))
> +    for f in prj.node("portforwarding"):
> +        fwd += ",hostfwd=%s::%s-:%s" % (f.text("proto"),
> +                                        f.text("host"),
> +                                        f.text("buildenv"))
>  %>
>  
> -all: .stamps/stamp-install-initial-image
> -
> -.elbe-gen/initrd-preseeded.gz: .elbe-in/*
> -	rm -rf tmp-tree
> -	mkdir tmp-tree
> -	cp .elbe-in/*.cfg tmp-tree/
> -	-cp .elbe-in/apt.conf tmp-tree/
> -	mkdir -p tmp-tree/etc/apt
> -	-cp .elbe-in/apt.conf tmp-tree/etc/apt
> -	mkdir -p tmp-tree/usr/lib/post-base-installer.d
> -	cp .elbe-in/init-elbe.sh tmp-tree/
> -	cp .elbe-in/source.xml tmp-tree/
> -	cp .elbe-in/initrd-cdrom.gz tmp-tree/
> -	cp .elbe-in/vmlinuz tmp-tree/
> -% if opt.devel:
> -	cp .elbe-in/elbe-devel.tar.bz2 tmp-tree/
> -% endif
> -	mkdir -p tmp-tree/usr/share/keyrings
> -	-cp .elbe-in/*.gpg tmp-tree/usr/share/keyrings
> -	mkdir -p tmp-tree/usr/lib/base-installer.d
> -	echo 'mkdir -p /target/etc/apt/trusted.gpg.d/; cp /usr/share/keyrings/elbe-keyring.gpg /target/etc/apt/trusted.gpg.d/' > tmp-tree/usr/lib/base-installer.d/10copyelbekeyring
> -	chmod 755 tmp-tree/usr/lib/base-installer.d/*
> -	mkdir -p .elbe-gen
> -	gzip -cd .elbe-in/initrd.gz >.elbe-gen/initrd-preseeded
> -	cd tmp-tree && find . | cpio -H newc -o --append -F ../.elbe-gen/initrd-preseeded
> -	gzip -9f .elbe-gen/initrd-preseeded
> -	rm -rf tmp-tree
>  
> -.stamps/stamp-create-buildenv-img buildenv.img: .elbe-gen/initrd-preseeded.gz
> -	qemu-img create -f ${img} buildenv.img ${imgsize}
> -	mkdir -p .stamps
> -	touch .stamps/stamp-create-buildenv-img
> +GEN=.elbe-gen
> +IN=.elbe-in
> +
> +INITRD=$(GEN)/initrd-preseeded.gz
> +VMLINUZ=$(IN)/vmlinuz
> +
> +INITRD_FILES=$(shell find $(IN)/initrd-tree -type f)
> +
> +BASE=initvm-base.img
> +INITVM=initvm.img
> +
> +CLEAN=$(BASE) $(INITVM) $(GEN)
>  
> -.stamps/stamp-install-initial-image: .stamps/stamp-create-buildenv-img
> +all: $(INITVM)
> +
> +$(INITVM): $(BASE)
> +	qemu-img create -f ${img} -F ${img} -b $< $@
> +
> +$(BASE): $(INITRD)
> +	qemu-img create -f ${img} $@ ${imgsize}
>  	@ echo $(INTERPRETER)
>  	@ $(INTERPRETER) -M $(MACHINE) \
>  		-device virtio-rng-pci \
> -		-drive file=buildenv.img,if=$(HD_TYPE),bus=1,unit=0 \
> +		-drive file=$@,if=$(HD_TYPE),bus=1,unit=0 \
>  % if prj.has("mirror/cdrom"):
>  		-drive file=${prj.text("mirror/cdrom")},if=$(CDROM_TYPE),media=cdrom,bus=1,unit=0 \
>  % endif
> -		-kernel .elbe-in/vmlinuz \
> -		-initrd .elbe-gen/initrd-preseeded.gz \
> +		-kernel $(VMLINUZ) \
> +		-initrd $(INITRD)  \
>  		-append 'root=/dev/$(HD_NAME) debconf_priority=critical console=$(CONSOLE) DEBIAN_FRONTEND=text' \
>  		-no-reboot \
>  		-nographic \
> @@ -106,6 +93,8 @@ all: .stamps/stamp-install-initial-image
>  		-m $(MEMSIZE) \
>  		-smp $(SMP) \
>  		-usb \
> +		-enable-kvm \
> +		-cpu host \

you enable nesting in an case ?

>  		|| ( echo; \
>  		     echo "------------------------------------------------------------------"; \
>  		     echo "kvm failed to start"; \
> @@ -117,14 +106,20 @@ all: .stamps/stamp-install-initial-image
>  		     false \
>  		)
>  
> -	mkdir -p .stamps
> -	touch .stamps/stamp-install-initial-image
> +$(INITRD): $(INITRD_FILES)
> +	mkdir -p $(IN)/initrd-tree/usr/lib/base-installer.d
> +	echo 'mkdir -p /target/etc/apt/trusted.gpg.d/; cp /usr/share/keyrings/elbe-keyring.gpg /target/etc/apt/trusted.gpg.d/' > $(IN)/initrd-tree/usr/lib/base-installer.d/10copyelbekeyring
> +	chmod 755 $(IN)/initrd-tree/usr/lib/base-installer.d/*
> +	mkdir -p .elbe-gen
> +	gzip -cd $(IN)/initrd.gz > $(GEN)/initrd-preseeded
> +	cd $(IN)/initrd-tree && find . | cpio -H newc -o --append -F ../../$(GEN)/initrd-preseeded
> +	gzip -9f $(GEN)/initrd-preseeded
>  
>  run:
>  	$(INTERPRETER) -M $(MACHINE) \
>  		-device virtio-rng-pci \
>  		-device virtio-net-pci,netdev=user.0 \
> -		-drive file=buildenv.img,if=$(HD_TYPE),bus=1,unit=0 \
> +		-drive file=$(INITVM),if=$(HD_TYPE),bus=1,unit=0 \
>  		-no-reboot \
>  % if ((interpreter_v_major == 2) and (interpreter_v_minor >= 8)) or (interpreter_v_major > 2):
>  		-netdev user,ipv4,id=user.0${fwd} \
> @@ -132,6 +127,7 @@ run:
>  		-netdev user,id=user.0${fwd} \
>  % endif
>  % if opt.nesting:
> +		-enable-kvm \

why do you enable kvm only when nesting is set ?
IIRC the $(INTERPRETER) should include "-enable-kvm" when
this is required.

see elbepack/kvm.py 

it seems like find_kvm_exe() does not work properly where you are.


>  		-cpu host \
>  % endif
>  		-m $(MEMSIZE) \
> @@ -142,7 +138,7 @@ run-con:
>  	$(INTERPRETER) -M $(MACHINE) \
>  		-device virtio-rng-pci \
>  		-device virtio-net-pci,netdev=user.0 \
> -		-drive file=buildenv.img,if=$(HD_TYPE),bus=1,unit=0 \
> +		-drive file=$(INITVM),if=$(HD_TYPE),bus=1,unit=0 \
>  		-no-reboot \
>  % if ((interpreter_v_major == 2) and (interpreter_v_minor >= 8)) or (interpreter_v_major > 2):
>  		-netdev user,ipv4,id=user.0${fwd} \
> @@ -150,6 +146,7 @@ run-con:
>  		-netdev user,id=user.0${fwd} \
>  % endif
>  % if opt.nesting:
> +		-enable-kvm \
>  		-cpu host \
>  % endif
>  		-m $(MEMSIZE) \
> @@ -158,7 +155,9 @@ run-con:
>  		-smp $(SMP)
>  
>  clean:
> -	rm -fr .stamps/stamp* buildenv.img .elbe-vm .elbe-gen
> +	rm -fr $(CLEAN)
>  
>  distclean: clean
> -	echo clean
> +	@echo clean
> +
> +.PHONY: all clean distclean run run-con
> -- 
> 2.27.0
> 
> 
> _______________________________________________
> elbe-devel mailing list
> elbe-devel at linutronix.de
> https://lists.linutronix.de/mailman/listinfo/elbe-devel

-- 
Torben Hohn
Linutronix GmbH | Bahnhofstrasse 3 | D-88690 Uhldingen-Mühlhofen
Phone: +49 7556 25 999 18; Fax.: +49 7556 25 999 99

Hinweise zum Datenschutz finden Sie hier (Informations on data privacy 
can be found here): https://linutronix.de/kontakt/Datenschutz.php

Linutronix GmbH | Firmensitz (Registered Office): Uhldingen-Mühlhofen | 
Registergericht (Registration Court): Amtsgericht Freiburg i.Br., HRB700 
806 | Geschäftsführer (Managing Directors): Heinz Egger, Thomas Gleixner



More information about the elbe-devel mailing list