{
rootfs=$1
hostname=$2
+ num_tty=$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
+ for tty in $(seq 1 $num_tty); do
if [ ! -e $rootfs/dev/tty$tty ]; then
mknod $rootfs/dev/tty$tty c 4 $tty
fi
# Normally not reached, but fallthrough in case of emergency.
z6:6:respawn:/sbin/sulogin
1:2345:respawn:/sbin/getty 38400 console
-c1:12345:respawn:/sbin/getty 38400 tty1 linux
-c2:12345:respawn:/sbin/getty 38400 tty2 linux
-c3:12345:respawn:/sbin/getty 38400 tty3 linux
-c4:12345:respawn:/sbin/getty 38400 tty4 linux
+$(for tty in $(seq 1 $num_tty); do echo "c${tty}:12345:respawn:/sbin/getty 38400 tty${tty} linux" ; done;)
p6::ctrlaltdel:/sbin/init 6
p0::powerfail:/sbin/init 0
EOF
{
path=$1
rootfs=$2
+ config=$3
+ num_tty=$4
# this only works if we have getty@.service to manipulate
if [ -f ${rootfs}/lib/systemd/system/getty\@.service ]; then
# Fix getty-static-service as debootstrap does not install dbus
if [ -e $rootfs//lib/systemd/system/getty-static.service ] ; then
- sed 's/ getty@tty[5-9].service//g' $rootfs/lib/systemd/system/getty-static.service | sed 's/\(tty2-tty\)[5-9]/\14/g' > $rootfs/etc/systemd/system/getty-static.service
+ local tty_services=$(for i in $(seq 2 $num_tty); do echo -n "getty@tty${i}.service "; done; )
+ sed 's/ getty@tty.*/'" $tty_services "'/g' \
+ $rootfs/lib/systemd/system/getty-static.service | \
+ sed 's/\(tty2-tty\)[5-9]/\1'"${num_tty}"'/g' > $rootfs/etc/systemd/system/getty-static.service
fi
# This function has been copied and adapted from lxc-fedora
chroot ${rootfs} ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
# Make systemd honor SIGPWR
chroot ${rootfs} ln -s /lib/systemd/system/halt.target /etc/systemd/system/sigpwr.target
- # Setup getty service on the 4 ttys we are going to allow in the
+ # Setup getty service on the ttys we are going to allow in the
# default config. Number should match lxc.tty
( cd ${rootfs}/etc/systemd/system/getty.target.wants
- for i in 1 2 3 4 ; do ln -sf ../getty\@.service getty@tty${i}.service; done )
+ for i in $(seq 1 $num_tty) ; do ln -sf ../getty\@.service getty@tty${i}.service; done )
+
+ # Since we use static-getty.target; we need to mask container-getty@.service generated by
+ # container-getty-generator, so we don't get multiple instances of agetty running.
+ # See https://github.com/lxc/lxc/issues/520 and https://github.com/lxc/lxc/issues/484
+ ( cd ${rootfs}/etc/systemd/system/getty.target.wants
+ for i in $(seq 0 $num_tty); do ln -sf /dev/null container-getty\@${i}.service; done )
return 0
}
rootfs=$2
hostname=$3
arch=$4
+ num_tty=$5
# Generate the configuration file
# if there is exactly one veth network entry, make sure it has an
grep -q "^lxc.rootfs" $path/config 2> /dev/null || echo "lxc.rootfs = $rootfs" >> $path/config
cat <<EOF >> $path/config
+lxc.tty = $num_tty
lxc.utsname = $hostname
lxc.arch = $arch
EOF
config="$path/config"
if [ -z "$rootfs" ]; then
if grep -q '^lxc.rootfs' $config 2> /dev/null ; then
- rootfs=$(awk -F= '/^lxc.rootfs =/{ print $2 }' $config)
+ rootfs=$(awk -F= '/^lxc.rootfs[ \t]+=/{ print $2 }' $config)
else
rootfs=$path/rootfs
fi
fi
+# determine the number of ttys - default is 4
+if grep -q '^lxc.tty' $config 2> /dev/null ; then
+ num_tty=$(awk -F= '/^lxc.tty[ \t]+=/{ print $2 }' $config)
+else
+ num_tty=4
+fi
+
install_debian $rootfs $release $arch $LXC_CACHE_PATH
if [ $? -ne 0 ]; then
echo "failed to install debian"
exit 1
fi
-configure_debian $rootfs $name
+configure_debian $rootfs $name $num_tty
if [ $? -ne 0 ]; then
echo "failed to configure debian for a container"
exit 1
fi
-copy_configuration $path $rootfs $name $arch
+copy_configuration $path $rootfs $name $arch $num_tty
if [ $? -ne 0 ]; then
echo "failed write configuration file"
exit 1
fi
-configure_debian_systemd $path $rootfs
+configure_debian_systemd $path $rootfs $config $num_tty
post_process ${rootfs} ${release} ${arch} ${hostarch} ${packages}