[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [RFC 3/7] linux-stubdomain: Build a disk image



This patch builds a disk image intended to be mounted as rootfs by the
Linux stub domain.  It is assembled using dracut and genext2fs.

Signed-off-by: Eric Shelton <eshelton@xxxxxxxxx>
---
 stubdom-linux/.gitignore          |  4 ++
 stubdom-linux/Makefile            | 45 +++++++++++++++++++-
 stubdom-linux/extra/initscript    | 25 +++++++++++
 stubdom-linux/extra/qemu-ifup     |  7 +++
 stubdom-linux/gen-stubdom-disk.sh | 89 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 168 insertions(+), 2 deletions(-)
 create mode 100644 stubdom-linux/extra/initscript
 create mode 100644 stubdom-linux/extra/qemu-ifup
 create mode 100755 stubdom-linux/gen-stubdom-disk.sh

diff --git a/stubdom-linux/.gitignore b/stubdom-linux/.gitignore
index 891f0c8..b8f2e26 100644
--- a/stubdom-linux/.gitignore
+++ b/stubdom-linux/.gitignore
@@ -4,3 +4,7 @@
 /linux-*.tar.xz
 /linux-*/
 /vmlinuz-stubdom
+/initramfs
+/stubdom-disk.img
+/dracut-???*
+/genext2fs-*
diff --git a/stubdom-linux/Makefile b/stubdom-linux/Makefile
index 31bfbee..a46f5b0 100644
--- a/stubdom-linux/Makefile
+++ b/stubdom-linux/Makefile
@@ -12,7 +12,19 @@ LINUX_V=linux-3.17.8
 VMLINUZ=$(LINUX_V)/arch/x86/boot/bzImage
 LINUX_URL=ftp://ftp.kernel.org/pub/linux/kernel/v3.x/$(LINUX_V).tar.xz
 
-all: $(VMLINUZ)
+DRACUT_URL="http://www.kernel.org/pub/linux/utils/boot/dracut";
+DRACUT_V=dracut-033
+
+GENEXT2FS_V = 1.4.1
+GENEXT2FS_URL="http://sourceforge.net/projects/genext2fs/files/genext2fs/$(GENEXT2FS_V)/genext2fs-$(GENEXT2FS_V).tar.gz/download"
+
+# Stubdom disk content
+STUBDOM_DISK_FILE= \
+  qemu-build/i386-softmmu/qemu-system-i386 \
+  extra/initscript \
+  extra/qemu-ifup
+
+all: $(VMLINUZ) stubdom-disk.img
 
 qemu-build/Makefile:
        export GIT=$(GIT); \
@@ -73,5 +85,34 @@ $(LINUX_V)/Makefile $(LINUX_V)/.config: $(LINUX_V).tar.xz
 $(VMLINUZ): $(LINUX_V)/.config
        $(MAKE) -C $(LINUX_V)
 
-install: $(VMLINUZ)
+$(DRACUT_V).tar.xz:
+       $(FETCHER) $@ $(DRACUT_URL)/$@
+
+DRACUT_INSTALL=$(CURDIR)/$(DRACUT_V)/dracut-install
+$(DRACUT_INSTALL): $(DRACUT_V).tar.xz
+       tar xf $<
+       $(MAKE) -C $(DRACUT_V) dracut-install
+
+GENEXT2FS = $(shell which genext2fs 2>/dev/null)
+ifeq ($(GENEXT2FS),)
+GENEXT2FS = $(CURDIR)/genext2fs-$(GENEXT2FS_V)/genext2fs
+endif
+
+genext2fs-$(GENEXT2FS_V).tar.gz:
+       $(FETCHER) $@ $(GENEXT2FS_URL)
+$(CURDIR)/genext2fs-$(GENEXT2FS_V)/genext2fs: genext2fs-$(GENEXT2FS_V).tar.gz
+       tar xf $<
+       cd genext2fs-$(GENEXT2FS_V) && ./configure
+       $(MAKE) -C genext2fs-$(GENEXT2FS_V)
+
+gen-stubdom-disk.sh: $(DRACUT_INSTALL) $(GENEXT2FS)
+
+export DRACUT_INSTALL
+export GENEXT2FS
+stubdom-disk.img: gen-stubdom-disk.sh $(STUBDOM_DISK_FILE)
+       env -u MAKELEVEL -u MAKEFLAGS -u MFLAGS ./$<
+       chmod a-w $@
+
+install: $(VMLINUZ) stubdom-disk.img
        cp -f $(VMLINUZ) $(DESTDIR)/usr/local/lib/xen/boot/vmlinuz-stubdom
+       cp -f stubdom-disk.img $(DESTDIR)/usr/local/lib/xen/boot/
diff --git a/stubdom-linux/extra/initscript b/stubdom-linux/extra/initscript
new file mode 100644
index 0000000..a0f50ad
--- /dev/null
+++ b/stubdom-linux/extra/initscript
@@ -0,0 +1,25 @@
+#!/bin/busybox sh
+
+set -e
+set -x
+mount -t sysfs /sys /sys
+mount -t proc /proc /proc
+mount -t xenfs -o nodev /proc/xen /proc/xen
+
+if test -e /sys/class/net/eth0; then
+  ip link set eth0 address fe:ff:ff:ff:ff:fe
+  ip addr flush eth0
+  ip link set eth0 up
+  brctl addbr br0
+  brctl addif br0 eth0
+  ip link set br0 up
+else
+  echo "No network interface named eth0."
+  ls -l /sys/class/net/
+fi
+
+domid=$(/bin/xenstore-read "target")
+vm_path=$(xenstore-read "/local/domain/$domid/vm")
+dm_args=$(xenstore-read "$vm_path/image/dmargs")
+
+/bin/qemu $dm_args
diff --git a/stubdom-linux/extra/qemu-ifup b/stubdom-linux/extra/qemu-ifup
new file mode 100644
index 0000000..d71672b
--- /dev/null
+++ b/stubdom-linux/extra/qemu-ifup
@@ -0,0 +1,7 @@
+#! /bin/busybox sh
+
+ip link set "$1" down
+ip link set "$1" address fe:ff:ff:ff:ff:fd
+ip addr flush "$1"
+brctl addif br0 "$1"
+ip link set "$1" up
diff --git a/stubdom-linux/gen-stubdom-disk.sh 
b/stubdom-linux/gen-stubdom-disk.sh
new file mode 100755
index 0000000..c209cba
--- /dev/null
+++ b/stubdom-linux/gen-stubdom-disk.sh
@@ -0,0 +1,89 @@
+#!/bin/bash
+
+set -e
+umask 022
+
+script_qemu_ifup="extra/qemu-ifup"
+script_init="extra/initscript"
+
+XEN_ROOT="$(cd ..; pwd)"
+xenstore_libs="$XEN_ROOT/tools/xenstore"
+libxc_libs="$XEN_ROOT/tools/libxc"
+export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$xenstore_libs"
+export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$libxc_libs"
+
+initdir="`pwd`/initramfs/"
+
+rm -fr "$initdir"
+
+# Using dracut to gather the shared libraries
+# from https://dracut.wiki.kernel.org/index.php/Main_Page
+if ! test -x "$DRACUT_INSTALL"; then
+  echo DRACUT_INSTALL unset or incorrect >&2
+  exit 1
+fi
+if ! test -x "$GENEXT2FS"; then
+  if ! which genext2fs 2>&1 >/dev/null; then
+    echo genext2fs not found and GENEXT2FS unset >&2
+    exit 1
+  fi
+else
+  function genext2fs(){
+    "$GENEXT2FS" "$@"
+  }
+fi
+
+
+inst() {
+    [[ -e "${initdir}/${2:-$1}" ]] && return 0  # already there
+    "$DRACUT_INSTALL" -D "$initdir" -l "$@"
+}
+
+mkdir -p "$initdir"/{bin,etc,proc/xen,sys,lib,dev,tmp}
+
+echo "Building initrd in $initdir"
+inst busybox /bin/busybox
+make DESTDIR="$initdir" -C qemu-build install
+# this gather libs install on the system for qemu
+inst "$initdir/bin/qemu-system-i386" /bin/qemu
+inst "$XEN_ROOT/tools/xenstore/xenstore-read" "/bin/xenstore-read"
+inst "$script_qemu_ifup" "/etc/qemu-ifup"
+chmod +x "$initdir/etc/qemu-ifup"
+inst "$script_init" "/init"
+chmod 755 "$initdir/init"
+
+ln -s busybox "$initdir/bin/mount"
+
+for d in "/usr/lib" "$xenstore_libs" "$libxc_libs"; do
+  d="$initdir/$d"
+  if test -d "$d"; then
+    mv "$d"/* "$initdir/lib64/"
+    if test -L "$d"; then
+      rm "$d"
+    else
+      rmdir --ignore-fail-on-non-empty -p "$d"
+    fi
+  fi
+done
+
+mv "$initdir/lib64/gcc"/*/*/* "$initdir/lib64/"
+rm -rf "$initdir/lib64/gcc"
+
+mkdir -p "$initdir/usr"
+ln -s /lib "$initdir/usr/lib"
+
+if false; then
+  IMAGE="./initramfs.cpio"
+  rm -f "$IMAGE"
+  (cd "$initdir"; find . | cpio -H newc --quiet -o) >| "$IMAGE" || exit 1
+  gzip -f "$IMAGE"
+else # ext2 fs using:
+  stubdom_disk=stubdom-disk.img
+  rm -f "$stubdom_disk"
+  genext2fs \
+    --root "$initdir" \
+    --size-in-blocks $(($(du -s "$initdir"|cut -f1)+2000)) \
+    --reserved-percentage 0 \
+    --squash \
+    "$stubdom_disk"
+fi
-- 
1.8.5.5


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.