Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # remount root rw
  4. mount -o remount,rw /
  5.  
  6. # prapare target paths
  7. mkdir -p /chroot
  8. mkdir -p /chroot/{bin,boot,dev,etc,home,lib,opt,proc,root,run,sbin,sys,tmp,usr,var}
  9.  
  10. # mount special filesystems
  11. mount -t proc proc /chroot/proc
  12. mount --rbind /sys /chroot/sys
  13. mount --rbind /dev /chroot/dev
  14.  
  15. # bind rw directories
  16. for f in {etc,var}; do mount --rbind /${f}_org /chroot/$f; done
  17.  
  18. # bind remaining directories
  19. for f in {bin,boot,home,lib,opt,root,run,sbin,tmp,usr}; do mount --rbind /$f /chroot/$f; done
  20.  
  21. # chroot
  22. echo "Note: /boot is still mounted read-only, remount to read-write if needed."
  23. echo -e "\e[33mYou are now in read-write chroot. Use CTRL+D when done to exit chroot and mount read-only again.\e[39m"
  24. chroot /chroot /usr/bin/env PS1="(rw) \u@\h:\w\$ " /bin/bash --noprofile -l
  25.  
  26. # unmount mounts
  27. for f in /chroot/{bin,boot,dev,etc,home,lib,opt,proc,root,run,sbin,sys,tmp,usr,var}; do
  28. umount -l $f
  29. done
  30.  
  31. sleep 1
  32.  
  33. # remount read-only again
  34. echo -e "\e[32mChroot left, re-mounting read-only again.\e[39m"
  35. mount -o remount,ro /
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement