"Merge" in code from debian lxc template that comes with Ubuntu 13.04

This commit is contained in:
Fabio Rehm 2013-05-01 22:01:59 -03:00
parent 4759adf143
commit 06a0d66616

View file

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
# This is a modified version of /usr/share/lxc/templates/lxc-debian # This is a modified version of /usr/share/lxc/templates/lxc-debian
# that comes with Ubuntu 12.10 changed to suit vagrant-lxc needs # that comes with Ubuntu 13.04 changed to suit vagrant-lxc needs
set -e set -e
@ -18,6 +18,14 @@ configure_debian()
hostname=$2 hostname=$2
release=$3 release=$3
# squeeze only has /dev/tty and /dev/tty0 by default,
# therefore creating missing device nodes for tty1-4.
for tty in $(seq 1 4); do
if [ ! -e $rootfs/dev/tty$tty ]; then
mknod $rootfs/dev/tty$tty c 4 $tty
fi
done
# configure the inittab # configure the inittab
cat <<EOF > $rootfs/etc/inittab cat <<EOF > $rootfs/etc/inittab
id:3:initdefault: id:3:initdefault:
@ -32,45 +40,33 @@ l6:6:wait:/etc/init.d/rc 6
# Normally not reached, but fallthrough in case of emergency. # Normally not reached, but fallthrough in case of emergency.
z6:6:respawn:/sbin/sulogin z6:6:respawn:/sbin/sulogin
1:2345:respawn:/sbin/getty 38400 console 1:2345:respawn:/sbin/getty 38400 console
#c1:12345:respawn:/sbin/getty 38400 tty1 linux c1:12345:respawn:/sbin/getty 38400 tty1 linux
c2:12345:respawn:/sbin/getty 38400 tty2 linux c2:12345:respawn:/sbin/getty 38400 tty2 linux
c3:12345:respawn:/sbin/getty 38400 tty3 linux c3:12345:respawn:/sbin/getty 38400 tty3 linux
c4:12345:respawn:/sbin/getty 38400 tty4 linux c4:12345:respawn:/sbin/getty 38400 tty4 linux
p6::ctrlaltdel:/sbin/init 6
p0::powerfail:/sbin/init 0
EOF EOF
echo '/etc/inittab created'
# disable selinux in debian # disable selinux in debian
mkdir -p $rootfs/selinux mkdir -p $rootfs/selinux
echo 0 > $rootfs/selinux/enforce echo 0 > $rootfs/selinux/enforce
echo 'selinux disabled'
# 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
auto eth0 auto eth0
iface eth0 inet dhcp iface eth0 inet dhcp
EOF EOF
echo 'network configured (dhcp on eth0)'
# set the hostname # set the hostname
cat <<EOF > $rootfs/etc/hostname cat <<EOF > $rootfs/etc/hostname
$hostname $hostname
EOF EOF
echo "/etc/hostname created (${hostname})"
# set dhcp hostname
cat <<EOF >> $rootfs/etc/dhcp/dhclient.conf
send host-name "$hostname";
EOF
echo 'dhcp hostname set'
# reconfigure some services
if [ ! -z "${LANG}" ]; then if [ ! -z "${LANG}" ]; then
# set default locale # set default locale
cat <<EOF > $rootfs/etc/locale.gen cat <<EOF > $rootfs/etc/locale.gen
@ -82,64 +78,11 @@ EOF
echo 'update-locale done' echo 'update-locale done'
fi fi
# set proxy if any
if [ ! -z "${HTTP_PROXY}" ]; then
cat <<EOF > $rootfs/etc/apt/apt.conf.d/10proxy
Acquire::http::Proxy "${HTTP_PROXY}";
Acquire::ftp::Proxy "${HTTP_PROXY}";
Acquire::ftp::Timeout "15";
Acquire::ftp::Passive "true";
Acquire::ftp::Proxy::Passive "true";
EOF
echo "Apt default proxy set to ${HTTP_PROXY}"
cat <<EOF >> $rootfs/etc/environment
HTTP_PROXY=${HTTP_PROXY}
HTTPS_PROXY=${HTTP_PROXY}
FTP_PROXY=${HTTP_PROXY}
EOF
echo "proxy ${HTTP_PROXY} added to /etc/environment"
fi
# recommends are as of now still abused in many packages
cat <<EOF > $rootfs/etc/apt/apt.conf.d/90recommends
APT::Install-Recommends "0";
APT::Install-Suggests "0";
EOF
echo '/etc/apt/apt.conf.d/90recommends created'
# set default release
cat <<EOF > $rootfs/etc/apt/apt.conf.d/30release
DPkg::Default-Release "${release}";
APT::Default-Release "${release}";
EOF
echo '/etc/apt/apt.conf.d/30release created'
# set minimal hosts
cat <<EOF > $rootfs/etc/hosts
127.0.0.1 localhost
127.0.1.1 $hostname.vagrantup.com $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
# remove pointless services in a container # remove pointless services in a container
for service in checkroot \ chroot $rootfs /usr/sbin/update-rc.d -f checkroot.sh remove
umountfs \ chroot $rootfs /usr/sbin/update-rc.d -f umountfs remove
hwclock.sh \ chroot $rootfs /usr/sbin/update-rc.d -f hwclock.sh remove
hwclockfirst.sh \ chroot $rootfs /usr/sbin/update-rc.d -f hwclockfirst.sh remove
mountall.sh ; do
chroot $rootfs /usr/sbin/update-rc.d -f $service remove > /dev/null 2>&1
echo "service ${service} removed from init"
done
# suppress log level output for udev
#sed -i "s/=\"err\"/=0/" $rootfs/etc/udev/udev.conf
echo "root:vagrant" | chroot $rootfs chpasswd echo "root:vagrant" | chroot $rootfs chpasswd
@ -209,19 +152,16 @@ copy_configuration()
rootfs=$2 rootfs=$2
name=$3 name=$3
arch=$4 arch=$4
release=$5
cat <<EOF >> $path/fstab
none $rootfs/dev/pts devpts defaults 0 0
none $rootfs/proc proc defaults 0 0
none $rootfs/sys sysfs defaults 0 0
none $rootfs/dev/shm tmpfs defaults 0 0
EOF
grep -q "^lxc.rootfs" $path/config 2>/dev/null || echo "lxc.rootfs = $rootfs" >> $path/config
cat <<EOF >> $path/config cat <<EOF >> $path/config
lxc.tty = 4 lxc.tty = 4
lxc.pts = 1024 lxc.pts = 1024
lxc.rootfs = ${rootfs} lxc.utsname = ${name}
# When using LXC with apparmor, uncomment the next line to run unconfined:
#lxc.aa_profile = unconfined
lxc.cgroup.devices.deny = a lxc.cgroup.devices.deny = a
# /dev/null and zero # /dev/null and zero
lxc.cgroup.devices.allow = c 1:3 rwm lxc.cgroup.devices.allow = c 1:3 rwm
@ -240,46 +180,8 @@ lxc.cgroup.devices.allow = c 5:2 rwm
lxc.cgroup.devices.allow = c 254:0 rwm lxc.cgroup.devices.allow = c 254:0 rwm
# mounts point # mounts point
#lxc.mount.entry=proc $rootfs/proc proc nodev,noexec,nosuid 0 0 lxc.mount.entry = proc proc proc nodev,noexec,nosuid 0 0
#lxc.mount.entry=devpts $rootfs/dev/pts devpts defaults 0 0 lxc.mount.entry = sysfs sys sysfs defaults 0 0
#lxc.mount.entry=sysfs $rootfs/sys sysfs defaults 0 0
lxc.mount = ${path}/fstab
lxc.utsname = ${name}
# networking
#lxc.network.type = veth
#lxc.network.flags = up
# Bridged network
#lxc.network.link = br42
#lxc.network.name = eth0
# It is fine to be commented out
# Warn: interface name 'vethXXXX' too long (>15)
#lxc.network.veth.pair = veth${name#*-}
#lxc.network.ipv4 = 10.1.1.1/24
#lxc.network.hwaddr = 00:12:34:56:78:9A
#lxc.network.hwaddr = \
00:16:3e:$(openssl rand -hex 3| sed 's/\(..\)/\1:/g; s/.$//')
# Limits
# Set max memory
lxc.cgroup.memory.limit_in_bytes = 1024M
# Scheduler, works like this: You assign to vm0 the value of 10 and to vm1
# the value of 20. This means: in each CPU Second vm1 will get the double
# amount of CPU cycles as vm0. Per default all values are set to 1024.
#lxc.cgroup.cpu.shares = 512
# CPUs
# assign first CPU to this container:
#lxc.cgroup.cpuset.cpus = 0
# assign the first, the second and the last CPU
#lxc.cgroup.cpuset.cpus = 0-1,3
# assign the first and the last CPU
#lxc.cgroup.cpuset.cpus = 0,3
EOF EOF
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
@ -407,7 +309,7 @@ if [ $? -ne 0 ]; then
exit 1 exit 1
fi fi
copy_configuration $path $rootfs $name $arch $release copy_configuration $path $rootfs $name
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "failed write configuration file" echo "failed write configuration file"
exit 1 exit 1