Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- #######################################################
- # This is a simple script to create a chroot
- # You'll have to run
- #
- # chroot /path/to/chroot </bin/bash>
- #
- # after this script exits.
- # written by Norbert Varzariu <loomsen@googlemail.com>
- #######################################################
- # has to be run as root, so lets check
- [[ $UID == 0 ]] && : || (echo "you have to be root";exit 1)
- _MNTPART=
- _CHROOTDIR=
- set -x
- function mount-defaults
- {
- mount "$_MNTPART" "$_CHROOTDIR"
- mount -t proc none $_CHROOTDIR/proc
- mount -t sysfs none $_CHROOTDIR/sys
- mount --bind /dev $_CHROOTDIR/dev
- mount --bind /dev/pts $_CHROOTDIR/dev/pts
- mount --bind /dev/shm $_CHROOTDIR/dev/shm
- }
- function unchroot
- {
- umount $_CHROOTDIR/dev/shm
- umount $_CHROOTDIR/dev/pts
- umount $_CHROOTDIR/dev
- umount $_CHROOTDIR/sys
- umount $_CHROOTDIR/proc
- umount $_CHROOTDIR
- }
- if [ "$1" == "" ]; then
- echo "usage: \"$0\" /path/to/partition <path-to-chroot>"
- exit $?
- else
- case "$1" in
- /dev/[sh]d* )
- _MNTPART="$1"
- if [ "$2" == "" ]; then _CHROOTDIR="/chroot"; else _CHROOTDIR="$2";fi
- export _CHROOTDIR _MNTPART
- ;;
- "clean"|"-c"|"--clean" )
- [[ "$2" != "" ]] && _CHROOTDIR="$2" || _CHROOTDIR="/chroot"
- unchroot
- exit $?
- ;;
- esac
- mount-defaults
- unset _CHROOTDIR _MNTPART
- fi
- exit $?
Add Comment
Please, Sign In to add comment