I need to be able to provide the /bin and /lib directories inside a chroot jail so that programs can dynamically link properly.

Is there a way to accomplish this without making a copy of the /bin and /lib dirs to the chroot jail?

I've tried symlinks, and they don't work from inside chroot jails, and directories can not be hardlinked.

3 Answers 3


You could use mount to remount the directories you need in your jail:

# mount --bind /bin /chroot/bin
# mount --bind /lib /chroot/lib
# chroot /chroot

For use in /etc/fstab:

/bin /chroot/bin none bind
/lib /chroot/lib none bind


  • 2
    Thanks a lot. Linux just keeps getting better and better the more I play with it :p Dec 17, 2010 at 2:17
  • I'm glad it worked out well! Cheers!
    – jgr
    Dec 17, 2010 at 11:00

If you didn't want to mount the directories as jgr said, you can use cp to recursivly copy directories and create hardlinks for all files:

cp -alf /bin /chroot/bin
cp -alf /lib /chroot/lib
chroot /chroot

This way your chroot's /bin and /lib can have slightly different structure / contents than the main directories.

  • 1
    Good idea, but if the /chroot is on a different device this won't work. You can't hardlink across devices.
    – AllenKll
    May 6, 2016 at 18:23

copy_file_and_dependencies() {
    DEPENDENCIES="$(ldd "$PROGRAM" | awk '{ print $3 }' | grep -v '(' | grep -v 'not a dynamic executable')"

    mkdir -p "${JAIL}$(dirname $PROGRAM)"
    cp -Lv "$PROGRAM" "${JAIL}${PROGRAM}"

    for f in $DEPENDENCIES; do
        mkdir -p "${JAIL}$(dirname $f)"
        cp -Lv "$f" "${JAIL}${f}"

export -f copy_file_and_dependencies

copy_file_and_dependencies /etc/ld.so.cache
copy_file_and_dependencies /bin/sh
# ...
  • 2
    The intent of the question seems to be to provide access to the existing files rather than copying them into the chroot.
    – psusi
    May 18, 2015 at 2:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .