Merge lp:~ubuntu-branches/ubuntu/quantal/lxc/quantal-201210151516 into lp:ubuntu/quantal/lxc

Proposed by Ubuntu Package Importer
Status: Rejected
Rejected by: James Westby
Proposed branch: lp:~ubuntu-branches/ubuntu/quantal/lxc/quantal-201210151516
Merge into: lp:ubuntu/quantal/lxc
Diff against target: 1175 lines (+1154/-0) (has conflicts)
3 files modified
.pc/0224-ubuntu-templates-devtmpfs/templates/lxc-ubuntu-cloud.in (+406/-0)
.pc/0224-ubuntu-templates-devtmpfs/templates/lxc-ubuntu.in (+718/-0)
debian/patches/0224-ubuntu-templates-devtmpfs (+30/-0)
Conflict adding file .pc/0224-ubuntu-templates-devtmpfs.  Moved existing file to .pc/0224-ubuntu-templates-devtmpfs.moved.
Conflict adding file debian/patches/0224-ubuntu-templates-devtmpfs.  Moved existing file to debian/patches/0224-ubuntu-templates-devtmpfs.moved.
To merge this branch: bzr merge lp:~ubuntu-branches/ubuntu/quantal/lxc/quantal-201210151516
Reviewer Review Type Date Requested Status
Ubuntu branches Pending
Review via email: mp+129689@code.launchpad.net

Description of the change

The package importer has detected a possible inconsistency between the package history in the archive and the history in bzr. As the archive is authoritative the importer has made lp:ubuntu/quantal/lxc reflect what is in the archive and the old bzr branch has been pushed to lp:~ubuntu-branches/ubuntu/quantal/lxc/quantal-201210151516. This merge proposal was created so that an Ubuntu developer can review the situations and perform a merge/upload if necessary. There are three typical cases where this can happen.
  1. Where someone pushes a change to bzr and someone else uploads the package without that change. This is the reason that this check is done by the importer. If this appears to be the case then a merge/upload should be done if the changes that were in bzr are still desirable.
  2. The importer incorrectly detected the above situation when someone made a change in bzr and then uploaded it.
  3. The importer incorrectly detected the above situation when someone just uploaded a package and didn't touch bzr.

If this case doesn't appear to be the first situation then set the status of the merge proposal to "Rejected" and help avoid the problem in future by filing a bug at https://bugs.launchpad.net/udd linking to this merge proposal.

(this is an automatically generated message)

To post a comment you must log in.

Unmerged revisions

164. By Serge Hallyn

releasing version 0.8.0~rc1-4ubuntu37

163. By Serge Hallyn

