Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # remount root rw
- mount -o remount,rw /
- # prapare target paths
- mkdir -p /chroot
- mkdir -p /chroot/{bin,boot,dev,etc,home,lib,opt,proc,root,run,sbin,sys,tmp,usr,var}
- # mount special filesystems
- mount -t proc proc /chroot/proc
- mount --rbind /sys /chroot/sys
- mount --rbind /dev /chroot/dev
- # bind rw directories
- for f in {etc,var}; do mount --rbind /${f}_org /chroot/$f; done
- # bind remaining directories
- for f in {bin,boot,home,lib,opt,root,run,sbin,tmp,usr}; do mount --rbind /$f /chroot/$f; done
- # chroot
- echo "Note: /boot is still mounted read-only, remount to read-write if needed."
- 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"
- chroot /chroot /usr/bin/env PS1="(rw) \u@\h:\w\$ " /bin/bash --noprofile -l
- # unmount mounts
- for f in /chroot/{bin,boot,dev,etc,home,lib,opt,proc,root,run,sbin,sys,tmp,usr,var}; do
- umount -l $f
- done
- sleep 1
- # remount read-only again
- echo -e "\e[32mChroot left, re-mounting read-only again.\e[39m"
- mount -o remount,ro /
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement