util/sockroot

rootmount.sh in master
Repositories | Summary | Log | Files

rootmount.sh (612B) download


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