0224-ubuntu-templates-devtmpfs: mount devtmpfs in ubuntu containers.
(LP: #1060404)

162. By Serge Hallyn

update 0222-debian-dhcp3-package: use dhcp3-client, not server!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory '.pc/0224-ubuntu-templates-devtmpfs'
2=== renamed directory '.pc/0224-ubuntu-templates-devtmpfs' => '.pc/0224-ubuntu-templates-devtmpfs.moved'
3=== added file '.pc/0224-ubuntu-templates-devtmpfs/.timestamp'
4=== added directory '.pc/0224-ubuntu-templates-devtmpfs/templates'
5=== added file '.pc/0224-ubuntu-templates-devtmpfs/templates/lxc-ubuntu'
6=== added file '.pc/0224-ubuntu-templates-devtmpfs/templates/lxc-ubuntu-cloud.in'
7--- .pc/0224-ubuntu-templates-devtmpfs/templates/lxc-ubuntu-cloud.in 1970-01-01 00:00:00 +0000
8+++ .pc/0224-ubuntu-templates-devtmpfs/templates/lxc-ubuntu-cloud.in 2012-10-15 15:25:24 +0000
9@@ -0,0 +1,406 @@
10+#!/bin/bash
11+
12+# template script for generating ubuntu container for LXC based on released cloud
13+# images
14+#
15+# Copyright © 2012 Serge Hallyn <serge.hallyn@canonical.com>
16+#
17+# This program is free software; you can redistribute it and/or modify
18+# it under the terms of the GNU General Public License version 2, as
19+# published by the Free Software Foundation.
20+
21+# This program is distributed in the hope that it will be useful,
22+# but WITHOUT ANY WARRANTY; without even the implied warranty of
23+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24+# GNU General Public License for more details.
25+
26+# You should have received a copy of the GNU General Public License along
27+# with this program; if not, write to the Free Software Foundation, Inc.,
28+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29+#
30+
31+set -e
32+
33+if [ -r /etc/default/lxc ]; then
34+ . /etc/default/lxc
35+fi
36+
37+copy_configuration()
38+{
39+ path=$1
40+ rootfs=$2
41+ name=$3
42+ arch=$4
43+ release=$5
44+
45+ if [ $arch = "i386" ]; then
46+ arch="i686"
47+ fi
48+
49+ # if there is exactly one veth network entry, make sure it has an
50+ # associated hwaddr.
51+ nics=`grep -e '^lxc\.network\.type[ \t]*=[ \t]*veth' $path/config | wc -l`
52+ if [ $nics -eq 1 ]; then
53+ grep -q "^lxc.network.hwaddr" $path/config || cat <<EOF >> $path/config
54+lxc.network.hwaddr = 00:16:3e:$(openssl rand -hex 3| sed 's/\(..\)/\1:/g; s/.$//')
55+EOF
56+ fi
57+
58+ grep -q "^lxc.rootfs" $path/config 2>/dev/null || echo "lxc.rootfs = $rootfs" >> $path/config
59+ cat <<EOF >> $path/config
60+lxc.utsname = $name
61+
62+lxc.tty = 4
63+lxc.pts = 1024
64+lxc.mount = $path/fstab
65+lxc.arch = $arch
66+lxc.cap.drop = sys_module mac_admin
67+lxc.pivotdir = lxc_putold
68+
69+# uncomment the next line to run the container unconfined:
70+#lxc.aa_profile = unconfined
71+
72+lxc.cgroup.devices.deny = a
73+# Allow any mknod (but not using the node)
74+lxc.cgroup.devices.allow = c *:* m
75+lxc.cgroup.devices.allow = b *:* m
76+# /dev/null and zero
77+lxc.cgroup.devices.allow = c 1:3 rwm
78+lxc.cgroup.devices.allow = c 1:5 rwm
79+# consoles
80+lxc.cgroup.devices.allow = c 5:1 rwm
81+lxc.cgroup.devices.allow = c 5:0 rwm
82+#lxc.cgroup.devices.allow = c 4:0 rwm
83+#lxc.cgroup.devices.allow = c 4:1 rwm
84+# /dev/{,u}random
85+lxc.cgroup.devices.allow = c 1:9 rwm
86+lxc.cgroup.devices.allow = c 1:8 rwm
87+lxc.cgroup.devices.allow = c 136:* rwm
88+lxc.cgroup.devices.allow = c 5:2 rwm
89+# rtc
90+lxc.cgroup.devices.allow = c 254:0 rwm
91+#fuse
92+lxc.cgroup.devices.allow = c 10:229 rwm
93+#tun
94+lxc.cgroup.devices.allow = c 10:200 rwm
95+#full
96+lxc.cgroup.devices.allow = c 1:7 rwm
97+#hpet
98+lxc.cgroup.devices.allow = c 10:228 rwm
99+#kvm
100+lxc.cgroup.devices.allow = c 10:232 rwm
101+EOF
102+
103+ cat <<EOF > $path/fstab
104+proc proc proc nodev,noexec,nosuid 0 0
105+sysfs sys sysfs defaults 0 0
106+EOF
107+
108+ # rmdir /dev/shm for containers that have /run/shm
109+ # I'm afraid of doing rm -rf $rootfs/dev/shm, in case it did
110+ # get bind mounted to the host's /run/shm. So try to rmdir
111+ # it, and in case that fails move it out of the way.
112+ if [ ! -L $rootfs/dev/shm ] && [ -d $rootfs/run/shm ] && [ -e $rootfs/dev/shm ]; then
113+ mv $rootfs/dev/shm $rootfs/dev/shm.bak
114+ ln -s /run/shm $rootfs/dev/shm
115+ fi
116+
117+ return 0
118+}
119+
120+usage()
121+{
122+ cat <<EOF
123+LXC Container configuration for Ubuntu Cloud images.
124+
125+Generic Options
126+[ -r | --release <release> ]: Release name of container, defaults to host
127+[ -a | --arch ]: Arhcitecture of container, defaults to host arcitecture
128+[ -C | --cloud ]: Configure container for use with meta-data service, defaults to no
129+[ -T | --tarball ]: Location of tarball
130+[ -d | --debug ]: Run with 'set -x' to debug errors
131+[ -s | --stream]: Use specified stream rather than 'released'
132+
133+Options, mutually exclusive of "-C" and "--cloud":
134+ [ -i | --hostid ]: HostID for cloud-init, defaults to random string
135+ [ -u | --userdata ]: Cloud-init user-data file to configure container on start
136+ [ -S | --auth-key ]: SSH Public key file to inject into container
137+ [ -L | --nolocales ]: Do not copy host's locales into container
138+
139+EOF
140+ return 0
141+}
142+
143+options=$(getopt -o a:hp:r:n:Fi:CLS:T:ds: -l arch:,help,path:,release:,name:,flush-cache,hostid:,auth-key:,cloud,no_locales,tarball:,debug,stream:,userdata: -- "$@")
144+if [ $? -ne 0 ]; then
145+ usage $(basename $0)
146+ exit 1
147+fi
148+eval set -- "$options"
149+
150+release=lucid
151+if [ -f /etc/lsb-release ]; then
152+ . /etc/lsb-release
153+ case "$DISTRIB_CODENAME" in
154+ lucid|natty|oneiric|precise|quantal)
155+ release=$DISTRIB_CODENAME
156+ ;;
157+ esac
158+fi
159+
160+arch=$(arch)
161+
162+# Code taken from debootstrap
163+if [ -x /usr/bin/dpkg ] && /usr/bin/dpkg --print-architecture >/dev/null 2>&1; then
164+ arch=`/usr/bin/dpkg --print-architecture`
165+elif type udpkg >/dev/null 2>&1 && udpkg --print-architecture >/dev/null 2>&1; then
166+ arch=`/usr/bin/udpkg --print-architecture`
167+else
168+ arch=$(arch)
169+ if [ "$arch" = "i686" ]; then
170+ arch="i386"
171+ elif [ "$arch" = "x86_64" ]; then
172+ arch="amd64"
173+ elif [ "$arch" = "armv7l" ]; then
174+ # note: arm images don't exist before oneiric; are called armhf in
175+ # precise and later; and are not supported by the query, so we don't actually
176+ # support them yet (see check later on). When Query2 is available,
177+ # we'll use that to enable arm images.
178+ arch="armel"
179+ fi
180+fi
181+
182+debug=0
183+hostarch=$arch
184+cloud=0
185+locales=1
186+flushcache=0
187+stream="released"
188+while true
189+do
190+ case "$1" in
191+ -h|--help) usage $0 && exit 0;;
192+ -p|--path) path=$2; shift 2;;
193+ -n|--name) name=$2; shift 2;;
194+ -F|--flush-cache) flushcache=1; shift 1;;
195+ -r|--release) release=$2; shift 2;;
196+ -a|--arch) arch=$2; shift 2;;
197+ -i|--hostid) host_id=$2; shift 2;;
198+ -u|--userdata) userdata=$2; shift 2;;
199+ -C|--cloud) cloud=1; shift 1;;
200+ -S|--auth-key) auth_key=$2; shift 2;;
201+ -L|--no_locales) locales=0; shift 2;;
202+ -T|--tarball) tarball=$2; shift 2;;
203+ -d|--debug) debug=1; shift 1;;
204+ -s|--stream) stream=$2; shift 2;;
205+ --) shift 1; break ;;
206+ *) break ;;
207+ esac
208+done
209+
210+if [ $debug -eq 1 ]; then
211+ set -x
212+fi
213+
214+if [ "$arch" == "i686" ]; then
215+ arch=i386
216+fi
217+
218+if [ $hostarch = "i386" -a $arch = "amd64" ]; then
219+ echo "can't create amd64 container on i386"
220+ exit 1
221+fi
222+
223+if [ $arch != "i386" -a $arch != "amd64" ]; then
224+ echo "Only i386 and amd64 are supported by the ubuntu cloud template."
225+ exit 1
226+fi
227+
228+if [ "$stream" != "daily" -a "$stream" != "released" ]; then
229+ echo "Only 'daily' and 'released' streams are supported"
230+ exit 1
231+fi
232+
233+if [ -n "$userdata" ]; then
234+ if [ ! -f "$userdata" ]; then
235+ echo "Userdata ($userdata) does not exist"
236+ exit 1
237+ else
238+ userdata=`readlink -f $userdata`
239+ fi
240+fi
241+
242+if [ -n "$auth_key" ]; then
243+ if [ ! -f "$auth_key" ]; then
244+ echo "--auth-key=${auth_key} must reference a file"
245+ exit 1
246+ fi
247+ auth_key=$(readlink -f "${auth_key}") ||
248+ { echo "failed to get full path for auth_key"; exit 1; }
249+fi
250+
251+if [ -z "$path" ]; then
252+ echo "'path' parameter is required"
253+ exit 1
254+fi
255+
256+if [ "$(id -u)" != "0" ]; then
257+ echo "This script should be run as 'root'"
258+ exit 1
259+fi
260+
261+# detect rootfs
262+config="$path/config"
263+if grep -q '^lxc.rootfs' $config 2>/dev/null ; then
264+ rootfs=`grep 'lxc.rootfs =' $config | awk -F= '{ print $2 }'`
265+else
266+ rootfs=$path/rootfs
267+fi
268+
269+type ubuntu-cloudimg-query
270+type wget
271+
272+# determine the url, tarball, and directory names
273+# download if needed
274+cache="/var/cache/lxc/cloud-$release"
275+
276+mkdir -p $cache
277+
278+if [ -n "$tarball" ]; then
279+ url2="$tarball"
280+else
281+ url1=`ubuntu-cloudimg-query $release $stream $arch --format "%{url}\n"`
282+ url2=`echo $url1 | sed -e 's/.tar.gz/-root\0/'`
283+fi
284+
285+filename=`basename $url2`
286+
287+wgetcleanup()
288+{
289+ rm -f $filename
290+}
291+
292+buildcleanup()
293+{
294+ cd $rootfs
295+ umount -l $cache/$xdir || true
296+ rm -rf $cache
297+}
298+
299+# if the release doesn't have a *-rootfs.tar.gz, then create one from the
300+# cloudimg.tar.gz by extracting the .img, mounting it loopback, and creating
301+# a tarball from the mounted image.
302+build_root_tgz()
303+{
304+ url=$1
305+ filename=$2
306+
307+ xdir=`mktemp -d -p .`
308+ tarname=`basename $url`
309+ imgname="$release-*-cloudimg-$arch.img"
310+ trap buildcleanup EXIT SIGHUP SIGINT SIGTERM
311+ if [ $flushcache -eq 1 -o ! -f $cache/$tarname ]; then
312+ rm -f $tarname
313+ echo "Downloading cloud image from $url"
314+ wget $url || { echo "Couldn't find cloud image $url."; exit 1; }
315+ fi
316+ echo "Creating new cached cloud image rootfs"
317+ tar --wildcards -zxf $tarname $imgname
318+ mount -o loop $imgname $xdir
319+ (cd $xdir; tar zcf ../$filename .)
320+ umount $xdir
321+ rm -f $tarname $imgname
322+ rmdir $xdir
323+ echo "New cloud image cache created"
324+ trap EXIT
325+ trap SIGHUP
326+ trap SIGINT
327+ trap SIGTERM
328+}
329+
330+mkdir -p /var/lock/subsys/
331+(
332+ flock -x 200
333+
334+ cd $cache
335+ if [ $flushcache -eq 1 ]; then
336+ echo "Clearing the cached images"
337+ rm -f $filename
338+ fi
339+
340+ trap wgetcleanup EXIT SIGHUP SIGINT SIGTERM
341+ if [ ! -f $filename ]; then
342+ wget $url2 || build_root_tgz $url1 $filename
343+ fi
344+ trap EXIT
345+ trap SIGHUP
346+ trap SIGINT
347+ trap SIGTERM
348+
349+ echo "Extracting container rootfs"
350+ mkdir -p $rootfs
351+ cd $rootfs
352+ tar -zxf $cache/$filename
353+
354+
355+ if [ $cloud -eq 0 ]; then
356+ echo "Configuring for running outside of a cloud environment"
357+ echo "If you want to configure for a cloud evironment, please use '-- -C' to create the container"
358+
359+ seed_d=$rootfs/var/lib/cloud/seed/nocloud-net
360+ rhostid=$(uuidgen | cut -c -8)
361+ host_id=${hostid:-$rhostid}
362+ mkdir -p $seed_d
363+
364+ cat > "$seed_d/meta-data" <<EOF
365+instance-id: lxc-$host_id
366+EOF
367+ if [ -n "$auth_key" ]; then
368+ {
369+ echo "public-keys:" &&
370+ sed -e '/^$/d' -e 's,^,- ,' "$auth_key" "$auth_key"
371+ } >> "$seed_d/meta-data"
372+ [ $? -eq 0 ] ||
373+ { echo "failed to write public keys to metadata"; exit 1; }
374+ fi
375+
376+ rm $rootfs/etc/hostname
377+
378+ if [ $locales -eq 1 ]; then
379+ cp /usr/lib/locale/locale-archive $rootfs/usr/lib/locale/locale-archive
380+ fi
381+
382+ if [ -f "$userdata" ]; then
383+ echo "Using custom user-data"
384+ cp $userdata $seed_d/user-data
385+ else
386+
387+ if [ -z "$MIRROR" ]; then
388+ MIRROR="http://archive.ubuntu.com/ubuntu"
389+ fi
390+
391+ cat > "$seed_d/user-data" <<EOF
392+#cloud-config
393+output: {all: '| tee -a /var/log/cloud-init-output.log'}
394+apt_mirror: $MIRROR
395+manage_etc_hosts: localhost
396+locale: $(/usr/bin/locale | awk -F= '/LANG=/ {print$NF}')
397+password: ubuntu
398+chpasswd: { expire: False }
399+EOF
400+ fi
401+
402+ else
403+
404+ echo "Configured for running in a cloud environment."
405+ echo "If you do not have a meta-data service, this container will likely be useless."
406+
407+ fi
408+) 200>/var/lock/subsys/lxc-ubucloud
409+
410+copy_configuration $path $rootfs $name $arch $release
411+
412+echo "Container $name created."
413+exit 0
414+
415+# vi: ts=4 expandtab
416
417=== added file '.pc/0224-ubuntu-templates-devtmpfs/templates/lxc-ubuntu.in'
418--- .pc/0224-ubuntu-templates-devtmpfs/templates/lxc-ubuntu.in 1970-01-01 00:00:00 +0000
419+++ .pc/0224-ubuntu-templates-devtmpfs/templates/lxc-ubuntu.in 2012-10-15 15:25:24 +0000
420@@ -0,0 +1,718 @@
421+#!/bin/bash
422+
423+#
424+# template script for generating ubuntu container for LXC
425+#
426+# This script consolidates and extends the existing lxc ubuntu scripts
427+#
428+
429+# Copyright © 2011 Serge Hallyn <serge.hallyn@canonical.com>
430+# Copyright © 2010 Wilhelm Meier
431+# Author: Wilhelm Meier <wilhelm.meier@fh-kl.de>
432+#
433+# This program is free software; you can redistribute it and/or modify
434+# it under the terms of the GNU General Public License version 2, as
435+# published by the Free Software Foundation.
436+
437+# This program is distributed in the hope that it will be useful,
438+# but WITHOUT ANY WARRANTY; without even the implied warranty of
439+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
440+# GNU General Public License for more details.
441+
442+# You should have received a copy of the GNU General Public License along
443+# with this program; if not, write to the Free Software Foundation, Inc.,
444+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
445+#
446+
447+set -e
448+
449+if [ -r /etc/default/lxc ]; then
450+ . /etc/default/lxc
451+fi
452+
453+configure_ubuntu()
454+{
455+ rootfs=$1
456+ hostname=$2
457+ release=$3
458+
459+ # configure the network using the dhcp
460+ cat <<EOF > $rootfs/etc/network/interfaces
461+# This file describes the network interfaces available on your system
462+# and how to activate them. For more information, see interfaces(5).
463+
464+# The loopback network interface
465+auto lo
466+iface lo inet loopback
467+
468+auto eth0
469+iface eth0 inet dhcp
470+EOF
471+
472+ # set the hostname
473+ cat <<EOF > $rootfs/etc/hostname
474+$hostname
475+EOF
476+ # set minimal hosts
477+ cat <<EOF > $rootfs/etc/hosts
478+127.0.0.1 localhost
479+127.0.1.1 $hostname
480+
481+# The following lines are desirable for IPv6 capable hosts
482+::1 ip6-localhost ip6-loopback
483+fe00::0 ip6-localnet
484+ff00::0 ip6-mcastprefix
485+ff02::1 ip6-allnodes
486+ff02::2 ip6-allrouters
487+EOF
488+
489+ if [ ! -f $rootfs/etc/init/container-detect.conf ]; then
490+ # suppress log level output for udev
491+ sed -i "s/=\"err\"/=0/" $rootfs/etc/udev/udev.conf
492+
493+ # remove jobs for consoles 5 and 6 since we only create 4 consoles in
494+ # this template
495+ rm -f $rootfs/etc/init/tty{5,6}.conf
496+ fi
497+
498+ if [ -z "$bindhome" ]; then
499+ chroot $rootfs useradd --create-home -s /bin/bash ubuntu
500+ echo "ubuntu:ubuntu" | chroot $rootfs chpasswd
501+ fi
502+
503+ return 0
504+}
505+
506+# finish setting up the user in the container by injecting ssh key and
507+# adding sudo group membership.
508+# passed-in user is either 'ubuntu' or the user to bind in from host.
509+finalize_user()
510+{
511+ user=$1
512+
513+ sudo_version=$(chroot $rootfs dpkg-query -W -f='${Version}' sudo)
514+
515+ if chroot $rootfs dpkg --compare-versions $sudo_version gt "1.8.3p1-1"; then
516+ groups="sudo"
517+ else
518+ groups="sudo admin"
519+ fi
520+
521+ for group in $groups; do
522+ chroot $rootfs groupadd --system $group >/dev/null 2>&1 || true
523+ chroot $rootfs adduser ${user} $group >/dev/null 2>&1 || true
524+ done
525+
526+ if [ -n "$auth_key" -a -f "$auth_key" ]; then
527+ u_path="/home/${user}/.ssh"
528+ root_u_path="$rootfs/$u_path"
529+
530+ mkdir -p $root_u_path
531+ cp $auth_key "$root_u_path/authorized_keys"
532+ chroot $rootfs chown -R ${user}: "$u_path"
533+
534+ echo "Inserted SSH public key from $auth_key into /home/${user}/.ssh/authorized_keys"
535+ fi
536+ return 0
537+}
538+
539+write_sourceslist()
540+{
541+ # $1 => path to the rootfs
542+ # $2 => architecture we want to add
543+ # $3 => whether to use the multi-arch syntax or not
544+
545+ case $2 in
546+ amd64|i386)
547+ MIRROR=${MIRROR:-http://archive.ubuntu.com/ubuntu}
548+ SECURITY_MIRROR=${SECURITY_MIRROR:-http://security.ubuntu.com/ubuntu}
549+ ;;
550+ *)
551+ MIRROR=${MIRROR:-http://ports.ubuntu.com/ubuntu-ports}
552+ SECURITY_MIRROR=${SECURITY_MIRROR:-http://ports.ubuntu.com/ubuntu-ports}
553+ ;;
554+ esac
555+ if [ -n "$3" ]; then
556+ cat >> "$1/etc/apt/sources.list" << EOF
557+deb [arch=$2] $MIRROR ${release} main restricted universe multiverse
558+deb [arch=$2] $MIRROR ${release}-updates main restricted universe multiverse
559+deb [arch=$2] $SECURITY_MIRROR ${release}-security main restricted universe multiverse
560+EOF
561+ else
562+ cat >> "$1/etc/apt/sources.list" << EOF
563+deb $MIRROR ${release} main restricted universe multiverse
564+deb $MIRROR ${release}-updates main restricted universe multiverse
565+deb $SECURITY_MIRROR ${release}-security main restricted universe multiverse
566+EOF
567+ fi
568+}
569+
570+cleanup()
571+{
572+ rm -rf $cache/partial-$arch
573+ rm -rf $cache/rootfs-$arch
574+}
575+
576+suggest_flush()
577+{
578+ echo "Container upgrade failed. The container cache may be out of date,"
579+ echo "in which case flushing the case (see -F in the hep output) may help."
580+}
581+
582+download_ubuntu()
583+{
584+ cache=$1
585+ arch=$2
586+ release=$3
587+
588+ packages=vim,ssh
589+ echo "installing packages: $packages"
590+
591+ trap cleanup EXIT SIGHUP SIGINT SIGTERM
592+ # check the mini ubuntu was not already downloaded
593+ mkdir -p "$cache/partial-$arch"
594+ if [ $? -ne 0 ]; then
595+ echo "Failed to create '$cache/partial-$arch' directory"
596+ return 1
597+ fi
598+
599+ # download a mini ubuntu into a cache
600+ echo "Downloading ubuntu $release minimal ..."
601+ if [ -n "$(which qemu-debootstrap)" ]; then
602+ qemu-debootstrap --verbose --components=main,universe --arch=$arch --include=$packages $release $cache/partial-$arch $MIRROR
603+ else
604+ debootstrap --verbose --components=main,universe --arch=$arch --include=$packages $release $cache/partial-$arch $MIRROR
605+ fi
606+
607+ if [ $? -ne 0 ]; then
608+ echo "Failed to download the rootfs, aborting."
609+ return 1
610+ fi
611+
612+ # Serge isn't sure whether we should avoid doing this when
613+ # $release == `distro-info -d`
614+ echo "Installing updates"
615+ > $cache/partial-$arch/etc/apt/sources.list
616+ write_sourceslist $cache/partial-$arch/ $arch
617+
618+ chroot "$1/partial-${arch}" apt-get update
619+ if [ $? -ne 0 ]; then
620+ echo "Failed to update the apt cache"
621+ return 1
622+ fi
623+ cat > "$1/partial-${arch}"/usr/sbin/policy-rc.d << EOF
624+#!/bin/sh
625+exit 101
626+EOF
627+ chmod +x "$1/partial-${arch}"/usr/sbin/policy-rc.d
628+
629+ lxc-unshare -s MOUNT -- chroot "$1/partial-${arch}" apt-get dist-upgrade -y || { suggest_flush; false; }
630+ rm -f "$1/partial-${arch}"/usr/sbin/policy-rc.d
631+
632+ chroot "$1/partial-${arch}" apt-get clean
633+
634+ mv "$1/partial-$arch" "$1/rootfs-$arch"
635+ trap EXIT
636+ trap SIGINT
637+ trap SIGTERM
638+ trap SIGHUP
639+ echo "Download complete"
640+ return 0
641+}
642+
643+copy_ubuntu()
644+{
645+ cache=$1
646+ arch=$2
647+ rootfs=$3
648+
649+ # make a local copy of the miniubuntu
650+ echo "Copying rootfs to $rootfs ..."
651+ mkdir -p $rootfs
652+ rsync -a $cache/rootfs-$arch/ $rootfs/ || return 1
653+ return 0
654+}
655+
656+install_ubuntu()
657+{
658+ rootfs=$1
659+ release=$2
660+ flushcache=$3
661+ cache="/var/cache/lxc/$release"
662+ mkdir -p /var/lock/subsys/
663+
664+ (
665+ flock -x 200
666+ if [ $? -ne 0 ]; then
667+ echo "Cache repository is busy."
668+ return 1
669+ fi
670+
671+
672+ if [ $flushcache -eq 1 ]; then
673+ echo "Flushing cache..."
674+ rm -rf "$cache/partial-$arch"
675+ rm -rf "$cache/rootfs-$arch"
676+ fi
677+
678+ echo "Checking cache download in $cache/rootfs-$arch ... "
679+ if [ ! -e "$cache/rootfs-$arch" ]; then
680+ download_ubuntu $cache $arch $release
681+ if [ $? -ne 0 ]; then
682+ echo "Failed to download 'ubuntu $release base'"
683+ return 1
684+ fi
685+ fi
686+
687+ echo "Copy $cache/rootfs-$arch to $rootfs ... "
688+ copy_ubuntu $cache $arch $rootfs
689+ if [ $? -ne 0 ]; then
690+ echo "Failed to copy rootfs"
691+ return 1
692+ fi
693+
694+ return 0
695+
696+ ) 200>/var/lock/subsys/lxc
697+
698+ return $?
699+}
700+
701+copy_configuration()
702+{
703+ path=$1
704+ rootfs=$2
705+ name=$3
706+ arch=$4
707+ release=$5
708+
709+ if [ $arch = "i386" ]; then
710+ arch="i686"
711+ fi
712+
713+ ttydir=""
714+ if [ -f $rootfs/etc/init/container-detect.conf ]; then
715+ ttydir=" lxc"
716+ fi
717+
718+ # if there is exactly one veth network entry, make sure it has an
719+ # associated hwaddr.
720+ nics=`grep -e '^lxc\.network\.type[ \t]*=[ \t]*veth' $path/config | wc -l`
721+ if [ $nics -eq 1 ]; then
722+ grep -q "^lxc.network.hwaddr" $path/config || cat <<EOF >> $path/config
723+lxc.network.hwaddr = 00:16:3e:$(openssl rand -hex 3| sed 's/\(..\)/\1:/g; s/.$//')
724+EOF
725+ fi
726+
727+ grep -q "^lxc.rootfs" $path/config 2>/dev/null || echo "lxc.rootfs = $rootfs" >> $path/config
728+ cat <<EOF >> $path/config
729+lxc.utsname = $name
730+
731+lxc.devttydir =$ttydir
732+lxc.tty = 4
733+lxc.pts = 1024
734+lxc.mount = $path/fstab
735+lxc.arch = $arch
736+lxc.cap.drop = sys_module mac_admin mac_override
737+lxc.pivotdir = lxc_putold
738+
739+# uncomment the next line to run the container unconfined:
740+#lxc.aa_profile = unconfined
741+
742+lxc.cgroup.devices.deny = a
743+# Allow any mknod (but not using the node)
744+lxc.cgroup.devices.allow = c *:* m
745+lxc.cgroup.devices.allow = b *:* m
746+# /dev/null and zero
747+lxc.cgroup.devices.allow = c 1:3 rwm
748+lxc.cgroup.devices.allow = c 1:5 rwm
749+# consoles
750+lxc.cgroup.devices.allow = c 5:1 rwm
751+lxc.cgroup.devices.allow = c 5:0 rwm
752+#lxc.cgroup.devices.allow = c 4:0 rwm
753+#lxc.cgroup.devices.allow = c 4:1 rwm
754+# /dev/{,u}random
755+lxc.cgroup.devices.allow = c 1:9 rwm
756+lxc.cgroup.devices.allow = c 1:8 rwm
757+lxc.cgroup.devices.allow = c 136:* rwm
758+lxc.cgroup.devices.allow = c 5:2 rwm
759+# rtc
760+lxc.cgroup.devices.allow = c 254:0 rwm
761+#fuse
762+lxc.cgroup.devices.allow = c 10:229 rwm
763+#tun
764+lxc.cgroup.devices.allow = c 10:200 rwm
765+#full
766+lxc.cgroup.devices.allow = c 1:7 rwm
767+#hpet
768+lxc.cgroup.devices.allow = c 10:228 rwm
769+#kvm
770+lxc.cgroup.devices.allow = c 10:232 rwm
771+EOF
772+
773+ cat <<EOF > $path/fstab
774+proc proc proc nodev,noexec,nosuid 0 0
775+sysfs sys sysfs defaults 0 0
776+EOF
777+
778+ if [ $? -ne 0 ]; then
779+ echo "Failed to add configuration"
780+ return 1
781+ fi
782+
783+ return 0
784+}
785+
786+trim()
787+{
788+ rootfs=$1
789+ release=$2
790+
791+ # provide the lxc service
792+ cat <<EOF > $rootfs/etc/init/lxc.conf
793+# fake some events needed for correct startup other services
794+
795+description "Container Upstart"
796+
797+start on startup
798+
799+script
800+ rm -rf /var/run/*.pid
801+ rm -rf /var/run/network/*
802+ /sbin/initctl emit stopped JOB=udevtrigger --no-wait
803+ /sbin/initctl emit started JOB=udev --no-wait
804+end script
805+EOF
806+
807+ # fix buggus runlevel with sshd
808+ cat <<EOF > $rootfs/etc/init/ssh.conf
809+# ssh - OpenBSD Secure Shell server
810+#
811+# The OpenSSH server provides secure shell access to the system.
812+
813+description "OpenSSH server"
814+
815+start on filesystem
816+stop on runlevel [!2345]
817+
818+expect fork
819+respawn
820+respawn limit 10 5
821+umask 022
822+# replaces SSHD_OOM_ADJUST in /etc/default/ssh
823+oom never
824+
825+pre-start script
826+ test -x /usr/sbin/sshd || { stop; exit 0; }
827+ test -e /etc/ssh/sshd_not_to_be_run && { stop; exit 0; }
828+ test -c /dev/null || { stop; exit 0; }
829+
830+ mkdir -p -m0755 /var/run/sshd
831+end script
832+
833+# if you used to set SSHD_OPTS in /etc/default/ssh, you can change the
834+# 'exec' line here instead
835+exec /usr/sbin/sshd
836+EOF
837+
838+ cat <<EOF > $rootfs/etc/init/console.conf
839+# console - getty
840+#
841+# This service maintains a console on tty1 from the point the system is
842+# started until it is shut down again.
843+
844+start on stopped rc RUNLEVEL=[2345]
845+stop on runlevel [!2345]
846+
847+respawn
848+exec /sbin/getty -8 38400 /dev/console
849+EOF
850+
851+ cat <<EOF > $rootfs/lib/init/fstab
852+# /lib/init/fstab: cleared out for bare-bones lxc
853+EOF
854+
855+ # reconfigure some services
856+ if [ -z "$LANG" ]; then
857+ chroot $rootfs locale-gen en_US.UTF-8
858+ chroot $rootfs update-locale LANG=en_US.UTF-8
859+ else
860+ chroot $rootfs locale-gen $LANG
861+ chroot $rootfs update-locale LANG=$LANG
862+ fi
863+
864+ # remove pointless services in a container
865+ chroot $rootfs /usr/sbin/update-rc.d -f ondemand remove
866+
867+ chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls u*.conf); do mv $f $f.orig; done'
868+ chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls tty[2-9].conf); do mv $f $f.orig; done'
869+ chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls plymouth*.conf); do mv $f $f.orig; done'
870+ chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls hwclock*.conf); do mv $f $f.orig; done'
871+ chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls module*.conf); do mv $f $f.orig; done'
872+
873+ # if this isn't lucid, then we need to twiddle the network upstart bits :(
874+ if [ $release != "lucid" ]; then
875+ sed -i 's/^.*emission handled.*$/echo Emitting lo/' $rootfs/etc/network/if-up.d/upstart
876+ fi
877+}
878+
879+post_process()
880+{
881+ rootfs=$1
882+ release=$2
883+ trim_container=$3
884+
885+ if [ $trim_container -eq 1 ]; then
886+ trim $rootfs $release
887+ elif [ ! -f $rootfs/etc/init/container-detect.conf ]; then
888+ # Make sure we have a working resolv.conf
889+ cresolvonf="${rootfs}/etc/resolv.conf"
890+ mv $cresolvonf ${cresolvonf}.lxcbak
891+ cat /etc/resolv.conf > ${cresolvonf}
892+
893+ # for lucid, if not trimming, then add the ubuntu-virt
894+ # ppa and install lxcguest
895+ if [ $release = "lucid" ]; then
896+ chroot $rootfs apt-get update
897+ chroot $rootfs apt-get install --force-yes -y python-software-properties
898+ chroot $rootfs add-apt-repository ppa:ubuntu-virt/ppa
899+ fi
900+
901+ chroot $rootfs apt-get update
902+ chroot $rootfs apt-get install --force-yes -y lxcguest
903+
904+ # Restore old resolv.conf
905+ rm -f ${cresolvonf}
906+ mv ${cresolvonf}.lxcbak ${cresolvonf}
907+ fi
908+
909+ # If the container isn't running a native architecture, setup multiarch
910+ if [ -x "$(ls -1 ${rootfs}/usr/bin/qemu-*-static 2>/dev/null)" ]; then
911+ dpkg_version=$(chroot $rootfs dpkg-query -W -f='${Version}' dpkg)
912+ if chroot $rootfs dpkg --compare-versions $dpkg_version ge "1.16.2"; then
913+ chroot $rootfs dpkg --add-architecture ${hostarch}
914+ else
915+ mkdir -p ${rootfs}/etc/dpkg/dpkg.cfg.d
916+ echo "foreign-architecture ${hostarch}" > ${rootfs}/etc/dpkg/dpkg.cfg.d/lxc-multiarch
917+ fi
918+
919+ # Save existing value of MIRROR and SECURITY_MIRROR
920+ DEFAULT_MIRROR=$MIRROR
921+ DEFAULT_SECURITY_MIRROR=$SECURITY_MIRROR
922+
923+ # Write a new sources.list containing both native and multiarch entries
924+ > ${rootfs}/etc/apt/sources.list
925+ write_sourceslist $rootfs $arch "native"
926+
927+ MIRROR=$DEFAULT_MIRROR
928+ SECURITY_MIRROR=$DEFAULT_SECURITY_MIRROR
929+ write_sourceslist $rootfs $hostarch "multiarch"
930+
931+ # Finally update the lists and install upstart using the host architecture
932+ chroot $rootfs apt-get update
933+ chroot $rootfs apt-get install --force-yes -y --no-install-recommends upstart:${hostarch} mountall:${hostarch} iproute:${hostarch} isc-dhcp-client:${hostarch}
934+ fi
935+
936+ # rmdir /dev/shm for containers that have /run/shm
937+ # I'm afraid of doing rm -rf $rootfs/dev/shm, in case it did
938+ # get bind mounted to the host's /run/shm. So try to rmdir
939+ # it, and in case that fails move it out of the way.
940+ if [ ! -L $rootfs/dev/shm ] && [ -d $rootfs/run/shm ] && [ -e $rootfs/dev/shm ]; then
941+ mv $rootfs/dev/shm $rootfs/dev/shm.bak
942+ ln -s /run/shm $rootfs/dev/shm
943+ fi
944+}
945+
946+do_bindhome()
947+{
948+ rootfs=$1
949+ user=$2
950+
951+ # copy /etc/passwd, /etc/shadow, and /etc/group entries into container
952+ pwd=`getent passwd $user` || { echo "Failed to copy password entry for $user"; false; }
953+ echo $pwd >> $rootfs/etc/passwd
954+
955+ # make sure user's shell exists in the container
956+ shell=`echo $pwd | cut -d: -f 7`
957+ if [ ! -x $rootfs/$shell ]; then
958+ echo "shell $shell for user $user was not found in the container."
959+ pkg=`dpkg -S $(readlink -m $shell) | cut -d ':' -f1`
960+ echo "Installing $pkg"
961+ chroot $rootfs apt-get --force-yes -y install $pkg
962+ fi
963+
964+ shad=`getent shadow $user`
965+ echo "$shad" >> $rootfs/etc/shadow
966+
967+ # bind-mount the user's path into the container's /home
968+ h=`getent passwd $user | cut -d: -f 6`
969+ mkdir -p $rootfs/$h
970+
971+ # use relative path in container
972+ h2=${h#/}
973+ while [ ${h2:0:1} = "/" ]; do
974+ h2=${h2#/}
975+ done
976+ echo "$h $h2 none bind 0 0" >> $path/fstab
977+
978+ # Make sure the group exists in container
979+ grp=`echo $pwd | cut -d: -f 4` # group number for $user
980+ grpe=`getent group $grp` || return 0 # if host doesn't define grp, ignore in container
981+ chroot $rootfs getent group "$grpe" || echo "$grpe" >> $rootfs/etc/group
982+}
983+
984+usage()
985+{
986+ cat <<EOF
987+$1 -h|--help [-a|--arch] [-b|--bindhome <user>] [--trim] [-d|--debug]
988+ [-F | --flush-cache] [-r|--release <release>] [ -S | --auth-key <keyfile>]
989+release: the ubuntu release (e.g. precise): defaults to host release on ubuntu, otherwise uses latest LTS
990+trim: make a minimal (faster, but not upgrade-safe) container
991+bindhome: bind <user>'s home into the container
992+ The ubuntu user will not be created, and <user> will have
993+ sudo access.
994+arch: the container architecture (e.g. amd64): defaults to host arch
995+auth-key: SSH Public key file to inject into container
996+EOF
997+ return 0
998+}
999+
1000+options=$(getopt -o a:b:hp:r:xn:FS:d -l arch:,bindhome:,help,path:,release:,trim,name:,flush-cache,auth-key:,debug -- "$@")
1001+if [ $? -ne 0 ]; then
1002+ usage $(basename $0)
1003+ exit 1
1004+fi
1005+eval set -- "$options"
1006+
1007+release=precise # Default to the last Ubuntu LTS release for non-Ubuntu systems
1008+if [ -f /etc/lsb-release ]; then
1009+ . /etc/lsb-release
1010+ if [ "$DISTRIB_ID" = "Ubuntu" ]; then
1011+ release=$DISTRIB_CODENAME
1012+ fi
1013+fi
1014+
1015+bindhome=
1016+arch=$(arch)
1017+
1018+# Code taken from debootstrap
1019+if [ -x /usr/bin/dpkg ] && /usr/bin/dpkg --print-architecture >/dev/null 2>&1; then
1020+ arch=`/usr/bin/dpkg --print-architecture`
1021+elif type udpkg >/dev/null 2>&1 && udpkg --print-architecture >/dev/null 2>&1; then
1022+ arch=`/usr/bin/udpkg --print-architecture`
1023+else
1024+ arch=$(arch)
1025+ if [ "$arch" = "i686" ]; then
1026+ arch="i386"
1027+ elif [ "$arch" = "x86_64" ]; then
1028+ arch="amd64"
1029+ elif [ "$arch" = "armv7l" ]; then
1030+ arch="armel"
1031+ fi
1032+fi
1033+
1034+debug=0
1035+trim_container=0
1036+hostarch=$arch
1037+flushcache=0
1038+while true
1039+do
1040+ case "$1" in
1041+ -h|--help) usage $0 && exit 0;;
1042+ -p|--path) path=$2; shift 2;;
1043+ -n|--name) name=$2; shift 2;;
1044+ -F|--flush-cache) flushcache=1; shift 1;;
1045+ -r|--release) release=$2; shift 2;;
1046+ -b|--bindhome) bindhome=$2; shift 2;;
1047+ -a|--arch) arch=$2; shift 2;;
1048+ -x|--trim) trim_container=1; shift 1;;
1049+ -S|--auth-key) auth_key=$2; shift 2;;
1050+ -d|--debug) debug=1; shift 1;;
1051+ --) shift 1; break ;;
1052+ *) break ;;
1053+ esac
1054+done
1055+
1056+if [ $debug -eq 1 ]; then
1057+ set -x
1058+fi
1059+
1060+if [ -n "$bindhome" ]; then
1061+ pwd=`getent passwd $bindhome`
1062+ if [ $? -ne 0 ]; then
1063+ echo "Error: no password entry found for $bindhome"
1064+ exit 1
1065+ fi
1066+fi
1067+
1068+
1069+if [ "$arch" == "i686" ]; then
1070+ arch=i386
1071+fi
1072+
1073+if [ $hostarch = "i386" -a $arch = "amd64" ]; then
1074+ echo "can't create amd64 container on i386"
1075+ exit 1
1076+fi
1077+
1078+type debootstrap
1079+if [ $? -ne 0 ]; then
1080+ echo "'debootstrap' command is missing"
1081+ exit 1
1082+fi
1083+
1084+if [ -z "$path" ]; then
1085+ echo "'path' parameter is required"
1086+ exit 1
1087+fi
1088+
1089+if [ "$(id -u)" != "0" ]; then
1090+ echo "This script should be run as 'root'"
1091+ exit 1
1092+fi
1093+
1094+# detect rootfs
1095+config="$path/config"
1096+if grep -q '^lxc.rootfs' $config 2>/dev/null ; then
1097+ rootfs=`grep 'lxc.rootfs =' $config | awk -F= '{ print $2 }'`
1098+else
1099+ rootfs=$path/rootfs
1100+fi
1101+
1102+install_ubuntu $rootfs $release $flushcache
1103+if [ $? -ne 0 ]; then
1104+ echo "failed to install ubuntu $release"
1105+ exit 1
1106+fi
1107+
1108+configure_ubuntu $rootfs $name $release
1109+if [ $? -ne 0 ]; then
1110+ echo "failed to configure ubuntu $release for a container"
1111+ exit 1
1112+fi
1113+
1114+copy_configuration $path $rootfs $name $arch $release
1115+if [ $? -ne 0 ]; then
1116+ echo "failed write configuration file"
1117+ exit 1
1118+fi
1119+
1120+post_process $rootfs $release $trim_container
1121+
1122+if [ -n "$bindhome" ]; then
1123+ do_bindhome $rootfs $bindhome
1124+ finalize_user $bindhome
1125+else
1126+ finalize_user ubuntu
1127+fi
1128+
1129+echo ""
1130+echo "##"
1131+if [ -n "$bindhome" ]; then
1132+ echo "# Log in as user $bindhome"
1133+else
1134+ echo "# The default user is 'ubuntu' with password 'ubuntu'!"
1135+ echo "# Use the 'sudo' command to run tasks as root in the container."
1136+fi
1137+echo "##"
1138+echo ""
1139
1140=== added file 'debian/patches/0224-ubuntu-templates-devtmpfs'
1141--- debian/patches/0224-ubuntu-templates-devtmpfs 1970-01-01 00:00:00 +0000
1142+++ debian/patches/0224-ubuntu-templates-devtmpfs 2012-10-15 15:25:24 +0000
1143@@ -0,0 +1,30 @@
1144+Description: templates: mount devtmpfs in ubuntu containers
1145+ That way /dev/disk/ exists.
1146+Author: Serge Hallyn <serge.hallyn@ubuntu.com>
1147+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/1060404
1148+Forwarded: yes
1149+
1150+Index: lxc/templates/lxc-ubuntu-cloud.in
1151+===================================================================
1152+--- lxc.orig/templates/lxc-ubuntu-cloud.in 2012-10-04 11:59:00.784184000 -0500
1153++++ lxc/templates/lxc-ubuntu-cloud.in 2012-10-04 12:02:27.983278932 -0500
1154+@@ -94,6 +94,7 @@
1155+ cat <<EOF > $path/fstab
1156+ proc proc proc nodev,noexec,nosuid 0 0
1157+ sysfs sys sysfs defaults 0 0
1158++devtmpfs dev devtmpfs defaults 0 0
1159+ EOF
1160+
1161+ # rmdir /dev/shm for containers that have /run/shm
1162+Index: lxc/templates/lxc-ubuntu.in
1163+===================================================================
1164+--- lxc.orig/templates/lxc-ubuntu.in 2012-10-04 11:59:00.784184000 -0500
1165++++ lxc/templates/lxc-ubuntu.in 2012-10-04 12:02:21.439278789 -0500
1166+@@ -353,6 +353,7 @@
1167+ cat <<EOF > $path/fstab
1168+ proc proc proc nodev,noexec,nosuid 0 0
1169+ sysfs sys sysfs defaults 0 0
1170++devtmpfs dev devtmpfs defaults 0 0
1171+ EOF
1172+
1173+ if [ $? -ne 0 ]; then
1174
1175=== renamed file 'debian/patches/0224-ubuntu-templates-devtmpfs' => 'debian/patches/0224-ubuntu-templates-devtmpfs.moved'

Subscribers

People subscribed via source and target branches