4 # template script for generating ubuntu container for LXC
6 # This script consolidates and extends the existing lxc ubuntu scripts
9 # Copyright © 2011 Serge Hallyn <serge.hallyn@canonical.com>
10 # Copyright © 2010 Wilhelm Meier
11 # Author: Wilhelm Meier <wilhelm.meier@fh-kl.de>
13 # This library is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU Lesser General Public
15 # License as published by the Free Software Foundation; either
16 # version 2.1 of the License, or (at your option) any later version.
18 # This library is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 # Lesser General Public License for more details.
23 # You should have received a copy of the GNU Lesser General Public
24 # License along with this library; if not, write to the Free Software
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 # Detect use under userns (unsupported)
29 [ "$arg" = "--" ] && break
30 if [ "$arg" = "--mapped-uid" -o "$arg" = "--mapped-gid" ]; then
31 echo "This template can't be used for unprivileged containers." 1>&2
32 echo "You may want to try the \"download\" template instead." 1>&2
37 # Make sure the usual locations are in PATH
38 export PATH
=$PATH:/usr
/sbin
:/usr
/bin
:/sbin
:/bin
42 LOCALSTATEDIR
="@LOCALSTATEDIR@"
43 LXC_TEMPLATE_CONFIG
="@LXCTEMPLATECONFIG@"
44 # Allows the lxc-cache directory to be set by environment variable
45 LXC_CACHE_PATH
=${LXC_CACHE_PATH:-"$LOCALSTATEDIR/cache/lxc"}
47 if [ -r /etc
/default
/lxc
]; then
51 # Check if given path is in a btrfs partition
54 [ -e $1 -a $
(stat
-f -c '%T' $1) = "btrfs" ]
57 # Check if given path is the root of a btrfs subvolume
60 [ -d $1 -a $
(stat
-f -c '%T' $1) = "btrfs" -a $
(stat
-c '%i' $1) -eq 256 ]
66 [ -d $path ] && return 0
67 mkdir
-p $
(dirname $path)
68 if which btrfs
>/dev
/null
2>&1 && is_btrfs $
(dirname $path); then
69 btrfs subvolume create
$path
78 [ -d $path ] ||
return 0
79 if which btrfs
>/dev
/null
2>&1 && is_btrfs_subvolume
$path; then
80 btrfs subvolume delete
$path
94 # configure the network using the dhcp
95 cat <<EOF > $rootfs/etc/network/interfaces
96 # This file describes the network interfaces available on your system
97 # and how to activate them. For more information, see interfaces(5).
99 # The loopback network interface
101 iface lo inet loopback
108 cat <<EOF > $rootfs/etc/hostname
112 cat <<EOF > $rootfs/etc/hosts
116 # The following lines are desirable for IPv6 capable hosts
117 ::1 ip6-localhost ip6-loopback
119 ff00::0 ip6-mcastprefix
121 ff02::2 ip6-allrouters
124 if [ ! -f $rootfs/etc
/init
/container-detect.conf
]; then
125 # suppress log level output for udev
126 sed -i "s/=\"err\"/=0/" $rootfs/etc
/udev
/udev.conf
128 # remove jobs for consoles 5 and 6 since we only create 4 consoles in
130 rm -f $rootfs/etc
/init
/tty
{5,6}.conf
133 if [ -z "$bindhome" ]; then
134 chroot
$rootfs useradd
--create-home -s /bin
/bash
$user
135 echo "$user:$password" | chroot
$rootfs chpasswd
138 # make sure we have the current locale defined in the container
139 if [ -z "$LANG" ] ||
echo $LANG |
grep -E -q "^C(\..+)*$"; then
140 chroot
$rootfs locale-gen en_US.UTF-8 || true
141 chroot
$rootfs update-locale LANG
=en_US.UTF-8 || true
143 chroot
$rootfs locale-gen
$LANG || true
144 chroot
$rootfs update-locale LANG
=$LANG || true
147 # generate new SSH keys
148 if [ -x $rootfs/var
/lib
/dpkg
/info
/openssh-server.postinst
]; then
149 cat > $rootfs/usr
/sbin
/policy-rc.d
<< EOF
153 chmod +x
$rootfs/usr
/sbin
/policy-rc.d
155 rm -f $rootfs/etc
/ssh
/ssh_host_
*key
*
156 mv $rootfs/etc
/init
/ssh.conf
$rootfs/etc
/init
/ssh.conf.disabled
157 DPKG_MAINTSCRIPT_PACKAGE
=openssh DPKG_MAINTSCRIPT_NAME
=postinst chroot
$rootfs /var
/lib
/dpkg
/info
/openssh-server.postinst configure
158 mv $rootfs/etc
/init
/ssh.conf.disabled
$rootfs/etc
/init
/ssh.conf
160 sed -i "s/root@$(hostname)/root@$hostname/g" $rootfs/etc
/ssh
/ssh_host_
*.pub
162 rm -f $rootfs/usr
/sbin
/policy-rc.d
168 # finish setting up the user in the container by injecting ssh key and
169 # adding sudo group membership.
170 # passed-in user is either 'ubuntu' or the user to bind in from host.
175 sudo_version
=$
(chroot
$rootfs dpkg-query
-W -f='${Version}' sudo
)
177 if chroot
$rootfs dpkg
--compare-versions $sudo_version gt
"1.8.3p1-1"; then
183 for group
in $groups; do
184 chroot
$rootfs groupadd
--system $group >/dev
/null
2>&1 || true
185 chroot
$rootfs adduser
${user} $group >/dev
/null
2>&1 || true
188 if [ -n "$auth_key" -a -f "$auth_key" ]; then
189 u_path
="/home/${user}/.ssh"
190 root_u_path
="$rootfs/$u_path"
191 mkdir
-p $root_u_path
192 cp $auth_key "$root_u_path/authorized_keys"
193 chroot
$rootfs chown
-R ${user}: "$u_path"
195 echo "Inserted SSH public key from $auth_key into /home/${user}/.ssh/authorized_keys"
200 # A function to try and autodetect squid-deb-proxy servers on the local network
201 # if either the squid-deb-proxy-client package is installed on the host or
202 # a parent container set the 50squid-deb-proxy-client file.
203 squid_deb_proxy_autodetect
()
205 local apt_discover
=/usr
/share
/squid-deb-proxy-client
/apt-avahi-discover
206 local proxy_file
=/etc
/apt
/apt.conf.d
/50squid-deb-proxy-client
207 squid_proxy_line
= # That's a global :/
209 # Maybe the host is aware of a squid-deb-proxy?
210 if [ -f $apt_discover ]; then
211 echo -n "Discovering squid-deb-proxy..."
212 squid_proxy_line
=$
($apt_discover)
213 if [ -n "$squid_proxy_line" ]; then
214 echo "found squid-deb-proxy: $squid_proxy_line"
216 echo "no squid-deb-proxy found"
220 # Are we in a nested container, and the parent already knows of a proxy?
221 if [ -f $proxy_file ]; then
222 # Extract the squid URL from the file (whatever is between "")
223 squid_proxy_line
=`cat $proxy_file | sed "s/.*\"\(.*\)\".*/\1/"`
228 # Choose proxies for container
229 # http_proxy will be used by debootstrap on the host.
230 # APT_PROXY will be used to set /etc/apt/apt.conf.d/70proxy in the container.
232 choose_container_proxy
()
237 if [ -z "$HTTP_PROXY" ]; then
240 case "$HTTP_PROXY" in
242 squid_deb_proxy_autodetect
243 if [ -n "$squid_proxy_line" ]; then
244 APT_PROXY
=$squid_proxy_line
245 export http_proxy
=$squid_proxy_line
251 RES
=`apt-config shell APT_PROXY Acquire::http::Proxy`
253 [ -z "$APT_PROXY" ] ||
export http_proxy
=$APT_PROXY
256 APT_PROXY
=$HTTP_PROXY
257 export http_proxy
=$HTTP_PROXY
264 # $1 => path to the partial cache or the rootfs
265 # $2 => architecture we want to add
266 # $3 => whether to use the multi-arch syntax or not
268 if [ -n "$APT_PROXY" ]; then
269 mkdir
-p $1/etc
/apt
/apt.conf.d
270 cat > $1/etc
/apt
/apt.conf.d
/70proxy
<< EOF
271 Acquire::http::Proxy "$APT_PROXY" ;
277 MIRROR
=${MIRROR:-http://archive.ubuntu.com/ubuntu}
278 SECURITY_MIRROR
=${SECURITY_MIRROR:-http://security.ubuntu.com/ubuntu}
281 MIRROR
=${MIRROR:-http://ports.ubuntu.com/ubuntu-ports}
282 SECURITY_MIRROR
=${SECURITY_MIRROR:-http://ports.ubuntu.com/ubuntu-ports}
286 cat >> "$1/etc/apt/sources.list" << EOF
287 deb [arch=$2] $MIRROR ${release} main restricted universe multiverse
288 deb [arch=$2] $MIRROR ${release}-updates main restricted universe multiverse
289 deb [arch=$2] $SECURITY_MIRROR ${release}-security main restricted universe multiverse
292 cat >> "$1/etc/apt/sources.list" << EOF
293 deb $MIRROR ${release} main restricted universe multiverse
294 deb $MIRROR ${release}-updates main restricted universe multiverse
295 deb $SECURITY_MIRROR ${release}-security main restricted universe multiverse
307 chroot
$rootfs apt-get update
310 if [ -n "${packages}" ]
312 chroot
$rootfs apt-get
install --force-yes -y --no-install-recommends ${packages}
318 try_rmsubvolume
$cache/partial-
$arch
319 try_rmsubvolume
$cache/rootfs-
$arch
324 echo "Container upgrade failed. The container cache may be out of date,"
325 echo "in which case flushing the cache (see -F in the help output) may help."
336 MIRROR
=${MIRROR:-http://archive.ubuntu.com/ubuntu}
337 SECURITY_MIRROR
=${SECURITY_MIRROR:-http://security.ubuntu.com/ubuntu}
340 MIRROR
=${MIRROR:-http://ports.ubuntu.com/ubuntu-ports}
341 SECURITY_MIRROR
=${SECURITY_MIRROR:-http://ports.ubuntu.com/ubuntu-ports}
345 packages_template
=${packages_template:-"apt-transport-https,ssh,vim"}
346 debootstrap_parameters
=
348 # Try to guess a list of langpacks to install
349 langpacks
="language-pack-en"
351 if which dpkg
>/dev
/null
2>&1; then
352 langpacks
=`(echo $langpacks &&
353 dpkg -l | grep -E "^ii language-pack-[a-z]* " |
354 cut -d ' ' -f3) | sort -u`
356 packages_template
="${packages_template},$(echo $langpacks | sed 's/ /,/g')"
358 if [ -n "$variant" ]; then
359 debootstrap_parameters
="$debootstrap_parameters --variant=$variant"
361 if [ "$variant" = 'minbase' ]; then
362 packages_template
="${packages_template},sudo,ifupdown,isc-dhcp-client"
365 echo "Installing packages in template: ${packages_template}"
367 trap cleanup EXIT SIGHUP SIGINT SIGTERM
368 # check the mini ubuntu was not already downloaded
369 try_mksubvolume
"$cache/partial-$arch"
370 if [ $?
-ne 0 ]; then
371 echo "Failed to create '$cache/partial-$arch' directory"
375 choose_container_proxy
$cache/partial-
$arch/ $arch
376 # download a mini ubuntu into a cache
377 echo "Downloading ubuntu $release minimal ..."
378 if [ -n "$(which qemu-debootstrap)" ]; then
379 qemu-debootstrap
--verbose $debootstrap_parameters --components=main
,universe
--arch=$arch --include=${packages_template} $release $cache/partial-
$arch $MIRROR
381 debootstrap
--verbose $debootstrap_parameters --components=main
,universe
--arch=$arch --include=${packages_template} $release $cache/partial-
$arch $MIRROR
384 if [ $?
-ne 0 ]; then
385 echo "Failed to download the rootfs, aborting."
389 # Serge isn't sure whether we should avoid doing this when
390 # $release == `distro-info -d`
391 echo "Installing updates"
392 > $cache/partial-
$arch/etc
/apt
/sources.list
393 write_sourceslist
$cache/partial-
$arch/ $arch
395 chroot
"$1/partial-${arch}" apt-get update
396 if [ $?
-ne 0 ]; then
397 echo "Failed to update the apt cache"
400 cat > "$1/partial-${arch}"/usr
/sbin
/policy-rc.d
<< EOF
404 chmod +x
"$1/partial-${arch}"/usr
/sbin
/policy-rc.d
408 mount -t proc proc "${1}/partial-${arch}/proc"
409 chroot "${1}/partial-${arch}" apt-get dist-upgrade -y
411 ) | lxc-unshare
-s MOUNT
-- sh
-eu ||
(suggest_flush
; false
)
413 rm -f "$1/partial-${arch}"/usr
/sbin
/policy-rc.d
415 chroot
"$1/partial-${arch}" apt-get clean
417 mv "$1/partial-$arch" "$1/rootfs-$arch"
422 echo "Download complete"
432 # make a local copy of the miniubuntu
433 echo "Copying rootfs to $rootfs ..."
434 try_mksubvolume
$rootfs
435 if which btrfs
>/dev
/null
2>&1 && is_btrfs_subvolume
$cache/rootfs-
$arch && is_btrfs_subvolume
$rootfs; then
436 realrootfs
=$
(dirname $config)/rootfs
437 [ "$rootfs" = "$realrootfs" ] || umount
$rootfs ||
return 1
438 btrfs subvolume delete
$realrootfs ||
return 1
439 btrfs subvolume snapshot
$cache/rootfs-
$arch $realrootfs ||
return 1
440 [ "$rootfs" = "$realrootfs" ] || mount
--bind $realrootfs $rootfs ||
return 1
442 rsync
-Ha $cache/rootfs-
$arch/ $rootfs/ ||
return 1
453 mkdir
-p $LOCALSTATEDIR/lock
/subsys
/
457 if [ $?
-ne 0 ]; then
458 echo "Cache repository is busy."
463 if [ $flushcache -eq 1 ]; then
464 echo "Flushing cache..."
465 try_rmsubvolume
$cache/partial-
$arch
466 try_rmsubvolume
$cache/rootfs-
$arch
469 echo "Checking cache download in $cache/rootfs-$arch ... "
470 if [ ! -e "$cache/rootfs-$arch" ]; then
471 download_ubuntu
$cache $arch $release
472 if [ $?
-ne 0 ]; then
473 echo "Failed to download 'ubuntu $release base'"
478 echo "Copy $cache/rootfs-$arch to $rootfs ... "
479 copy_ubuntu
$cache $arch $rootfs
480 if [ $?
-ne 0 ]; then
481 echo "Failed to copy rootfs"
487 ) 9>$LOCALSTATEDIR/lock
/subsys
/lxc-ubuntu
$release
500 if [ $arch = "i386" ]; then
504 # if there is exactly one veth network entry, make sure it has an
506 nics
=`grep -e '^lxc\.network\.type[ \t]*=[ \t]*veth' $path/config | wc -l`
507 if [ $nics -eq 1 ]; then
508 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
511 # Generate the configuration file
512 ## Relocate all the network config entries
513 sed -i -e "/lxc.network/{w ${path}/config-network" -e "d}" $path/config
515 ## Relocate any other config entries
516 sed -i -e "/lxc./{w ${path}/config-auto" -e "d}" $path/config
518 ## Add all the includes
519 echo "" >> $path/config
520 echo "# Common configuration" >> $path/config
521 if [ -e "${LXC_TEMPLATE_CONFIG}/ubuntu.common.conf" ]; then
522 echo "lxc.include = ${LXC_TEMPLATE_CONFIG}/ubuntu.common.conf" >> $path/config
524 if [ -e "${LXC_TEMPLATE_CONFIG}/ubuntu.${release}.conf" ]; then
525 echo "lxc.include = ${LXC_TEMPLATE_CONFIG}/ubuntu.${release}.conf" >> $path/config
528 ## Add the container-specific config
529 echo "" >> $path/config
530 echo "# Container specific configuration" >> $path/config
531 [ -e "$path/config-auto" ] && cat $path/config-auto
>> $path/config
&& rm $path/config-auto
532 grep -q "^lxc.rootfs" $path/config
2>/dev
/null ||
echo "lxc.rootfs = $rootfs" >> $path/config
533 cat <<EOF >> $path/config
538 ## Re-add the previously removed network config
539 echo "" >> $path/config
540 echo "# Network configuration" >> $path/config
541 cat $path/config-network
>> $path/config
542 rm $path/config-network
544 if [ $?
-ne 0 ]; then
545 echo "Failed to add configuration"
558 # Disable service startup
559 cat > $rootfs/usr
/sbin
/policy-rc.d
<< EOF
563 chmod +x
$rootfs/usr
/sbin
/policy-rc.d
565 # If the container isn't running a native architecture, setup multiarch
566 if [ -x "$(ls -1 ${rootfs}/usr/bin/qemu-*-static 2>/dev/null)" ]; then
567 dpkg_version
=$
(chroot
$rootfs dpkg-query
-W -f='${Version}' dpkg
)
568 if chroot
$rootfs dpkg
--compare-versions $dpkg_version ge
"1.16.2"; then
569 chroot
$rootfs dpkg
--add-architecture ${hostarch}
571 mkdir
-p ${rootfs}/etc
/dpkg
/dpkg.cfg.d
572 echo "foreign-architecture ${hostarch}" > ${rootfs}/etc
/dpkg
/dpkg.cfg.d
/lxc-multiarch
575 # Save existing value of MIRROR and SECURITY_MIRROR
576 DEFAULT_MIRROR
=$MIRROR
577 DEFAULT_SECURITY_MIRROR
=$SECURITY_MIRROR
579 # Write a new sources.list containing both native and multiarch entries
580 > ${rootfs}/etc
/apt
/sources.list
581 write_sourceslist
$rootfs $arch "native"
583 MIRROR
=$DEFAULT_MIRROR
584 SECURITY_MIRROR
=$DEFAULT_SECURITY_MIRROR
585 write_sourceslist
$rootfs $hostarch "multiarch"
587 # Finally update the lists and install upstart using the host architecture
588 HOST_PACKAGES
="upstart:${hostarch} mountall:${hostarch} isc-dhcp-client:${hostarch}"
589 chroot
$rootfs apt-get update
590 if chroot
$rootfs dpkg
-l iproute2 |
grep -q ^ii
; then
591 HOST_PACKAGES
="$HOST_PACKAGES iproute2:${hostarch}"
593 HOST_PACKAGES
="$HOST_PACKAGES iproute:${hostarch}"
595 install_packages
$rootfs $HOST_PACKAGES
598 # Install Packages in container
599 if [ -n "$packages" ]
601 local packages
="`echo $packages | sed 's/,/ /g'`"
602 echo "Installing packages: ${packages}"
603 install_packages
$rootfs $packages
606 # Set initial timezone as on host
607 if [ -f /etc
/timezone
]; then
608 cat /etc
/timezone
> $rootfs/etc
/timezone
609 chroot
$rootfs dpkg-reconfigure
-f noninteractive tzdata
610 elif [ -f /etc
/sysconfig
/clock ]; then
611 .
/etc
/sysconfig
/clock
612 echo $ZONE > $rootfs/etc
/timezone
613 chroot
$rootfs dpkg-reconfigure
-f noninteractive tzdata
615 echo "Timezone in container is not configured. Adjust it manually."
618 # rmdir /dev/shm for containers that have /run/shm
619 # I'm afraid of doing rm -rf $rootfs/dev/shm, in case it did
620 # get bind mounted to the host's /run/shm. So try to rmdir
621 # it, and in case that fails move it out of the way.
622 # NOTE: This can only be removed once 12.04 goes out of support
623 if [ ! -L $rootfs/dev
/shm
] && [ -e $rootfs/dev
/shm
]; then
624 rmdir $rootfs/dev
/shm
2>/dev
/null ||
mv $rootfs/dev
/shm
$rootfs/dev
/shm.bak
625 ln -s /run
/shm
$rootfs/dev
/shm
628 # Re-enable service startup
629 rm $rootfs/usr
/sbin
/policy-rc.d
637 # copy /etc/passwd, /etc/shadow, and /etc/group entries into container
638 pwd=`getent passwd $user` ||
{ echo "Failed to copy password entry for $user"; false
; }
639 echo $pwd >> $rootfs/etc
/passwd
641 # make sure user's shell exists in the container
642 shell
=`echo $pwd | cut -d: -f 7`
643 if [ ! -x $rootfs/$shell ]; then
644 echo "shell $shell for user $user was not found in the container."
645 pkg
=`dpkg -S $(readlink -m $shell) | cut -d ':' -f1`
646 echo "Installing $pkg"
647 install_packages
$rootfs $pkg
650 shad
=`getent shadow $user`
651 echo "$shad" >> $rootfs/etc
/shadow
653 # bind-mount the user's path into the container's /home
654 h
=`getent passwd $user | cut -d: -f 6`
657 # use relative path in container
659 while [ ${h2:0:1} = "/" ]; do
662 echo "lxc.mount.entry = $h $h2 none bind 0 0" >> $path/config
664 # Make sure the group exists in container
665 grp
=`echo $pwd | cut -d: -f 4` # group number for $user
666 grpe
=`getent group $grp` ||
return 0 # if host doesn't define grp, ignore in container
667 chroot
$rootfs getent group
"$grpe" ||
echo "$grpe" >> $rootfs/etc
/group
673 $1 -h|--help [-a|--arch] [-b|--bindhome <user>] [-d|--debug]
674 [-F | --flush-cache] [-r|--release <release>] [-v|--variant] [ -S | --auth-key <keyfile>]
675 [--rootfs <rootfs>] [--packages <packages>] [-u|--user <user>] [--password <password>]
676 [--mirror <url>] [--security-mirror <url>]
677 release: the ubuntu release (e.g. xenial): defaults to host release on ubuntu, otherwise uses latest LTS
678 variant: debootstrap variant to use (see debootstrap(8))
679 bindhome: bind <user>'s home into the container
680 The ubuntu user will not be created, and <user> will have
682 arch: the container architecture (e.g. amd64): defaults to host arch
683 auth-key: SSH Public key file to inject into container
684 packages: list of packages to add comma separated
685 mirror,security-mirror: mirror for download and /etc/apt/sources.list
690 options
=$
(getopt
-o a
:b
:hp
:r
:v
:n
:FS
:du
: -l arch
:,bindhome
:,help,path
:,release
:,variant
:,name
:,flush-cache
,auth-key
:,debug
,rootfs
:,packages
:,user
:,password
:,mirror
:,security-mirror
: -- "$@")
691 if [ $?
-ne 0 ]; then
695 eval set -- "$options"
697 release
=xenial
# Default to the last Ubuntu LTS release for non-Ubuntu systems
698 if [ -f /etc
/lsb-release
]; then
700 if [ "$DISTRIB_ID" = "Ubuntu" ]; then
701 release
=$DISTRIB_CODENAME
707 # Code taken from debootstrap
708 if [ -x /usr
/bin
/dpkg
] && /usr
/bin
/dpkg
--print-architecture >/dev
/null
2>&1; then
709 arch
=`/usr/bin/dpkg --print-architecture`
710 elif which udpkg
>/dev
/null
2>&1 && udpkg
--print-architecture >/dev
/null
2>&1; then
711 arch
=`/usr/bin/udpkg --print-architecture`
714 if [ "$arch" = "i686" ]; then
716 elif [ "$arch" = "x86_64" ]; then
718 elif [ "$arch" = "armv7l" ]; then
720 elif [ "$arch" = "aarch64" ]; then
722 elif [ "$arch" = "ppc64le" ]; then
737 -h|
--help) usage
$0 && exit 0;;
738 --rootfs) rootfs
=$2; shift 2;;
739 -p|
--path) path
=$2; shift 2;;
740 -n|
--name) name
=$2; shift 2;;
741 -u|
--user) user
=$2; shift 2;;
742 --password) password
=$2; shift 2;;
743 -F|
--flush-cache) flushcache
=1; shift 1;;
744 -r|
--release) release
=$2; shift 2;;
745 -v|
--variant) variant
=$2; shift 2;;
746 --packages) packages
=$2; shift 2;;
747 -b|
--bindhome) bindhome
=$2; shift 2;;
748 -a|
--arch) arch
=$2; shift 2;;
749 -S|
--auth-key) auth_key
=$2; shift 2;;
750 -d|
--debug) debug
=1; shift 1;;
751 --mirror) MIRROR
=$2; shift 2;;
752 --security-mirror) SECURITY_MIRROR
=$2; shift 2;;
753 --) shift 1; break ;;
758 if [ $debug -eq 1 ]; then
762 if [ -n "$bindhome" ]; then
763 pwd=`getent passwd $bindhome`
764 if [ $?
-ne 0 ]; then
765 echo "Error: no password entry found for $bindhome"
771 if [ "$arch" = "i686" ]; then
775 if [ $hostarch = "i386" -a $arch = "amd64" ]; then
776 echo "can't create $arch container on $hostarch"
780 if [ $hostarch = "armhf" -o $hostarch = "armel" -o $hostarch = "arm64" ] && \
781 [ $arch != "armhf" -a $arch != "armel" -a $arch != "arm64" ]; then
782 echo "can't create $arch container on $hostarch"
786 if [ $arch = "arm64" ] && [ $hostarch != "arm64" ]; then
787 echo "can't create $arch container on $hostarch"
791 if [ $hostarch = "powerpc" -a $arch != "powerpc" ]; then
792 echo "can't create $arch container on $hostarch"
796 which debootstrap
>/dev
/null
2>&1 ||
{ echo "'debootstrap' command is missing" >&2; false
; }
798 if [ -z "$path" ]; then
799 echo "'path' parameter is required"
803 if [ "$(id -u)" != "0" ]; then
804 echo "This script should be run as 'root'"
809 config
="$path/config"
810 # if $rootfs exists here, it was passed in with --rootfs
811 if [ -z "$rootfs" ]; then
812 if grep -q '^lxc.rootfs' $config 2>/dev
/null
; then
813 rootfs
=$
(awk -F= '/^lxc.rootfs =/{ print $2 }' $config)
819 install_ubuntu
$rootfs $release $flushcache $LXC_CACHE_PATH
820 if [ $?
-ne 0 ]; then
821 echo "failed to install ubuntu $release"
825 configure_ubuntu
$rootfs $name $release $user $password
826 if [ $?
-ne 0 ]; then
827 echo "failed to configure ubuntu $release for a container"
831 copy_configuration
$path $rootfs $name $arch $release
832 if [ $?
-ne 0 ]; then
833 echo "failed write configuration file"
837 post_process
$rootfs $release $trim_container $packages
839 if [ -n "$bindhome" ]; then
840 do_bindhome
$rootfs $bindhome
841 finalize_user
$bindhome
848 if [ -n "$bindhome" ]; then
849 echo "# Log in as user $bindhome"
851 echo "# The default user is '$user' with password '$password'!"
852 echo "# Use the 'sudo' command to run tasks as root in the container."