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

Thomas Lamprecht t.lamprecht at proxmox.com
Mon May 2 16:10:59 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>
---

changes since v1:
* do not add comment to inittab, its clear how it works
  and the accumulate as I didn't deleted it, so each start
  added a new comment.

 src/PVE/LXC/Setup/Alpine.pm | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/src/PVE/LXC/Setup/Alpine.pm b/src/PVE/LXC/Setup/Alpine.pm
index e7655bc..7705c8d 100644
--- a/src/PVE/LXC/Setup/Alpine.pm
+++ b/src/PVE/LXC/Setup/Alpine.pm
@@ -43,7 +43,27 @@ 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";
+
+    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