42
43
iface eth0 inet dhcp
45
# so you can 'ssh $hostname.' or 'ssh $hostname.local'
46
if [ -f $rootfs/etc/dhcp/dhclient.conf ]; then
47
sed -i "s/<hostname>/$hostname/" $rootfs/etc/dhcp/dhclient.conf
48
elif [ -f $rootfs/etc/dhcp3/dhclient.conf ]; then
49
sed -i "s/<hostname>/$hostname/" $rootfs/etc/dhcp3/dhclient.conf
53
47
cat <<EOF > $rootfs/etc/hostname
58
52
127.0.0.1 localhost $hostname
61
# suppress log level output for udev
62
sed -i "s/=\"err\"/=0/" $rootfs/etc/udev/udev.conf
64
# remove jobs for consoles 5 and 6 since we only create 4 consoles in
66
rm -f $rootfs/etc/init/tty{5,6}.conf
68
echo "Please change root-password !"
69
echo "root:root" | chroot $rootfs chpasswd
55
if [ "$release" = "precise" ]; then
60
# suppress log level output for udev
61
sed -i "s/=\"err\"/=0/" $rootfs/etc/udev/udev.conf
63
# remove jobs for consoles 5 and 6 since we only create 4 consoles in
65
rm -f $rootfs/etc/init/tty{5,6}.conf
68
chroot $rootfs groupadd --system $group >/dev/null 2>&1 || true
69
chroot $rootfs useradd --create-home -s /bin/bash -G $group ubuntu
70
echo "ubuntu:ubuntu" | chroot $rootfs chpasswd
71
if [ -n "$auth_key" -a -f "$auth_key" ]; then
72
u_path="/home/ubuntu/.ssh"
73
root_u_path="$rootfs/$u_path"
75
cp $auth_key "$root_u_path/authorized_keys"
76
chroot $rootfs chown -R ubuntu: "$u_path"
78
echo "Inserted SSH public key from $auth_key into /home/ubuntu/.ssh/authorized_keys"
85
# $1 => path to the rootfs
86
# $2 => architecture we want to add
87
# $3 => whether to use the multi-arch syntax or not
91
MIRROR=${MIRROR:-http://archive.ubuntu.com/ubuntu}
92
SECURITY_MIRROR=${SECURITY_MIRROR:-http://security.ubuntu.com/ubuntu}
97
MIRROR=${MIRROR:-http://archive.ubuntu.com/ubuntu}
98
SECURITY_MIRROR=${SECURITY_MIRRORMIRROR:-http://security.ubuntu.com/ubuntu}
101
MIRROR=${MIRROR:-http://ports.ubuntu.com/ubuntu-ports}
102
SECURITY_MIRROR=${SECURITY_MIRROR:-http://ports.ubuntu.com/ubuntu-ports}
107
MIRROR=${MIRROR:-http://ports.ubuntu.com/ubuntu-ports}
108
SECURITY_MIRROR=${SECURITY_MIRROR:-http://ports.ubuntu.com/ubuntu-ports}
112
cat >> "$1/etc/apt/sources.list" << EOF
113
deb [arch=$2] $MIRROR ${release} main restricted universe multiverse
114
deb [arch=$2] $MIRROR ${release}-updates main restricted universe multiverse
115
deb [arch=$2] $SECURITY_MIRROR ${release}-security main restricted universe multiverse
118
cat >> "$1/etc/apt/sources.list" << EOF
119
deb $MIRROR ${release} main restricted universe multiverse
120
deb $MIRROR ${release}-updates main restricted universe multiverse
121
deb $SECURITY_MIRROR ${release}-security main restricted universe multiverse
98
150
# download a mini ubuntu into a cache
99
151
echo "Downloading ubuntu $release minimal ..."
100
debootstrap --verbose --components=main,universe --arch=$arch --include=$packages $release $cache/partial-$arch $MIRROR
152
if [ -n "$(which qemu-debootstrap)" ]; then
153
qemu-debootstrap --verbose --components=main,universe --arch=$arch --include=$packages $release $cache/partial-$arch $MIRROR
155
debootstrap --verbose --components=main,universe --arch=$arch --include=$packages $release $cache/partial-$arch $MIRROR
101
158
if [ $? -ne 0 ]; then
102
159
echo "Failed to download the rootfs, aborting."
163
echo "Installing updates"
164
if [ -z "$MIRROR" ]; then
165
MIRROR="http://archive.ubuntu.com/ubuntu"
167
cat >> "$1/partial-${arch}/etc/apt/sources.list" << EOF
168
deb $MIRROR ${release}-updates main universe
169
deb http://security.ubuntu.com/ubuntu ${release}-security main universe
171
chroot "$1/partial-${arch}" apt-get update
172
if [ $? -ne 0 ]; then
173
echo "Failed to update the apt cache"
176
cat > "$1/partial-${arch}"/usr/sbin/policy-rc.d << EOF
180
chmod +x "$1/partial-${arch}"/usr/sbin/policy-rc.d
182
chroot "$1/partial-${arch}" apt-get dist-upgrade -y
185
rm -f "$1/partial-${arch}"/usr/sbin/policy-rc.d
186
if [ $ret -ne 0 ]; then
187
echo "Failed to upgrade the cache"
106
191
# Serge isn't sure whether we should avoid doing this when
107
192
# $release == `distro-info -d`
108
193
echo "Installing updates"
111
MIRROR=${MIRROR:-http://archive.ubuntu.com/ubuntu}
112
SECURITY_MIRROR=${SECURITY_MIRROR:-http://security.ubuntu.com/ubuntu}
117
MIRROR=${MIRROR:-http://archive.ubuntu.com/ubuntu}
118
SECURITY_MIRROR=${SECURITY_MIRRORMIRROR:-http://security.ubuntu.com/ubuntu}
121
MIRROR=${MIRROR:-http://ports.ubuntu.com/ubuntu-ports}
122
SECURITY_MIRROR=${SECURITY_MIRROR:-http://ports.ubuntu.com/ubuntu-ports}
127
MIRROR=${MIRROR:-http://ports.ubuntu.com/ubuntu-ports}
128
SECURITY_MIRROR=${SECURITY_MIRROR:-http://ports.ubuntu.com/ubuntu-ports}
131
cat >> "$1/partial-${arch}/etc/apt/sources.list" << EOF
132
deb $MIRROR ${release}-updates main universe
133
deb $SECURITY_MIRROR ${release}-security main universe
194
> $cache/partial-$arch/etc/apt/sources.list
195
write_sourceslist $cache/partial-$arch/ $arch
135
197
chroot "$1/partial-${arch}" apt-get update
136
198
if [ $? -ne 0 ]; then
137
199
echo "Failed to update the apt cache"
224
287
if [ $arch = "i386" ]; then
292
if [ $release = "precise" ]; then
296
# if there is exactly one veth network entry, make sure it has an
298
nics=`grep -e '^lxc\.network\.type[ \t]*=[ \t]*veth' $path/config | wc -l`
299
if [ $nics -eq 1 ]; then
300
grep -q "^lxc.network.hwaddr" $path/config || cat <<EOF >> $path/config
301
lxc.network.hwaddr= 00:16:3e:$(openssl rand -hex 3| sed 's/\(..\)/\1:/g; s/.$//')
228
305
cat <<EOF >> $path/config
229
306
lxc.utsname = $name
308
lxc.devttydir = $ttydir
233
311
lxc.rootfs = $rootfs
234
312
lxc.mount = $path/fstab
236
lxc.cap.drop = sys_module mac_admin
314
lxc.cap.drop = sys_module mac_admin mac_override
238
316
lxc.cgroup.devices.deny = a
239
317
# Allow any mknod (but not using the node)
381
459
if [ $trim_container -eq 1 ]; then
382
460
trim $rootfs $release
461
elif [ $release = "lucid" -o $release = "maverick" -o $release = "natty" \
462
-o $release = "oneiric" ]; then
384
463
# for lucid and maverick, if not trimming, then add the ubuntu-virt
385
464
# ppa and install lxcguest
386
465
if [ $release = "lucid" -o $release = "maverick" ]; then
391
470
chroot $rootfs apt-get update
392
471
chroot $rootfs apt-get install --force-yes -y lxcguest
474
# If the container isn't running a native architecture, setup multiarch
475
if [ -x "$(ls -1 ${rootfs}/usr/bin/qemu-*-static 2>/dev/null)" ]; then
476
mkdir -p ${rootfs}/etc/dpkg/dpkg.cfg.d
477
echo "foreign-architecture ${hostarch}" > ${rootfs}/etc/dpkg/dpkg.cfg.d/lxc-multiarch
479
# Save existing value of MIRROR and SECURITY_MIRROR
480
DEFAULT_MIRROR=$MIRROR
481
DEFAULT_SECURITY_MIRROR=$SECURITY_MIRROR
483
# Write a new sources.list containing both native and multiarch entries
484
> ${rootfs}/etc/apt/sources.list
485
write_sourceslist $rootfs $arch "native"
487
MIRROR=$DEFAULT_MIRROR
488
SECURITY_MIRROR=$DEFAULT_SECURITY_MIRROR
489
write_sourceslist $rootfs $hostarch "multiarch"
491
# Finally update the lists and install upstart using the host architecture
492
chroot $rootfs apt-get update
493
chroot $rootfs apt-get install --force-yes -y --no-install-recommends upstart:${hostarch} mountall:amd64 iproute:amd64 isc-dhcp-client:amd64
421
522
$1 -h|--help [-a|--arch] [-b|--bindhome <user>] [--trim]
422
[-F | --flush-cache] [-r|--release <release>]
523
[-F | --flush-cache] [-r|--release <release>] [ -S | --auth_key <keyfile>]
423
524
release: lucid | maverick | natty | oneiric | precise
424
525
trim: make a minimal (faster, but not upgrade-safe) container
425
526
bindhome: bind <user>'s home into the container
426
527
arch: amd64 or i386: defaults to host arch
528
auth_key: SSH Public key file to inject into container
431
options=$(getopt -o a:b:hp:r:xn:F -l arch:,bindhome:,help,path:,release:,trim,name:,flush-cache -- "$@")
533
options=$(getopt -o a:b:hp:r:xn:FS: -l arch:,bindhome:,help,path:,release:,trim,name:,flush-cache,auth-key: -- "$@")
432
534
if [ $? -ne 0 ]; then
433
535
usage $(basename $0)
526
configure_ubuntu $rootfs $name
629
configure_ubuntu $rootfs $name $release
527
630
if [ $? -ne 0 ]; then
528
631
echo "failed to configure ubuntu $release for a container"
532
copy_configuration $path $rootfs $name $arch
635
copy_configuration $path $rootfs $name $arch $release
533
636
if [ $? -ne 0 ]; then
534
637
echo "failed write configuration file"