forked from anarsoul/linux-build
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdo_chroot.sh
More file actions
executable file
·36 lines (31 loc) · 753 Bytes
/
do_chroot.sh
File metadata and controls
executable file
·36 lines (31 loc) · 753 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
set -e
set -x
if [ "$(id -u)" -ne "0" ]; then
echo "This script requires root."
exit 1
fi
cleanup() {
if [ -e "$DEST/proc/cmdline" ]; then
umount "$DEST/proc"
fi
if [ -d "$DEST/sys/kernel" ]; then
umount "$DEST/sys"
fi
umount "$DEST/dev" || true
umount "$DEST/tmp" || true
}
trap cleanup EXIT
DEST=rootfs-20180912
mount -o bind /tmp "$DEST/tmp"
mount -o bind /dev "$DEST/dev"
chroot "$DEST" mount -t proc proc /proc
chroot "$DEST" mount -t sysfs sys /sys
#chroot "$DEST" mv /etc/resolv.conf /etc/resolv.conf.dist
cp /etc/resolv.conf $DEST/etc/resolv.conf
chroot "$DEST" $@
#chroot "$DEST" mv /etc/resolv.conf.dist /etc/resolv.conf
chroot "$DEST" umount /sys
chroot "$DEST" umount /proc
umount "$DEST/dev"
umount "$DEST/tmp"