From a8713271355c68023ea090eb223682e784c64f93 Mon Sep 17 00:00:00 2001 From: Damjan Georgievski Date: Tue, 27 Jan 2015 20:02:24 +0100 Subject: [PATCH 1/2] export a proper debian PATH for the chroot when running in the chroot, it would be expected to have a Debian-ish environment, most important the PATH variable. Otherwise the host PATH would be used which can wrong for Debian, especially if the host is Arch (which doesn't have /bin, /sbin or /usr/sbin). Signed-off-by: Damjan Georgievski --- contrib/mkimage/debootstrap | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/mkimage/debootstrap b/contrib/mkimage/debootstrap index c7a2b66830..83f17e0c4e 100755 --- a/contrib/mkimage/debootstrap +++ b/contrib/mkimage/debootstrap @@ -189,6 +189,7 @@ fi ( set -x + export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin # make sure we're fully up-to-date chroot "$rootfsDir" bash -c 'apt-get update && apt-get dist-upgrade -y' From 91770ec9e4b5bce330ddebc421248d275549ccc5 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Sat, 28 Feb 2015 00:11:55 -0700 Subject: [PATCH 2/2] Adjust contrib/mkimage/debootstrap PATH handling to be more robust Instead of applying it only for the final `chroot`, this adds a chroot helper function to apply it appropriately for every chroot, including making sure that we find `chroot` in our current host `PATH` in case it's in a strange place. Signed-off-by: Andrew "Tianon" Page --- contrib/mkimage/debootstrap | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/contrib/mkimage/debootstrap b/contrib/mkimage/debootstrap index 83f17e0c4e..db35d3177a 100755 --- a/contrib/mkimage/debootstrap +++ b/contrib/mkimage/debootstrap @@ -15,6 +15,16 @@ done suite="$1" shift +# get path to "chroot" in our current PATH +chrootPath="$(type -P chroot)" +rootfs_chroot() { + # "chroot" doesn't set PATH, so we need to set it explicitly to something our new debootstrap chroot can use appropriately! + + # set PATH and chroot away! + PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' \ + "$chrootPath" "$rootfsDir" "$@" +} + # allow for DEBOOTSTRAP=qemu-debootstrap ./mkimage.sh ... : ${DEBOOTSTRAP:=debootstrap} @@ -41,13 +51,13 @@ chmod +x "$rootfsDir/usr/sbin/policy-rc.d" # prevent upstart scripts from running during install/update ( set -x - chroot "$rootfsDir" dpkg-divert --local --rename --add /sbin/initctl + rootfs_chroot dpkg-divert --local --rename --add /sbin/initctl cp -a "$rootfsDir/usr/sbin/policy-rc.d" "$rootfsDir/sbin/initctl" sed -i 's/^exit.*/exit 0/' "$rootfsDir/sbin/initctl" ) # shrink a little, since apt makes us cache-fat (wheezy: ~157.5MB vs ~120MB) -( set -x; chroot "$rootfsDir" apt-get clean ) +( set -x; rootfs_chroot apt-get clean ) # this file is one APT creates to make sure we don't "autoremove" our currently # in-use kernel, which doesn't really apply to debootstraps/Docker images that @@ -189,10 +199,9 @@ fi ( set -x - export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin # make sure we're fully up-to-date - chroot "$rootfsDir" bash -c 'apt-get update && apt-get dist-upgrade -y' + rootfs_chroot sh -xc 'apt-get update && apt-get dist-upgrade -y' # delete all the apt list files since they're big and get stale quickly rm -rf "$rootfsDir/var/lib/apt/lists"/*