Subject: [alpine-devel] [PATCH v2] alpine-iso: add support to create Xen Dom0 LiveCD/USB

From: Roger Pau Monne <[email-masked]>
Date: Thu, 29 Dec 2011 20:18:18 +0100

A new profile has been added, called alpine-xen, that shoud be used
when trying to craft a Xen Dom0 LiveCD/USB.

Changes since v1:

 * Removed dummy net setup, since xencommons doesn't need net to
   start.

Please review and comment.
---
 Makefile            |   64 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 alpine-xen.conf.mk  |    4 +++
 alpine-xen.packages |   10 ++++++++
 3 files changed, 77 insertions(+), 1 deletions(-)
 create mode 100644 alpine-xen.conf.mk
 create mode 100644 alpine-xen.packages

diff --git a/Makefile b/Makefile
index 7fa36b2..65a7dd0 100755
--- a/Makefile
+++ b/Makefile
@@ -200,6 +200,44 @@ $(VSTEMPLATE):
 	@cd $(VSTEMPLATE_DIR) && $(TAR) -jcf $@ *
 
 #
+# apkovl rules
+#
+
+ifdef BUILD_APKOVL
+APKOVL_DEST	:= $(ISO_DIR)/$(BUILD_APKOVL).apkovl.tar.gz
+APKOVL_DIR	:= $(DESTDIR)/apkovl_$(BUILD_APKOVL)
+endif
+
+# Helper function to link a script to runlevel
+
+rc_add = \
+	@mkdir -p "$(APKOVL_DIR)"/etc/runlevels/"$(2)"; \
+	ln -sf /etc/init.d/"$(1)" "$(APKOVL_DIR)"/etc/runlevels/"$(2)"/"$(1)";
+
+$(ISO_DIR)/xen.apkovl.tar.gz:
+	@rm -rf "$(APKOVL_DIR)"
+	@mkdir -p "$(APKOVL_DIR)"
+	@mkdir -p "$(APKOVL_DIR)"/etc/apk
+	@echo "xen udev" >> "$(APKOVL_DIR)"/etc/apk/world
+	@echo "xen_netback" >> "$(APKOVL_DIR)"/etc/modules
+	@echo "xen_blkback" >> "$(APKOVL_DIR)"/etc/modules
+	$(call rc_add,devfs,sysinit)
+	$(call rc_add,dmesg,sysinit)
+	$(call rc_add,hwclock,boot)
+	$(call rc_add,modules,boot)
+	$(call rc_add,sysctl,boot)
+	$(call rc_add,hostname,boot)
+	$(call rc_add,bootmisc,boot)
+	$(call rc_add,syslog,boot)
+	$(call rc_add,mount-ro,shutdown)
+	$(call rc_add,killprocs,shutdown)
+	$(call rc_add,savecache,shutdown)
+	$(call rc_add,udev,sysinit)
+	$(call rc_add,udev-postmount,default)
+	$(call rc_add,xencommons,default)
+	@cd $(APKOVL_DIR) && $(TAR) -zcf $@ *
+	@echo "==> apkovl: built $@"
+#
 # ISO rules
 #
 
@@ -223,24 +261,42 @@ $(ISOLINUX_CFG):
 	@echo "$(SYSLINUX_SERIAL)" >$@
 	@echo "timeout 20" >>$@
 	@echo "prompt 1" >>$@
+ifeq ($(PROFILE), alpine-xen)
+	@echo "default xen-$(KERNEL_FLAVOR_DEFAULT)" >>$@
+	@for flavor in $(KERNEL_FLAVOR); do \
+		echo "label xen-$$flavor"; \
+		echo "	kernel /boot/mboot.c32"; \
+		echo "	append /boot/xen.gz --- /boot/$$flavor alpine_dev=cdrom:iso9660 modules=loop,squashfs,sd-mod,usb-storage,floppy,sr-mod modloop=/boot/$$flavor.modloop.squashfs $(BOOT_CONSOLE) --- /boot/$$flavor.gz"; \
+	done >>$@
+else
 	@echo "default $(KERNEL_FLAVOR_DEFAULT)" >>$@
 	@for flavor in $(KERNEL_FLAVOR); do \
 		echo "label $$flavor"; \
 		echo "	kernel /boot/$$flavor"; \
 		echo "	append initrd=/boot/$$flavor.gz alpine_dev=cdrom:iso9660 modules=loop,squashfs,sd-mod,usb-storage,floppy,sr-mod quiet $(BOOT_CONSOLE)"; \
 	done >>$@
