diff options
Diffstat (limited to 'recipes-containers/lxc/files/lxc-0.9.0-enable-chroot-chpasswd-functionality-for-busybox-hosts.patch')
-rw-r--r-- | recipes-containers/lxc/files/lxc-0.9.0-enable-chroot-chpasswd-functionality-for-busybox-hosts.patch | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/recipes-containers/lxc/files/lxc-0.9.0-enable-chroot-chpasswd-functionality-for-busybox-hosts.patch b/recipes-containers/lxc/files/lxc-0.9.0-enable-chroot-chpasswd-functionality-for-busybox-hosts.patch new file mode 100644 index 00000000..d07c6580 --- /dev/null +++ b/recipes-containers/lxc/files/lxc-0.9.0-enable-chroot-chpasswd-functionality-for-busybox-hosts.patch | |||
@@ -0,0 +1,70 @@ | |||
1 | From 4ddc14bd0866ff769421857044dd14867f1944d5 Mon Sep 17 00:00:00 2001 | ||
2 | From: Bogdan Purcareata <bogdan.purcareata@freescale.com> | ||
3 | Date: Thu, 11 Apr 2013 16:15:43 +0300 | ||
4 | Subject: [PATCH v2] lxc-template: enable chroot + chpasswd functionality for | ||
5 | Busybox hosts | ||
6 | |||
7 | This patch supports the scenario where a user wants to install a | ||
8 | busybox container on a busybox host. | ||
9 | |||
10 | When running the template, in order to change the root password, | ||
11 | the template needs to do the chroot. On busybox-powered hosts, chroot | ||
12 | is not part of the coreutils package - it's part of busybox. And the | ||
13 | busybox implementation or chroot only works if it has /lib in the new | ||
14 | root populated with the right binaries (or at least that's the | ||
15 | solution I found to make it work). | ||
16 | |||
17 | The temporarily bind-mounts /lib in the NEWROOT, chroots there, | ||
18 | changes the password, goes back and unmounts. This set of operations | ||
19 | is contained in a new MOUNT namespace, using the lxc-unshare call. | ||
20 | |||
21 | Signed-off-by: Bogdan Purcareata <bogdan.purcareata@freescale.com> | ||
22 | --- | ||
23 | templates/lxc-busybox.in | 30 ++++++++++++++++++++++++++++-- | ||
24 | 1 file changed, 28 insertions(+), 2 deletions(-) | ||
25 | |||
26 | diff --git a/templates/lxc-busybox.in b/templates/lxc-busybox.in | ||
27 | index cb425ec..2ca2bfd 100644 | ||
28 | --- a/templates/lxc-busybox.in | ||
29 | +++ b/templates/lxc-busybox.in | ||
30 | @@ -189,9 +189,35 @@ configure_busybox() | ||
31 | # passwd exec must be setuid | ||
32 | chmod +s $rootfs/bin/passwd | ||
33 | touch $rootfs/etc/shadow | ||
34 | - echo "setting root passwd to root" | ||
35 | - echo "root:root" | chroot $rootfs chpasswd | ||
36 | |||
37 | + # setting passwd for root | ||
38 | + CHPASSWD_FILE=$rootfs/root/chpasswd.sh | ||
39 | + | ||
40 | + cat <<EOF >$CHPASSWD_FILE | ||
41 | +echo "setting root password to \"root\"" | ||
42 | + | ||
43 | +mount --bind /lib $rootfs/lib | ||
44 | +if [ \$? -ne 0 ]; then | ||
45 | + echo "Failed bind-mounting /lib at $rootfs/lib" | ||
46 | + exit 1 | ||
47 | +fi | ||
48 | + | ||
49 | +chroot $rootfs chpasswd <<EOFF 2>/dev/null | ||
50 | +root:root | ||
51 | +EOFF | ||
52 | + | ||
53 | + | ||
54 | +if [ \$? -ne 0 ]; then | ||
55 | + echo "Failed to change root password" | ||
56 | + exit 1 | ||
57 | +fi | ||
58 | + | ||
59 | +umount $rootfs/lib | ||
60 | + | ||
61 | +EOF | ||
62 | + | ||
63 | + lxc-unshare -s MOUNT -- /bin/sh < $CHPASSWD_FILE | ||
64 | + rm $CHPASSWD_FILE | ||
65 | |||
66 | # add ssh functionality if dropbear package available on host | ||
67 | which dropbear >/dev/null 2>&1 | ||
68 | -- | ||
69 | 1.7.11.7 | ||
70 | |||