Guest User

Untitled

a guest
Jul 21st, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. #######################################################
  4. # This is a simple script to create a chroot
  5. # You'll have to run
  6. #
  7. # chroot /path/to/chroot </bin/bash>
  8. #
  9. # after this script exits.
  10. # written by Norbert Varzariu <loomsen@googlemail.com>
  11. #######################################################
  12. # has to be run as root, so lets check
  13. [[ $UID == 0 ]] && : || (echo "you have to be root";exit 1)
  14.  
  15. _MNTPART=
  16. _CHROOTDIR=
  17.  
  18. set -x
  19.  
  20. function mount-defaults
  21. {
  22. mount "$_MNTPART" "$_CHROOTDIR"
  23. mount -t proc none $_CHROOTDIR/proc
  24. mount -t sysfs none $_CHROOTDIR/sys
  25. mount --bind /dev $_CHROOTDIR/dev
  26. mount --bind /dev/pts $_CHROOTDIR/dev/pts
  27. mount --bind /dev/shm $_CHROOTDIR/dev/shm
  28. }
  29.  
  30. function unchroot
  31. {
  32. umount $_CHROOTDIR/dev/shm
  33. umount $_CHROOTDIR/dev/pts
  34. umount $_CHROOTDIR/dev
  35. umount $_CHROOTDIR/sys
  36. umount $_CHROOTDIR/proc
  37. umount $_CHROOTDIR
  38. }
  39.  
  40. if [ "$1" == "" ]; then
  41. echo "usage: \"$0\" /path/to/partition <path-to-chroot>"
  42. exit $?
  43. else
  44. case "$1" in
  45. /dev/[sh]d* )
  46. _MNTPART="$1"
  47. if [ "$2" == "" ]; then _CHROOTDIR="/chroot"; else _CHROOTDIR="$2";fi
  48. export _CHROOTDIR _MNTPART
  49. ;;
  50. "clean"|"-c"|"--clean" )
  51. [[ "$2" != "" ]] && _CHROOTDIR="$2" || _CHROOTDIR="/chroot"
  52. unchroot
  53. exit $?
  54. ;;
  55. esac
  56. mount-defaults
  57. unset _CHROOTDIR _MNTPART
  58. fi
  59.  
  60. exit $?
Add Comment
Please, Sign In to add comment