+endif
 
 $(SYSLINUX_CFG): $(ALL_MODLOOP_DIRSTAMP)
 	@echo "==> iso: configure syslinux"
 	@echo "$(SYSLINUX_SERIAL)" >$@
 	@echo "timeout 20" >>$@
 	@echo "prompt 1" >>$@
+ifeq ($(PROFILE), alpine-xen)
+	@echo "default xen-$(KERNEL_FLAVOR_DEFAULT)" >>$@
+	@for flavor in $(KERNEL_FLAVOR); do \
+		echo "label xen-$$flavor"; \
+		echo "	kernel /boot/mboot.c32"; \
+		echo "	append /boot/xen.gz --- /boot/$$flavor alpine_dev=usbdisk:vfat modules=loop,squashfs,sd-mod,usb-storage modloop=/boot/$$flavor.modloop.squashfs $(BOOT_CONSOLE) --- /boot/$$flavor.gz"; \
+	done >>$@
+else
 	@echo "default $(KERNEL_FLAVOR_DEFAULT)" >>$@
 	@for flavor in $(KERNEL_FLAVOR); do \
 		echo "label $$flavor"; \
 		echo "	kernel /boot/$$flavor"; \
 		echo "	append initrd=/boot/$$flavor.gz alpine_dev=usbdisk:vfat modules=loop,squashfs,sd-mod,usb-storage quiet $(BOOT_CONSOLE)"; \
 	done >>$@
+endif
 
 clean-syslinux:
 	@rm -f $(SYSLINUX_CFG) $(ISOLINUX_CFG) $(ISOLINUX_BIN)
@@ -266,6 +322,12 @@ $(ISO_KERNEL_STAMP): $(MODLOOP_DIRSTAMP)
 	@mkdir -p $(dir $(ISO_KERNEL))
 	@apk fetch $(APK_OPTS) --stdout $(KERNEL_PKGNAME) \
 		| $(TAR) -C $(ISO_DIR) -xz boot
+ifeq ($(PROFILE), alpine-xen)
+	@apk fetch $(APK_OPTS) --stdout xen \
+		| $(TAR) -C $(ISO_DIR) -xz boot
+	@apk fetch $(APK_OPTS) --stdout syslinux \
+		| $(TAR) -xz usr/share/syslinux/mboot.c32 -O > $(ISO_DIR)/boot/mboot.c32
+endif
 	@rm -f $(ISO_KERNEL)
 	@ln -s vmlinuz-$(MODLOOP_KERNEL_RELEASE) $(ISO_KERNEL)
 	@rm -rf $(ISO_DIR)/.[A-Z]* $(ISO_DIR)/.[a-z]* $(ISO_DIR)/lib
@@ -281,7 +343,7 @@ $(APKOVL_STAMP):
 	fi
 	@touch $@
 
-$(ISOFS_DIRSTAMP): $(ALL_MODLOOP) $(ALL_INITFS) $(ISOLINUX_CFG) $(ISOLINUX_BIN) $(ALL_ISO_KERNEL) $(ISO_REPOS_DIRSTAMP) $(APKOVL_STAMP) $(SYSLINUX_CFG)
+$(ISOFS_DIRSTAMP): $(ALL_MODLOOP) $(ALL_INITFS) $(ISOLINUX_CFG) $(ISOLINUX_BIN) $(ALL_ISO_KERNEL) $(ISO_REPOS_DIRSTAMP) $(APKOVL_STAMP) $(SYSLINUX_CFG) $(APKOVL_DEST)
 	@echo "$(ALPINE_NAME)-$(ALPINE_RELEASE) $(BUILD_DATE)" \
 		> $(ISO_DIR)/.alpine-release
 	@touch $@
diff --git a/alpine-xen.conf.mk b/alpine-xen.conf.mk
new file mode 100644
index 0000000..016db33
--- /dev/null
+++ b/alpine-xen.conf.mk
@@ -0,0 +1,4 @@
+ALPINE_NAME     := alpine-xen
+MODLOOP_EXTRA   :=
+KERNEL_FLAVOR   := grsec
+BUILD_APKOVL    := xen
diff --git a/alpine-xen.packages b/alpine-xen.packages
new file mode 100644
index 0000000..b1cbd42
--- /dev/null
+++ b/alpine-xen.packages
@@ -0,0 +1,10 @@
+bkeymaps
+alpine-base
+alpine-mirrors
+wpa_supplicant
+wireless-tools
+openssl
+tzdata
+xen
+udev
+multipath-tools
-- 
1.7.7.1

