Hi all,

you'll find attached patch to update lxc openSUSE template for upcoming
openSUSE 12.1 release. Moreover, the way it creates container has been
modified to use "build" package (from OBS Tools), which ensure we can
create a 12.1 container on an older distribution (ie not running latest
RPM version).

For now, container is configured to not use systemd (unfortunately) but
sysvinit.
-- 
Frederic Crozat <fcro...@suse.com>
SUSE

>From 658cb3e87f37e7386c611650c5c2717caac193cd Mon Sep 17 00:00:00 2001
From: Frederic Crozat <fcro...@suse.com>
Date: Tue, 25 Oct 2011 11:25:18 +0200
Subject: [PATCH] templates: update openSUSE template for openSUSE 12.1

rely on "build" package, to ensure chroot can be created with
distribution older than 12.1
---
 templates/lxc-opensuse.in |   72 +++++++++++++++++++++++++++-----------------
 1 files changed, 44 insertions(+), 28 deletions(-)

diff --git a/templates/lxc-opensuse.in b/templates/lxc-opensuse.in
index 811876a..9e44773 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,6 @@ 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
-EOF
     cat <<EOF >> $rootfs/etc/sysconfig/boot
 # disable root fsck
 ROOTFS_FSCK="0"
@@ -136,7 +114,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 +127,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 +143,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

------------------------------------------------------------------------------
The demand for IT networking professionals continues to grow, and the
demand for specialized networking skills is growing even more rapidly.
Take a complimentary Learning@Cisco Self-Assessment and learn 
about Cisco certifications, training, and career opportunities. 
http://p.sf.net/sfu/cisco-dev2dev
_______________________________________________
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel

Reply via email to