Support non-apt OS, fix sysvinit autologin
Refine LXC container bootstrap and sysvinit autologin handling. - Fix case branch formatting and change Debian-family check to an elif to avoid logic fall-through. - Add a non-apt branch for Fedora/Rocky/Alma/CentOS/openEuler/openSUSE/Arch/Gentoo that sets the container timezone from the host and ensures curl is installed via the appropriate package manager. - Improve sysvinit (/etc/inittab) auto-login changes: use more robust sed patterns, append a console autologin entry via heredoc, signal init to reload inittab before killing getty processes, and target getty processes more precisely to ensure proper respawn with new settings.
This commit is contained in:
@@ -1211,36 +1211,30 @@ EOF
|
||||
;;
|
||||
|
||||
sysvinit)
|
||||
# Devuan/older systems - modify inittab for auto-login
|
||||
# Devuan 5 (daedalus) uses SysVinit with various inittab formats
|
||||
# LXC can use /dev/console OR /dev/tty1 depending on how pct console connects
|
||||
# Devuan/older SysVinit systems: modify inittab for auto-login on tty1 + console
|
||||
if [[ -f /etc/inittab ]]; then
|
||||
# Backup original inittab
|
||||
cp /etc/inittab /etc/inittab.bak 2>/dev/null || true
|
||||
|
||||
# Enable autologin on tty1 (for direct access) - handle various formats
|
||||
# Devuan uses format: 1:2345:respawn:/sbin/getty 38400 tty1
|
||||
sed -i 's|^\(1:[0-9]*:respawn:\).*getty.*tty1.*|1:2345:respawn:/sbin/agetty --autologin root --noclear tty1 38400 linux|' /etc/inittab
|
||||
# Replace the tty1 getty line with an autologin version.
|
||||
# Devuan 5 ships: 1:2345:respawn:/sbin/agetty --noclear tty1 38400 linux
|
||||
sed -i 's|^\(1:[0-9]*:respawn:\).*[ag]etty.*tty1.*|1:2345:respawn:/sbin/agetty --autologin root --noclear tty1 38400 linux|' /etc/inittab
|
||||
|
||||
# CRITICAL: Add/replace console entry for LXC - this is what pct console uses!
|
||||
# Remove any existing console entries first (commented or not)
|
||||
sed -i '/^[^#]*:.*:respawn:.*getty.*console/d' /etc/inittab
|
||||
# Add/replace console entry (pct console maps to /dev/console in some configs)
|
||||
sed -i '/^[^#]*:.*:respawn:.*[ag]etty.*console/d' /etc/inittab
|
||||
sed -i '/^# LXC console autologin/d' /etc/inittab
|
||||
cat >>/etc/inittab <<'EOF'
|
||||
|
||||
# Add new console entry for LXC at the end
|
||||
echo "" >>/etc/inittab
|
||||
echo "# LXC console autologin (added by community-scripts)" >>/etc/inittab
|
||||
echo "co:2345:respawn:/sbin/agetty --autologin root --noclear console 115200 linux" >>/etc/inittab
|
||||
# LXC console autologin (added by community-scripts)
|
||||
co:2345:respawn:/sbin/agetty --autologin root --noclear console 115200 linux
|
||||
EOF
|
||||
|
||||
# Force a reload of inittab and respawn ALL getty processes
|
||||
# Kill ALL getty processes to force respawn with new autologin settings
|
||||
pkill -9 -f '[ag]etty' &>/dev/null || true
|
||||
|
||||
# Small delay to let init notice the dead processes
|
||||
sleep 1
|
||||
|
||||
# Reload inittab - try multiple methods
|
||||
# IMPORTANT: signal init to load the new inittab into memory FIRST,
|
||||
# then kill the running getty — init will respawn it using the new config.
|
||||
# (Killing first causes init to respawn with the OLD in-memory config.)
|
||||
telinit q &>/dev/null || init q &>/dev/null || kill -HUP 1 &>/dev/null || true
|
||||
sleep 1
|
||||
pkill -f '[ag]etty.*tty1' &>/dev/null || true
|
||||
pkill -f '[ag]etty.*console' &>/dev/null || true
|
||||
fi
|
||||
touch /root/.hushlogin
|
||||
;;
|
||||
|
||||
Reference in New Issue
Block a user