[lxc-devel] [lxc/master] Fix sshd template on systems with systemd

mar-kolya on Github lxc-bot at linuxcontainers.org
Sun Feb 21 06:17:50 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 654 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160221/57ea957d/attachment.bin>
-------------- next part --------------
From 7e8aa95e439761d21c8667e503522a21b027a376 Mon Sep 17 00:00:00 2001
From: Nikolay Martynov <mar.kolya at gmail.com>
Date: Sun, 21 Feb 2016 01:16:15 -0500
Subject: [PATCH] Fix sshd template on systems with systemd

Systems with systemd have /sbin/init as a symlink pointing to real init.
Sshd template tries to bind-mount special init implementation.
The problem is that one cannot bind-mount to a location that is a symlink.

Fix this by deferencing /sbin/init symling and using that as bind-mount location.

Signed-off-by: Nikolay Martynov <mar.kolya at gmail.com>
---
 templates/lxc-sshd.in | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/templates/lxc-sshd.in b/templates/lxc-sshd.in
index d34b3b4..9b07ea6 100644
--- a/templates/lxc-sshd.in
+++ b/templates/lxc-sshd.in
@@ -125,6 +125,8 @@ copy_configuration()
     rootfs=$2
     name=$3
 
+    init_path=$(realpath --relative-to=/ $(readlink -f /sbin/init))
+
     grep -q "^lxc.rootfs" $path/config 2>/dev/null || echo "lxc.rootfs = $rootfs" >> $path/config
 cat <<EOF >> $path/config
 lxc.utsname = $name
@@ -140,7 +142,7 @@ lxc.mount.entry = /bin bin none ro,bind 0 0
 lxc.mount.entry = /usr usr none ro,bind 0 0
 lxc.mount.entry = /sbin sbin none ro,bind 0 0
 lxc.mount.entry = tmpfs var/run/sshd tmpfs mode=0644 0 0
-lxc.mount.entry = @LXCTEMPLATEDIR@/lxc-sshd sbin/init none ro,bind 0 0
+lxc.mount.entry = @LXCTEMPLATEDIR@/lxc-sshd $init_path none ro,bind 0 0
 lxc.mount.entry = /etc/init.d etc/init.d none ro,bind 0 0
 
 lxc.mount.auto = cgroup:mixed proc:mixed sys:mixed


More information about the lxc-devel mailing list