File lxc-opensuse-12.1.patch of Package lxc

From 44ee8a102e3d8052631fbb119f58a55ce678d039 Mon Sep 17 00:00:00 2001
From: Frederic Crozat <fcrozat@suse.com>
Date: Tue, 25 Oct 2011 11:25:18 +0200
Subject: [PATCH 1/2] templates: update openSUSE template for openSUSE 12.1

rely on "build" package, to ensure chroot can be created with
distribution older than 12.1

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
---
 templates/lxc-opensuse.in |   75 ++++++++++++++++++++++++++++----------------
 1 files changed, 48 insertions(+), 27 deletions(-)

diff --git a/templates/lxc-opensuse.in b/templates/lxc-opensuse.in
index 811876a..d30147d 100644
--- a/templates/lxc-opensuse.in
+++ b/templates/lxc-opensuse.in
@@ -25,7 +25,7 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
-DISTRO=11.4
+DISTRO=12.1
 
 configure_opensuse()
 {
@@ -106,28 +106,11 @@ cons:2345:respawn:/sbin/mingetty --noclear console screen
 c1:2345:respawn:/sbin/mingetty --noclear tty1 screen
 EOF
 
-    # patch boot script, no longer needed in openSUSE 12.1 / SLE11-SP2
-    patch --quiet -d $rootfs/etc/init.d/ << EOF
---- boot.orig	2011-05-26 16:03:07.000000000 +0200
-+++ boot	2011-05-26 16:03:19.000000000 +0200
-@@ -98,12 +98,12 @@
-     echo "***************************************************************"
-     /sbin/halt -f
-     fi
--    echo -n "Mounting devtmpfs at /dev"
--    mount -n -t devtmpfs -o mode=0755 devtmpfs /dev
--    rc_status -v -r
-+#    echo -n "Mounting devtmpfs at /dev"
-+#    mount -n -t devtmpfs -o mode=0755 devtmpfs /dev
-+#    rc_status -v -r
- fi
-
--cp -axT --remove-destination /lib/udev/devices /dev
-+#cp -axT --remove-destination /lib/udev/devices /dev
-
- if test -d /sys/kernel/debug -a "$HAVE_DEBUGFS" = "1" ; then
-     mount -n -t debugfs debugfs /sys/kernel/debug > /dev/null 2>&1
+    # set /dev/console as securetty
+    cat << EOF >> $rootfs/etc/securetty
+console
 EOF
+
     cat <<EOF >> $rootfs/etc/sysconfig/boot
 # disable root fsck
 ROOTFS_FSCK="0"
@@ -136,7 +119,7 @@ EOF
 
 
     # remove pointless services in a container
-    insserv -r -f -p $rootfs/etc/init.d boot.udev boot.udev_retry boot.md boot.lvm boot.loadmodules boot.device-mapper boot.clock boot.swap boot.klog
+    chroot $rootfs /sbin/insserv -r -f boot.udev boot.loadmodules boot.device-mapper boot.clock boot.swap boot.klog kbd
 
     echo "Please change root-password !"
     echo "root:root" | chroot $rootfs chpasswd
@@ -149,6 +132,12 @@ download_opensuse()
     cache=$1
     arch=$2
 
+    if [ ! -x /usr/bin/build ]; then
+       echo "Could not create openSUSE template :"
+       echo "you need to install \"build\" package"
+       return 1
+    fi
+
     # check the mini opensuse was not already downloaded
     mkdir -p "$cache/partial-$arch"
 
@@ -159,18 +148,50 @@ download_opensuse()
 
     # download a mini opensuse into a cache
     echo "Downloading opensuse minimal ..."
+    mkdir -p "$cache/partial-$arch-packages"
+    zypper --quiet --root $cache/partial-$arch-packages --non-interactive ar http://download.opensuse.org/distribution/$DISTRO/repo/oss/ repo-oss
+    zypper --quiet --root $cache/partial-$arch-packages --non-interactive ar http://download.opensuse.org/update/$DISTRO/ update
+    zypper --quiet --root $cache/partial-$arch-packages --non-interactive --gpg-auto-import-keys update
+    zypper --root $cache/partial-$arch-packages --non-interactive in --auto-agree-with-licenses --download-only zypper lxc patterns-openSUSE-base sysvinit-init
+    cat > $cache/partial-$arch-packages/opensuse.conf << EOF
+Preinstall: aaa_base bash coreutils diffutils
+Preinstall: filesystem fillup glibc grep insserv libacl1 libattr1
+Preinstall: libbz2-1 libgcc46 libxcrypt libncurses5 pam
+Preinstall: permissions libreadline6 rpm sed tar zlib libselinux1
+Preinstall: liblzma5 libcap2 libpcre0
+Preinstall: libpopt0 libelf1 liblua5_1
+
+RunScripts: aaa_base
+
+Support: zypper
+Support: patterns-openSUSE-base
+Support: lxc
+Prefer: sysvinit-init
+
+Ignore: patterns-openSUSE-base:patterns-openSUSE-yast2_install_wf
+EOF
+
+    CLEAN_BUILD=1 BUILD_ROOT="$cache/partial-$arch" BUILD_DIST="$cache/partial-$arch-packages/opensuse.conf" /usr/lib/build/init_buildsystem  --clean --cachedir $cache/partial-$arch-cache --repository $cache/partial-$arch-packages/var/cache/zypp/packages/repo-oss/suse/$arch --repository $cache/partial-$arch-packages/var/cache/zypp/packages/repo-oss/suse/noarch
+    chroot $cache/partial-$arch /usr/bin/zypper --quiet --non-interactive ar http://download.opensuse.org/distribution/$DISTRO/repo/oss repo-oss
+    chroot $cache/partial-$arch /usr/bin/zypper --quiet --non-interactive ar http://download.opensuse.org/update/$DISTRO/ update
+    chroot $cache/partial-$arch rpm -e patterns-openSUSE-base
+    umount $cache/partial-$arch/proc
+#   really clean the image
+    rm -fr $cache/partial-$arch/{.build,.guessed_dist,.srcfiles*,installed-pkg}
+    rm -fr $cache/partial-$arch/dev
+#    make sure we have a minimal /dev
     mkdir -p "$cache/partial-$arch/dev"
     mknod -m 666 $cache/partial-$arch/dev/null c 1 3
     mknod -m 666 $cache/partial-$arch/dev/zero c 1 5
-    zypper --quiet --root $cache/partial-$arch --non-interactive ar http://download.opensuse.org/distribution/$DISTRO/repo/oss/ repo-oss
-    zypper --quiet --root $cache/partial-$arch --non-interactive ar http://download.opensuse.org/update/$DISTRO/ update
-    zypper --quiet --root $cache/partial-$arch --non-interactive --gpg-auto-import-keys in --auto-agree-with-licenses -t pattern base
-    zypper --quiet --root $cache/partial-$arch --non-interactive --gpg-auto-import-keys in +lxc -kbd -patterns-openSUSE-base
+#   create mtab symlink
+    rm -f $cache/partial-$arch/etc/mtab
+    ln -sf /proc/self/mounts $cache/partial-$arch/etc/mtab
     if [ $? -ne 0 ]; then
 	echo "Failed to download the rootfs, aborting."
 	return 1
     fi
 
+    rm -fr "$cache/partial-$arch-packages"
     mv "$1/partial-$arch" "$1/rootfs-$arch"
     echo "Download complete."
 
-- 
1.7.7


From 594d9ba1043bdbc3bb0bded71e19a6ed3e724e4d Mon Sep 17 00:00:00 2001
From: Frederic Crozat <fcrozat@suse.com>
Date: Wed, 18 Apr 2012 17:17:18 +0200
Subject: [PATCH] various fixes for openSUSE template: - create /etc/hostname
 as symlink to /etc/HOSTNAME (lxc-clone fix) - fix
 inadequate space in lxc.mount config (lxc-clone fix) - fix
 openSUSE 12.1 template creation on x86 platform - disable
 network in container if not configured - configure network
 scripts properly

---
 templates/lxc-opensuse.in |   34 +++++++++++++++++++++++++++++-----
 1 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/templates/lxc-opensuse.in b/templates/lxc-opensuse.in
index 120b2c7..4342150 100644
--- a/templates/lxc-opensuse.in
+++ b/templates/lxc-opensuse.in
@@ -34,8 +34,8 @@ configure_opensuse()
 
    # set network as static, but everything is done by LXC outside the container
    cat <<EOF > $rootfs/etc/sysconfig/network/ifcfg-eth0
-STARTMODE='auto'
-BOOTPROTO='static'
+STARTMODE='manual'
+BOOTPROTO='none'
 EOF
 
    # set default route
@@ -71,6 +71,8 @@ EOF
     cat <<EOF > $rootfs/etc/HOSTNAME
 $hostname
 EOF
+    # ensure /etc/hostname is available too
+    ln -s -f HOSTNAME $rootfs/etc/hostname
 
     # do not use hostname from HOSTNAME variable
     cat <<EOF >> $rootfs/etc/sysconfig/cron
@@ -156,10 +158,11 @@ download_opensuse()
     cat > $cache/partial-$arch-packages/opensuse.conf << EOF
 Preinstall: aaa_base bash coreutils diffutils
 Preinstall: filesystem fillup glibc grep insserv libacl1 libattr1
-Preinstall: libbz2-1 libgcc46 libxcrypt libncurses5 pam
+Preinstall: libbz2-1 libgcc46 libncurses5 pam
 Preinstall: permissions libreadline6 rpm sed tar zlib libselinux1
 Preinstall: liblzma5 libcap2 libpcre0
 Preinstall: libpopt0 libelf1 liblua5_1
+Preinstall: netcfg
 
 RunScripts: aaa_base
 
@@ -169,9 +172,21 @@ Support: lxc
 Prefer: sysvinit-init
 
 Ignore: patterns-openSUSE-base:patterns-openSUSE-yast2_install_wf
+Ignore: patterns-openSUSE-base:polkit-defaults-privs
+Ignore: patterns-openSUSE-base:openSUSE-build-key
 EOF
+    if [ "$arch" == "i686" ]; then
+        mkdir -p $cache/partial-$arch-packages/var/cache/zypp/packages/repo-oss/suse/i686/
+        for i in "$cache/partial-$arch-packages/var/cache/zypp/packages/repo-oss/suse/i586/*" ; do
+            ln -s $i $cache/partial-$arch-packages/var/cache/zypp/packages/repo-oss/suse/i686/
+        done
+        mkdir -p $cache/partial-$arch-packages/var/cache/zypp/packages/update/i686
+        for i in "$cache/partial-$arch-packages/var/cache/zypp/packages/update/i586/*" ; do
+            ln -s $i $cache/partial-$arch-packages/var/cache/zypp/packages/update/i686/
+	done
+    fi
 
-    CLEAN_BUILD=1 BUILD_ROOT="$cache/partial-$arch" BUILD_DIST="$cache/partial-$arch-packages/opensuse.conf" /usr/lib/build/init_buildsystem  --clean --cachedir $cache/partial-$arch-cache --repository $cache/partial-$arch-packages/var/cache/zypp/packages/repo-oss/suse/$arch --repository $cache/partial-$arch-packages/var/cache/zypp/packages/repo-oss/suse/noarch
+    CLEAN_BUILD=1 BUILD_ARCH="$arch" BUILD_ROOT="$cache/partial-$arch" BUILD_DIST="$cache/partial-$arch-packages/opensuse.conf" /usr/lib/build/init_buildsystem  --clean --cachedir $cache/partial-$arch-cache --repository $cache/partial-$arch-packages/var/cache/zypp/packages/repo-oss/suse/$arch --repository $cache/partial-$arch-packages/var/cache/zypp/packages/repo-oss/suse/noarch --repository $cache/partial-$arch-packages/var/cache/zypp/packages/update/$arch --repository $cache/partial-$arch-packages/var/cache/zypp/packages/update/noarch
     chroot $cache/partial-$arch /usr/bin/zypper --quiet --non-interactive ar http://download.opensuse.org/distribution/$DISTRO/repo/oss repo-oss
     chroot $cache/partial-$arch /usr/bin/zypper --quiet --non-interactive ar http://download.opensuse.org/update/$DISTRO/ update
     chroot $cache/partial-$arch rpm -e patterns-openSUSE-base
@@ -254,13 +269,22 @@ copy_configuration()
     rootfs=$2
     name=$3
 
+# only disable network if no network configuration was passed
+grep -q lxc.network.type $path/config
+network_not_configured=$?
+if [ $network_not_configured -eq 1 ]; then
+   cat <<EOF >> $path/config
+lxc.network.type = empty
+EOF
+fi
+
     cat <<EOF >> $path/config
 lxc.utsname = $name
 
 lxc.tty = 4
 lxc.pts = 1024
 lxc.rootfs = $rootfs
-lxc.mount  = $path/fstab
+lxc.mount = $path/fstab
 
 lxc.cgroup.devices.deny = a
 # /dev/null and zero
-- 
1.7.7

openSUSE Build Service is sponsored by