sockroot

Login to a secured (chrooted) shell via a UNIX-socket
Log | Files | Refs

rootmount.sh (612B)


      1 #!/bin/sh -e
      2 # xchroot DIR [CMD...] - chroot into a Void (or other Linux) installation
      3 
      4 fail() {
      5 	printf '%s\n' "$1" 1>&2
      6 	exit 1
      7 }
      8 
      9 if [ "$(id -u)" -ne 0 ]; then
     10 	fail 'xchroot needs to run as root'
     11 fi
     12 
     13 CHROOT=$1; shift
     14 
     15 [ -d "$CHROOT" ] || fail 'not a directory'
     16 [ -d "$CHROOT/dev" ] || fail 'no /dev in chroot'
     17 [ -d "$CHROOT/proc" ] || fail 'no /proc in chroot'
     18 [ -d "$CHROOT/sys" ] || fail 'no /sys in chroot'
     19 
     20 for _fs in dev proc sys; do
     21 	mount --rbind "/$_fs" "$CHROOT/$_fs"
     22 	mount --make-rslave "$CHROOT/$_fs"
     23 done
     24 
     25 touch "$CHROOT/etc/resolv.conf"
     26 mount --bind /etc/resolv.conf "$CHROOT/etc/resolv.conf"
     27