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
12 COMMAND_="" # command to start in chroot
24 Usage: "$PROG_NAME_" NEWROOT [COMMAND....]
26 $PROG_NAME__ is a chroot wrapper with proc/sys/pts/dev filesystem handling
34 if [[ $MOUNTED_ == "" ]]; then
35 MOUNTED_="$to_append_"
37 MOUNTED_="$MOUNTED_ $to_append_"
43 local type_="$1" # type _or_ src
49 if [[ $options_ == "--bind" ]]; then
50 all_options_="--bind $type_"
52 all_options_="-t $type_ none"
54 mount $all_options_ "${DEST_}/$dest_" && storeMounts "$dest_"
59 for i in $MOUNTED_; do
69 while getopts "h" opt; do
71 h) printUsage; exit 0 ;;
72 ?) printUsage; exit 64 ;;
75 shift $(($OPTIND - 1))
78 die "Wrong number of arguments."
84 if [ ! -d "$DEST_" ]; then
85 die "Target chroot does not exist: $DEST_"
91 mountit "/dev" "dev" "--bind"
92 chroot "$DEST_" $COMMAND_