-
-
Notifications
You must be signed in to change notification settings - Fork 50
/
enter-chroot.sh
executable file
·47 lines (35 loc) · 1.16 KB
/
enter-chroot.sh
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
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env bash
# Root rights are required
if [ $EUID != 0 ]; then
echo "Root rights are required!"
exit 1
fi
script_dir="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
bootstrap="${script_dir}"/root.x86_64
if [ ! -d "${bootstrap}" ]; then
echo "Bootstrap is missing"
exit 1
fi
# First unmount just in case
umount -Rl "${bootstrap}"
mount --bind "${bootstrap}" "${bootstrap}"
mount -t proc /proc "${bootstrap}"/proc
mount --bind /sys "${bootstrap}"/sys
mount --make-rslave "${bootstrap}"/sys
mount --bind /dev "${bootstrap}"/dev
mount --bind /dev/pts "${bootstrap}"/dev/pts
mount --bind /dev/shm "${bootstrap}"/dev/shm
mount --make-rslave "${bootstrap}"/dev
rm -f "${bootstrap}"/etc/resolv.conf
cp /etc/resolv.conf "${bootstrap}"/etc/resolv.conf
mkdir -p "${bootstrap}"/run/shm
echo "Entering chroot"
echo "To exit the chroot, perform the \"exit\" command"
chroot "${bootstrap}" /usr/bin/env LANG=en_US.UTF-8 TERM=xterm PATH="/bin:/sbin:/usr/bin:/usr/sbin" /bin/bash
echo "Exiting chroot"
umount -l "${bootstrap}"
umount "${bootstrap}"/proc
umount "${bootstrap}"/sys
umount "${bootstrap}"/dev/pts
umount "${bootstrap}"/dev/shm
umount "${bootstrap}"/dev