mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-08-04 11:05:10 +00:00
Merge pull request #746 from ar45/fix_debian_systemd_getty
Fix #520 - multiple instances of agetty on systemd.
This commit is contained in:
commit
a36a3c0d63
@ -45,10 +45,11 @@ configure_debian()
|
||||
{
|
||||
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
|
||||
@ -68,10 +69,7 @@ l6:6:wait:/etc/init.d/rc 6
|
||||
# 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
|
||||
@ -191,6 +189,8 @@ configure_debian_systemd()
|
||||
{
|
||||
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
|
||||
@ -206,7 +206,10 @@ configure_debian_systemd()
|
||||
|
||||
# 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
|
||||
@ -216,10 +219,16 @@ configure_debian_systemd()
|
||||
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
|
||||
}
|
||||
@ -353,6 +362,7 @@ copy_configuration()
|
||||
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
|
||||
@ -378,6 +388,7 @@ copy_configuration()
|
||||
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
|
||||
@ -608,31 +619,38 @@ fi
|
||||
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}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user