Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 30 lines (28 sloc) 1.23 KB
# Usage: superchroot destdir [cmd [args...]]
# Like chroot, but fixes up a few things you probably want
# in order to run programs in the chroot (which might e.g.
# be the root filesystem of a different Linux distro you
# have installed in a separate partition). Requires root
# privileges.
# I knew this script was pretty decent for me in 2010;
# Linux plumbing might have changed a bit since then.
# Look and see whether you really want to do
# every step this script does.
set -eu
target="$(readlink -f "$1")"; shift
mountpoint -q "$target/dev" || mount -o bind /dev "$target/dev"
mountpoint -q "$target/dev/pts" || mount -t devpts devpts "$target/dev/pts"
mountpoint -q "$target/proc" || mount -t proc mynone "$target/proc"
mountpoint -q "$target/sys" || mount -o bind /sys "$target/sys"
#hmm, this is destructive if the target uses resolv.conf
#as static configuration (unlike NetworkManager):
cp /etc/resolv.conf "$target/etc/resolv.conf"
# since sudo and env both change $PATH, we have to find these tools with
# the host system path beforehand.
env="$(which env)"
chroot="$(which chroot)"
exec sudo -i "$env" -i TERM="$TERM" SHELL=/bin/bash PATH=/usr/sbin:/usr/bin:/sbin:/bin "$chroot" "$target" "$@"