Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers 2

up vote 11 down vote accepted

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

Cheers!

share|improve this answer
1  
Thanks a lot. Linux just keeps getting better and better the more I play with it :p –  Charlie Somerville Dec 17 '10 at 2:17
    
I'm glad it worked out well! Cheers! –  jgr Dec 17 '10 at 11:00
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.