2 # Filename: grml-chroot
3 # Purpose: Program to chroot into another system
4 # Authors: grml-team (grml.org), (c) Michael Gebetsroither <gebi@grml.org>
5 # Bug-Reports: see http://grml.org/bugs/
6 # License: This file is licensed under the GPL v2.
7 ################################################################################
9 PROG_NAME_=$(basename $0)
11 MOUNTED_="" # all mounted destinations
23 Usage: "$PROG_NAME_" NEWROOT [COMMAND....]
25 $PROG_NAME_ is a chroot wrapper with proc/sys/pts/dev filesystem handling
33 if [[ $MOUNTED_ == "" ]]; then
34 MOUNTED_="$to_append_"
36 MOUNTED_="$MOUNTED_ $to_append_"
42 local type_="$1" # type _or_ src
48 if [[ $options_ == "--bind" ]]; then
49 all_options_="--bind $type_"
51 all_options_="-t $type_ none"
53 mount $all_options_ "${DEST_}/$dest_" && storeMounts "$dest_"
58 for i in $MOUNTED_; do
68 while getopts "h" opt; do
70 h) printUsage; exit 0 ;;
71 ?) printUsage; exit 64 ;;
74 shift $(($OPTIND - 1))
78 die "Wrong number of arguments."
83 if [ ! -d "$DEST_" ]; then
84 die "Target chroot does not exist: $DEST_"
90 mountit "/dev" "dev" "--bind"