---
Unsubscribe:  [email-masked]
Help:         [email-masked]
---

---

From: Natanael Copa <[email-masked]>
Date: Fri, 30 Dec 2011 11:10:37 +0100

On Thu, 29 Dec 2011 20:18:18 +0100

> Please review and comment.

Nice!

In general, the Makefile is getting bigger and messier. We need to do
something to split it up. We should try avoid having profile specifics
in main Makefile and try avoid if/else in Makefile. (that is meant for
myself as well)

> ---
>  Makefile            |   64
> ++++++++++++++++++++++++++++++++++++++++++++++++++-
> alpine-xen.conf.mk  |    4 +++ alpine-xen.packages |   10 ++++++++

Have been thinking of other apkovls too, for for example
alpine-desktop. I am not convinced that shipping an iso with apkovl is
the prober direction to go though. We have talked about implementing
"policy" packages in apk so you could have a "profile" package for
different setups. policy pakcages could include some configuration that
could be overridden by user.

Not sure what the status for that is currently.

> +	ln -sf /etc/init.d/"$(1)"

I think the helper funciton was pretty elegant :)

> "$(APKOVL_DIR)"/etc/runlevels/"$(2)"/"$(1)"; +

In case we go for shipping apkovls in iso's, we might want keep some
files in there too. So we should probably do that in subdirs.

hum... need to think about this.

> +		echo "	append /boot/xen.gz --- /boot/$$flavor

I wonder if we could/should keep those in $(PROFILE).conf.mk...

> alpine_dev=cdrom:iso9660
> modules=loop,squashfs,sd-mod,usb-storage,floppy,sr-mod
> modloop=/boot/$$flavor.modloop.squashfs $(BOOT_CONSOLE)
> --- /boot/$$flavor.gz"; \
> +	done >>$@
> +else
>  		echo "	append initrd=/boot/$$flavor.gz

... hmm.. maybe not. The xen structure is pretty different. Looks
difficult to put that in alpine-xen.conf.mk.

Also, we have the update-extlinux.conf tool. I think we should try fix
that tool so it could create isolinux.cfg suitable for iso image.

> alpine_dev=cdrom:iso9660
> modules=loop,squashfs,sd-mod,usb-storage,floppy,sr-mod quiet
> $(BOOT_CONSOLE)"; \ done >>$@ +endif 
> +		echo "	append /boot/xen.gz --- /boot/$$flavor
> alpine_dev=usbdisk:vfat modules=loop,squashfs,sd-mod,usb-storage
> modloop=/boot/$$flavor.modloop.squashfs $(BOOT_CONSOLE)
> --- /boot/$$flavor.gz"; \
> +	done >>$@
> +else
>  		echo "	append initrd=/boot/$$flavor.gz
> alpine_dev=usbdisk:vfat modules=loop,squashfs,sd-mod,usb-storage
> quiet $(BOOT_CONSOLE)"; \ done >>$@ +endif
>  
>  clean-syslinux:
> +		| $(TAR) -xz usr/share/syslinux/mboot.c32 -O >
> $(ISO_DIR)/boot/mboot.c32 +endif
>  	@rm -f $(ISO_KERNEL)

hard to do the above without special case for xen. hum...

> -$(ISOFS_DIRSTAMP): $(ALL_MODLOOP) $(ALL_INITFS) $(ISOLINUX_CFG)
> $(ISOLINUX_BIN) $(ALL_ISO_KERNEL) $(ISO_REPOS_DIRSTAMP)
> $(APKOVL_STAMP) $(SYSLINUX_CFG) +$(ISOFS_DIRSTAMP): $(ALL_MODLOOP)
> $(ALL_INITFS) $(ISOLINUX_CFG) $(ISOLINUX_BIN) $(ALL_ISO_KERNEL)
> $(ISO_REPOS_DIRSTAMP) $(APKOVL_STAMP) $(SYSLINUX_CFG) $(APKOVL_DEST)

I think I will apply this and we can think of how to clean it up later.

-nc

---