-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart_chroot_real.sh
88 lines (65 loc) · 1.68 KB
/
start_chroot_real.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
if [ $UID -ne 0 ] ; then
#echo $UID
#sudo bash ${BASH_SOURCE[0]}
echo "need root , start as root or sudo"
exit 0
fi
if [ ! -e proc ] ; then
echo "directory proc not found"
exit 1
fi
function dir_mount {
se="$(pwd)/$1 "
#echo $se
grep "$se" /proc/mounts > /dev/null
if [ ! 0 -eq $? ] ; then
echo -e "\033[01;32m *\033[00m mount /$1 ( $2 )"
mount -t $2 none $1
fi
}
function dir_mount_opt {
grep "$(pwd)/$1" /proc/mounts > /dev/null
if [ ! 0 -eq $? ] ; then
echo -e "\033[01;32m *\033[00m mount /$1 ( $2 , $3)"
mount -o $3 -t $2 none $1
fi
}
echo -e "\n\033[01;32m *\033[00m init chroot\n"
mount --bind $(pwd) $(pwd)
dir_mount 'proc' 'proc'
dir_mount 'sys' 'sysfs'
dir_mount 'dev' 'devtmpfs'
dir_mount_opt 'dev/shm' 'tmpfs' 'mode=1777'
dir_mount_opt 'dev/pts' 'devpts' 'gid=5'
dir_mount 'run' 'tmpfs'
dir_mount 'var/tmp' 'tmpfs'
echo ""
if [[ -L "$(pwd)/etc/resolv.conf" ]]; then
dirname="none"
dest=$(readlink etc/resolv.conf)
#echo $dest
if [[ "$dest" == "../"* ]] ; then
dirname=$(dirname $dest | cut -d'/' -f2-)
file=$(basename $dest)
mkdir -p $dirname
dest=$dirname"/"$file
cat /etc/resolv.conf > $dest
echo -e "\033[01;32m *\033[00m $dest created"
else
dirname=$(pwd)$(dirname $dest)
if [ ! -e $dirname ] ; then
mkdir $dirname
fi
cat /etc/resolv.conf > $(pwd)$dest
echo -e "\033[01;32m *\033[00m $dest created"
fi
if [[ $dirname == "none" ]] ; then
echo -e "\033[01;31m *\033[00m $dest not created"
fi
else
cat /etc/resolv.conf > $(pwd)/etc/resolv.conf
echo -e "\033[01;32m *\033[00m created /etc/resolv.conf"
fi
echo -e "\n\033[01;32m *\033[00m starting chroot\n"
chroot .