On Wed, Aug 30, 2017 at 3:16 PM, Tony Nelson tonynelson@georgeanelson.com wrote:
I have an old CentOS5 that I chroot into. On my old f20 box, PATH included /bin, but now on f26 it does not. I don't understand how this could happen; I would think that PATH is set inside the chroot by the shell. How does PATH get set? I see how it is modified and have fixed my issue, provided I use a login shell.
It's because chroot keeps PATH set. So if your pre-chroot PATH doesn't include "/sbin" or "/bin", they won't be in the chrooted PATH:
root@fedraw ~ # echo $PATH /usr/sbin:/usr/bin
root@fedraw ~ # chroot /bb ./busybox sh
\u@\h \w # echo $PATH /usr/sbin:/usr/bin
\u@\h \w # exit
root@fedraw ~ # PATH=/sbin:/bin:/usr/sbin:/usr/bin chroot /bb ./busybox sh
\u@\h \w # echo $PATH /sbin:/bin:/usr/sbin:/usr/bin
\u@\h \w # exit
root@fedraw ~ #
If you use a login shell (eg, "chroot /bb bash -l" instead of "chroot /bb bash"), the dotfiles that will be sourced will set the appropriate chrooted PATH.