chroot_ln_file.sh
#!/bin/bash
mkdir -p $(dirname $2/$1)
ln $1 $2/$1 &> /dev/null
ori=$(readlink $1)
if [ -n "$ori" ]; then
real=$(realpath -s $ori)
if [[ "$real" == "$ori" ]]; then
$0 $real $2
else
$0 $(dirname $1)/$ori $2
fi
fi
chroot_lnso.sh
#!/bin/bash
ldd $1 | sed 's/^\s*//g' | sed 's/.* => //g' | sed 's/ (0x.*)//g' | grep '^/' | xargs -i $(dirname $0)/chroot_ln_file.sh {} $2
用法:
sudo bash chroot_ln_file.sh /bin/bash /var/chroot
sudo bash chroot_lnso.sh /bin/bash /var/chroot