password=$5
# configure the network using the dhcp
- cat <<EOF > $rootfs/etc/network/interfaces
+ if chroot $rootfs which netplan >/dev/null 2>&1; then
+ cat <<EOF > $rootfs/etc/netplan/10-lxc.yaml
+network:
+ ethernets:
+ eth0: {dhcp4: true}
+ version: 2
+EOF
+ else
+ 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).
auto eth0
iface eth0 inet dhcp
EOF
+ fi
# set the hostname
cat <<EOF > $rootfs/etc/hostname
EOF
chmod +x $rootfs/usr/sbin/policy-rc.d
+ if [ -f "$rootfs/etc/init/ssh.conf" ]; then
+ mv "$rootfs/etc/init/ssh.conf" "$rootfs/etc/init/ssh.conf.disabled"
+ fi
+
rm -f $rootfs/etc/ssh/ssh_host_*key*
- mv $rootfs/etc/init/ssh.conf $rootfs/etc/init/ssh.conf.disabled
+
DPKG_MAINTSCRIPT_PACKAGE=openssh DPKG_MAINTSCRIPT_NAME=postinst chroot $rootfs /var/lib/dpkg/info/openssh-server.postinst configure
- mv $rootfs/etc/init/ssh.conf.disabled $rootfs/etc/init/ssh.conf
sed -i "s/root@$(hostname)/root@$hostname/g" $rootfs/etc/ssh/ssh_host_*.pub
+ if [ -f "$rootfs/etc/init/ssh.conf.disabled" ]; then
+ mv "$rootfs/etc/init/ssh.conf.disabled" "$rootfs/etc/init/ssh.conf"
+ fi
+
rm -f $rootfs/usr/sbin/policy-rc.d
fi
arch=$2
release=$3
- packages_template=${packages_template:-"ssh,vim"}
+ case $2 in
+ amd64|i386)
+ MIRROR=${MIRROR:-http://archive.ubuntu.com/ubuntu}
+ SECURITY_MIRROR=${SECURITY_MIRROR:-http://security.ubuntu.com/ubuntu}
+ ;;
+ *)
+ MIRROR=${MIRROR:-http://ports.ubuntu.com/ubuntu-ports}
+ SECURITY_MIRROR=${SECURITY_MIRROR:-http://ports.ubuntu.com/ubuntu-ports}
+ ;;
+ esac
+
+ packages_template=${packages_template:-"apt-transport-https,ssh,vim"}
+ debootstrap_parameters=
# Try to guess a list of langpacks to install
langpacks="language-pack-en"
fi
packages_template="${packages_template},$(echo $langpacks | sed 's/ /,/g')"
- if [ $variant == 'minbase' ]; then
- packages_template="${packages_template},sudo,ifupdown,isc-dhcp-client"
+ if [ -n "$variant" ]; then
+ debootstrap_parameters="$debootstrap_parameters --variant=$variant"
+ fi
+ if [ "$variant" = 'minbase' ]; then
+ packages_template="${packages_template},sudo"
+ # Newer releases use netplan, EOL releases not supported
+ case $release in
+ trusty|xenial|zesty)
+ packages_template="${packages_template},ifupdown,isc-dhcp-client"
+ ;;
+ esac
fi
echo "Installing packages in template: ${packages_template}"
# download a mini ubuntu into a cache
echo "Downloading ubuntu $release minimal ..."
if [ -n "$(which qemu-debootstrap)" ]; then
- qemu-debootstrap --verbose $(if [ -n "$variant" ]; then echo --variant="$variant"; fi) --components=main,universe --arch=$arch --include=${packages_template} $release $cache/partial-$arch $MIRROR
+ qemu-debootstrap --verbose $debootstrap_parameters --components=main,universe --arch=$arch --include=${packages_template} $release $cache/partial-$arch $MIRROR
else
- debootstrap --verbose $(if [ -n "$variant" ]; then echo --variant="$variant"; fi) --components=main,universe --arch=$arch --include=${packages_template} $release $cache/partial-$arch $MIRROR
+ debootstrap --verbose $debootstrap_parameters --components=main,universe --arch=$arch --include=${packages_template} $release $cache/partial-$arch $MIRROR
fi
if [ $? -ne 0 ]; then
EOF
chmod +x "$1/partial-${arch}"/usr/sbin/policy-rc.d
- lxc-unshare -s MOUNT -- chroot "$1/partial-${arch}" apt-get dist-upgrade -y || { suggest_flush; false; }
+ (
+ cat << EOF
+ mount -t proc proc "${1}/partial-${arch}/proc"
+ chroot "${1}/partial-${arch}" apt-get dist-upgrade -y
+EOF
+ ) | lxc-unshare -s MOUNT -- sh -eu || (suggest_flush; false)
+
rm -f "$1/partial-${arch}"/usr/sbin/policy-rc.d
chroot "$1/partial-${arch}" apt-get clean
btrfs subvolume snapshot $cache/rootfs-$arch $realrootfs || return 1
[ "$rootfs" = "$realrootfs" ] || mount --bind $realrootfs $rootfs || return 1
else
- rsync -Ha $cache/rootfs-$arch/ $rootfs/ || return 1
+ rsync -SHaAX $cache/rootfs-$arch/ $rootfs/ || return 1
fi
return 0
}
# if there is exactly one veth network entry, make sure it has an
# associated hwaddr.
- nics=`grep -e '^lxc\.network\.type[ \t]*=[ \t]*veth' $path/config | wc -l`
+ nics=`grep -e '^lxc\.net\.0\.type[ \t]*=[ \t]*veth' $path/config | wc -l`
if [ $nics -eq 1 ]; then
- grep -q "^lxc.network.hwaddr" $path/config || sed -i -e "/^lxc\.network\.type[ \t]*=[ \t]*veth/a lxc.network.hwaddr = 00:16:3e:$(openssl rand -hex 3| sed 's/\(..\)/\1:/g; s/.$//')" $path/config
+ grep -q "^lxc.net.0.hwaddr" $path/config || sed -i -e "/^lxc\.net\.0\.type[ \t]*=[ \t]*veth/a lxc.net.0.hwaddr = 00:16:3e:$(openssl rand -hex 3| sed 's/\(..\)/\1:/g; s/.$//')" $path/config
fi
# Generate the configuration file
## Relocate all the network config entries
- sed -i -e "/lxc.network/{w ${path}/config-network" -e "d}" $path/config
+ sed -i -e "/lxc.net.0/{w ${path}/config-network" -e "d}" $path/config
## Relocate any other config entries
sed -i -e "/lxc./{w ${path}/config-auto" -e "d}" $path/config
echo "" >> $path/config
echo "# Container specific configuration" >> $path/config
[ -e "$path/config-auto" ] && cat $path/config-auto >> $path/config && rm $path/config-auto
- grep -q "^lxc.rootfs" $path/config 2>/dev/null || echo "lxc.rootfs = $rootfs" >> $path/config
+ grep -q "^lxc.rootfs.path" $path/config 2>/dev/null || echo "lxc.rootfs.path = $rootfs" >> $path/config
cat <<EOF >> $path/config
-lxc.utsname = $name
+lxc.uts.name = $name
lxc.arch = $arch
EOF
[-F | --flush-cache] [-r|--release <release>] [-v|--variant] [ -S | --auth-key <keyfile>]
[--rootfs <rootfs>] [--packages <packages>] [-u|--user <user>] [--password <password>]
[--mirror <url>] [--security-mirror <url>]
-release: the ubuntu release (e.g. precise): defaults to host release on ubuntu, otherwise uses latest LTS
+release: the ubuntu release (e.g. xenial): defaults to host release on ubuntu, otherwise uses latest LTS
variant: debootstrap variant to use (see debootstrap(8))
bindhome: bind <user>'s home into the container
The ubuntu user will not be created, and <user> will have
fi
eval set -- "$options"
-release=precise # Default to the last Ubuntu LTS release for non-Ubuntu systems
+release=xenial # Default to the last Ubuntu LTS release for non-Ubuntu systems
if [ -f /etc/lsb-release ]; then
. /etc/lsb-release
if [ "$DISTRIB_ID" = "Ubuntu" ]; then
config="$path/config"
# if $rootfs exists here, it was passed in with --rootfs
if [ -z "$rootfs" ]; then
- if grep -q '^lxc.rootfs' $config 2>/dev/null ; then
- rootfs=$(awk -F= '/^lxc.rootfs =/{ print $2 }' $config)
+ if grep -q '^lxc.rootfs.path' $config 2>/dev/null ; then
+ rootfs=$(awk -F= '/^lxc.rootfs.path =/{ print $2 }' $config)
else
rootfs=$path/rootfs
fi