[pve-devel] [PATCH container 2/2] Alpine: generate correct inittab

Thomas Lamprecht t.lamprecht at proxmox.com
Mon May 2 15:26:51 CEST 2016


Previously inittab had a hardcoded number of ttys, remove them and
re-add the ones configured by the user.

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 src/PVE/LXC/Setup/Alpine.pm | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/src/PVE/LXC/Setup/Alpine.pm b/src/PVE/LXC/Setup/Alpine.pm
index e7655bc..c817b20 100644
--- a/src/PVE/LXC/Setup/Alpine.pm
+++ b/src/PVE/LXC/Setup/Alpine.pm
@@ -43,7 +43,29 @@ sub template_fixup {
 }
 
 sub setup_init {
-    # Nothing to do
+    my ($self, $conf) = @_;
+
+    my $filename = "/etc/inittab";
+    return if !$self->ct_file_exists($filename);
+
+    my $ttycount =  PVE::LXC::Config->get_tty_count($conf);
+    my $inittab = $self->ct_file_get_contents($filename);
+
+    my @lines = grep {
+	    # remove getty lines
+	    !/^\s*tty\d+::[^:]*:.*getty/
+    } split(/\n/, $inittab);
+
+    $inittab = join("\n", @lines) . "\n";
+
+    $inittab .= "\n# Setup configured gettys\n";
+    for (my $id = 1; $id <= $ttycount; $id++) {
+	next if $id == 7; # reserved for X11
+
+	$inittab .= "tty$id\::respawn:/sbin/getty 38400 tty$id\n";
+    }
+
+    $self->ct_file_set_contents($filename, $inittab);
 }
 
 sub setup_network {
-- 
2.1.4





More information about the pve-devel mailing list