Commit adca8543 by Serge Hallyn Committed by Daniel Lezcano

Simplify the Ubuntu template a bit

- Update list of extra packages for debootstrap to only include vim and ssh. The others were only relevant when we were still using the minbase variant. (LP: #996839) - Drop any hardcoded Ubuntu version check and replace by feature checks instead. - Format lxc-ubuntu to consistently use 4-spaces indent instead of mixed spaces/tabs. - Update default /etc/network/interfaces to include the header. - Update default /etc/hosts to match that of a regular Ubuntu system. - Drop support for end-of-life releases (gutsy on sparc). - Make sure /etc/resolv.conf is valid before running any apt command. - Update template help message for release and arch parameters. - Switch default Ubuntu version from lucid to precise. Signed-off-by: 's avatarStéphane Graber <stgraber@ubuntu.com> Signed-off-by: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com> Signed-off-by: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com>
parent f876c223
...@@ -38,6 +38,10 @@ configure_ubuntu() ...@@ -38,6 +38,10 @@ configure_ubuntu()
# configure the network using the dhcp # configure the network using the dhcp
cat <<EOF > $rootfs/etc/network/interfaces cat <<EOF > $rootfs/etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo auto lo
iface lo inet loopback iface lo inet loopback
...@@ -51,10 +55,18 @@ $hostname ...@@ -51,10 +55,18 @@ $hostname
EOF EOF
# set minimal hosts # set minimal hosts
cat <<EOF > $rootfs/etc/hosts cat <<EOF > $rootfs/etc/hosts
127.0.0.1 localhost $hostname 127.0.0.1 localhost
127.0.1.1 $hostname
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
EOF EOF
if [ "$release" != "precise" ] && [ "$release" != "quantal" ]; then if [ ! -f $rootfs/etc/init/container-detect.conf ]; then
# suppress log level output for udev # suppress log level output for udev
sed -i "s/=\"err\"/=0/" $rootfs/etc/udev/udev.conf sed -i "s/=\"err\"/=0/" $rootfs/etc/udev/udev.conf
...@@ -78,7 +90,9 @@ finalize_user() ...@@ -78,7 +90,9 @@ finalize_user()
{ {
user=$1 user=$1
if [ "$release" = "precise" ] || [ "$release" = "quantal" ]; then sudo_version=$(chroot $rootfs dpkg-query -W -f='${Version}' sudo)
if chroot $rootfs dpkg --compare-versions $sudo_version gt "1.8.3p1-1"; then
groups="sudo" groups="sudo"
else else
groups="sudo admin" groups="sudo admin"
...@@ -112,18 +126,6 @@ write_sourceslist() ...@@ -112,18 +126,6 @@ write_sourceslist()
MIRROR=${MIRROR:-http://archive.ubuntu.com/ubuntu} MIRROR=${MIRROR:-http://archive.ubuntu.com/ubuntu}
SECURITY_MIRROR=${SECURITY_MIRROR:-http://security.ubuntu.com/ubuntu} SECURITY_MIRROR=${SECURITY_MIRROR:-http://security.ubuntu.com/ubuntu}
;; ;;
sparc)
case $SUITE in
gutsy)
MIRROR=${MIRROR:-http://archive.ubuntu.com/ubuntu}
SECURITY_MIRROR=${SECURITY_MIRRORMIRROR:-http://security.ubuntu.com/ubuntu}
;;
*)
MIRROR=${MIRROR:-http://ports.ubuntu.com/ubuntu-ports}
SECURITY_MIRROR=${SECURITY_MIRROR:-http://ports.ubuntu.com/ubuntu-ports}
;;
esac
;;
*) *)
MIRROR=${MIRROR:-http://ports.ubuntu.com/ubuntu-ports} MIRROR=${MIRROR:-http://ports.ubuntu.com/ubuntu-ports}
SECURITY_MIRROR=${SECURITY_MIRROR:-http://ports.ubuntu.com/ubuntu-ports} SECURITY_MIRROR=${SECURITY_MIRROR:-http://ports.ubuntu.com/ubuntu-ports}
...@@ -150,13 +152,7 @@ download_ubuntu() ...@@ -150,13 +152,7 @@ download_ubuntu()
arch=$2 arch=$2
release=$3 release=$3
if [ $release = "lucid" ]; then packages=vim,ssh
packages=dialog,apt,apt-utils,resolvconf,iproute,inetutils-ping,vim,dhcp3-client,ssh,lsb-release,gnupg
elif [ $release = "natty" ]; then
packages=dialog,apt,apt-utils,resolvconf,iproute,inetutils-ping,vim,isc-dhcp-client,isc-dhcp-common,ssh,lsb-release,gnupg,netbase
else
packages=dialog,apt,apt-utils,iproute,inetutils-ping,vim,isc-dhcp-client,isc-dhcp-common,ssh,lsb-release,gnupg,netbase,ubuntu-keyring
fi
echo "installing packages: $packages" echo "installing packages: $packages"
# check the mini ubuntu was not already downloaded # check the mini ubuntu was not already downloaded
...@@ -258,39 +254,40 @@ install_ubuntu() ...@@ -258,39 +254,40 @@ install_ubuntu()
flushcache=$3 flushcache=$3
cache="/var/cache/lxc/$release" cache="/var/cache/lxc/$release"
mkdir -p /var/lock/subsys/ mkdir -p /var/lock/subsys/
( (
flock -n -x 200 flock -n -x 200
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Cache repository is busy." echo "Cache repository is busy."
return 1 return 1
fi fi
if [ $flushcache -eq 1 ]; then if [ $flushcache -eq 1 ]; then
echo "Flushing cache..." echo "Flushing cache..."
rm -rf "$cache/partial-$arch" rm -rf "$cache/partial-$arch"
rm -rf "$cache/rootfs-$arch" rm -rf "$cache/rootfs-$arch"
fi fi
echo "Checking cache download in $cache/rootfs-$arch ... " echo "Checking cache download in $cache/rootfs-$arch ... "
if [ ! -e "$cache/rootfs-$arch" ]; then if [ ! -e "$cache/rootfs-$arch" ]; then
download_ubuntu $cache $arch $release download_ubuntu $cache $arch $release
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to download 'ubuntu $release base'" echo "Failed to download 'ubuntu $release base'"
return 1 return 1
fi fi
fi fi
echo "Copy $cache/rootfs-$arch to $rootfs ... " echo "Copy $cache/rootfs-$arch to $rootfs ... "
copy_ubuntu $cache $arch $rootfs copy_ubuntu $cache $arch $rootfs
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to copy rootfs" echo "Failed to copy rootfs"
return 1 return 1
fi fi
return 0 return 0
) 200>/var/lock/subsys/lxc ) 200>/var/lock/subsys/lxc
return $? return $?
} }
...@@ -308,7 +305,7 @@ copy_configuration() ...@@ -308,7 +305,7 @@ copy_configuration()
fi fi
ttydir="" ttydir=""
if [ $release = "precise" ] || [ $release = "quantal" ]; then if [ -f $rootfs/etc/init/container-detect.conf ]; then
ttydir=" lxc" ttydir=" lxc"
fi fi
...@@ -369,8 +366,8 @@ sysfs sys sysfs defaults 0 0 ...@@ -369,8 +366,8 @@ sysfs sys sysfs defaults 0 0
EOF EOF
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to add configuration" echo "Failed to add configuration"
return 1 return 1
fi fi
return 0 return 0
...@@ -447,11 +444,11 @@ EOF ...@@ -447,11 +444,11 @@ EOF
# reconfigure some services # reconfigure some services
if [ -z "$LANG" ]; then if [ -z "$LANG" ]; then
chroot $rootfs locale-gen en_US.UTF-8 chroot $rootfs locale-gen en_US.UTF-8
chroot $rootfs update-locale LANG=en_US.UTF-8 chroot $rootfs update-locale LANG=en_US.UTF-8
else else
chroot $rootfs locale-gen $LANG chroot $rootfs locale-gen $LANG
chroot $rootfs update-locale LANG=$LANG chroot $rootfs update-locale LANG=$LANG
fi fi
# remove pointless services in a container # remove pointless services in a container
...@@ -477,21 +474,25 @@ post_process() ...@@ -477,21 +474,25 @@ post_process()
if [ $trim_container -eq 1 ]; then if [ $trim_container -eq 1 ]; then
trim $rootfs $release trim $rootfs $release
elif [ $release = "lucid" -o $release = "natty" \ elif [ ! -f $rootfs/etc/init/container-detect.conf ]; then
-o $release = "oneiric" ]; then # Make sure we have a working resolv.conf
cresolvonf="${rootfs}/etc/resolv.conf"
mv $cresolvonf ${cresolvonf}.lxcbak
cat /etc/resolv.conf > ${cresolvonf}
# for lucid, if not trimming, then add the ubuntu-virt # for lucid, if not trimming, then add the ubuntu-virt
# ppa and install lxcguest # ppa and install lxcguest
if [ $release = "lucid" ]; then if [ $release = "lucid" ]; then
chroot $rootfs apt-get install --force-yes -y python-software-properties chroot $rootfs apt-get install --force-yes -y python-software-properties
chroot $rootfs add-apt-repository ppa:ubuntu-virt/ppa chroot $rootfs add-apt-repository ppa:ubuntu-virt/ppa
fi fi
cresolvonf="${rootfs}/etc/resolv.conf"
mv $cresolvonf ${cresolvonf}.lxcbak
cat /etc/resolv.conf > ${cresolvonf}
chroot $rootfs apt-get update chroot $rootfs apt-get update
chroot $rootfs apt-get install --force-yes -y lxcguest chroot $rootfs apt-get install --force-yes -y lxcguest
rm -f ${cresolvonf}
mv ${cresolvonf}.lxcbak ${cresolvonf} # Restore old resolv.conf
rm -f ${cresolvonf}
mv ${cresolvonf}.lxcbak ${cresolvonf}
fi fi
# If the container isn't running a native architecture, setup multiarch # If the container isn't running a native architecture, setup multiarch
...@@ -516,11 +517,11 @@ post_process() ...@@ -516,11 +517,11 @@ post_process()
chroot $rootfs apt-get install --force-yes -y --no-install-recommends upstart:${hostarch} mountall:${hostarch} iproute:${hostarch} isc-dhcp-client:${hostarch} chroot $rootfs apt-get install --force-yes -y --no-install-recommends upstart:${hostarch} mountall:${hostarch} iproute:${hostarch} isc-dhcp-client:${hostarch}
fi fi
# rmdir /dev/shm in precise and quantal containers. # rmdir /dev/shm for containers that have /run/shm
# I'm afraid of doing rm -rf $rootfs/dev/shm, in case it did # I'm afraid of doing rm -rf $rootfs/dev/shm, in case it did
# get bind mounted to the host's /run/shm. So try to rmdir # get bind mounted to the host's /run/shm. So try to rmdir
# it, and in case that fails move it out of the way. # it, and in case that fails move it out of the way.
if [ $release = "precise" ] || [ $release = "quantal" ]; then if [ -d $rootfs/run/shm ]; then
[ -d "$rootfs/dev/shm" ] && rmdir $rootfs/dev/shm [ -d "$rootfs/dev/shm" ] && rmdir $rootfs/dev/shm
[ -e "$rootfs/dev/shm" ] && mv $rootfs/dev/shm $rootfs/dev/shm.bak [ -e "$rootfs/dev/shm" ] && mv $rootfs/dev/shm $rootfs/dev/shm.bak
ln -s /run/shm $rootfs/dev/shm ln -s /run/shm $rootfs/dev/shm
...@@ -551,11 +552,12 @@ do_bindhome() ...@@ -551,11 +552,12 @@ do_bindhome()
# bind-mount the user's path into the container's /home # bind-mount the user's path into the container's /home
h=`getent passwd $user | cut -d: -f 6` h=`getent passwd $user | cut -d: -f 6`
mkdir -p $rootfs/$h mkdir -p $rootfs/$h
# use relative path in container
h2=${h#/} # use relative path in container
while [ ${h2:0:1} = "/" ]; do h2=${h#/}
h2=${h2#/} while [ ${h2:0:1} = "/" ]; do
done h2=${h2#/}
done
echo "$h $h2 none bind 0 0" >> $path/fstab echo "$h $h2 none bind 0 0" >> $path/fstab
# Make sure the group exists in container # Make sure the group exists in container
...@@ -569,12 +571,12 @@ usage() ...@@ -569,12 +571,12 @@ usage()
cat <<EOF cat <<EOF
$1 -h|--help [-a|--arch] [-b|--bindhome <user>] [--trim] [-d|--debug] $1 -h|--help [-a|--arch] [-b|--bindhome <user>] [--trim] [-d|--debug]
[-F | --flush-cache] [-r|--release <release>] [ -S | --auth-key <keyfile>] [-F | --flush-cache] [-r|--release <release>] [ -S | --auth-key <keyfile>]
release: lucid | natty | oneiric | precise | quantal release: the ubuntu release (e.g. precise): defaults to host release on ubuntu, otherwise uses latest LTS
trim: make a minimal (faster, but not upgrade-safe) container trim: make a minimal (faster, but not upgrade-safe) container
bindhome: bind <user>'s home into the container bindhome: bind <user>'s home into the container
The ubuntu user will not be created, and <user> will have The ubuntu user will not be created, and <user> will have
sudo access. sudo access.
arch: amd64 or i386: defaults to host arch arch: the container architecture (e.g. amd64): defaults to host arch
auth-key: SSH Public key file to inject into container auth-key: SSH Public key file to inject into container
EOF EOF
return 0 return 0
...@@ -587,14 +589,12 @@ if [ $? -ne 0 ]; then ...@@ -587,14 +589,12 @@ if [ $? -ne 0 ]; then
fi fi
eval set -- "$options" eval set -- "$options"
release=lucid release=precise # Default to the last Ubuntu LTS release for non-Ubuntu systems
if [ -f /etc/lsb-release ]; then if [ -f /etc/lsb-release ]; then
. /etc/lsb-release . /etc/lsb-release
case "$DISTRIB_CODENAME" in if [ "$DISTRIB_ID" = "Ubuntu" ]; then
lucid|natty|oneiric|precise|quantal) release=$DISTRIB_CODENAME
release=$DISTRIB_CODENAME fi
;;
esac
fi fi
bindhome= bindhome=
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment