This repository was archived by the owner on Dec 22, 2017. It is now read-only.
forked from haotseng/docker_armhf_debian
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen_debian_armhf_rootfs.sh
More file actions
executable file
·166 lines (127 loc) · 3.58 KB
/
gen_debian_armhf_rootfs.sh
File metadata and controls
executable file
·166 lines (127 loc) · 3.58 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/bash
#
# build armhf rootfs for docker.
#
THIS_SCRIPT=`echo $0 | sed "s/^.*\///"`
SCRIPT_PATH=`echo $0 | sed "s/\/${THIS_SCRIPT}$//"`
real_pwd=`pwd`
real_pwd=`realpath ${real_pwd}`
output_dir=${real_pwd}/output
work_dir=${real_pwd}/_build_tmp
if [ $EUID -ne 0 ]; then
echo "this tool must be run as root"
exit_process 1
fi
if [ -d $work_dir ]; then
echo "Working directory $work_dir exist, please remove it before run this script"
exit 1
fi
mkdir -p $work_dir
mkdir -p $output_dir
#
# Debian parameters
#
deb_mirror="http://ftp.halifax.rwth-aachen.de/debian" # Debian mirror nearby
deb_release="stretch"
rootfs="${work_dir}/rootfs"
architecture="armhf"
if [ "$deb_local_mirror" == "" ]; then
deb_local_mirror=$deb_mirror
fi
#
# 1st stage
#
mkdir -p $rootfs
debootstrap --foreign --arch $architecture --variant=minbase $deb_release $rootfs $deb_local_mirror
cp /usr/bin/qemu-arm-static ${rootfs}/usr/bin/
#
# 2nd stage
#
LANG=C chroot $rootfs /debootstrap/debootstrap --second-stage
cat << EOF > ${rootfs}/etc/apt/sources.list
deb $deb_local_mirror $deb_release main contrib non-free
EOF
echo "bsms" > ${rootfs}/etc/hostname
cat << EOF > ${rootfs}/etc/resolv.conf
nameserver 85.214.20.141 # https://digitalcourage.de/support/zensurfreier-dns-server
EOF
cat << EOF > ${rootfs}/etc/network/interfaces
auto lo
iface lo inet loopback
EOF
#
# 3rd stage
#
export MALLOC_CHECK_=0 # workaround for LP: #520465
export LC_ALL=C
export DEBIAN_FRONTEND=noninteractive
mount -t proc proc ${rootfs}/proc
mount -o bind /dev/ ${rootfs}/dev/
mount -o bind /dev/pts ${rootfs}/dev/pts
cat << EOF > ${rootfs}/debconf.set
console-common console-data/keymap/policy select Select keymap from full list
console-common console-data/keymap/full select en-latin1-nodeadkeys
EOF
cat << EOF > ${rootfs}/third-stage
#!/bin/bash
rm -rf /debootstrap
debconf-set-selections /debconf.set
rm -f /debconf.set
apt-get update
apt-get -y install locales console-common
sed -i -e 's/KERNEL\!=\"eth\*|/KERNEL\!=\"/' /lib/udev/rules.d/75-persistent-net-generator.rules
rm -f /etc/udev/rules.d/70-persistent-net.rules
rm -f /third-stage
EOF
chmod +x ${rootfs}/third-stage
LANG=C chroot ${rootfs} /third-stage
#
# Manual Configuration Within the chroot
#
#LANG=C chroot ${rootfs}
#{make additional changes within the chroot}
#exit
#
# Cleanup
#
cat << EOF > ${rootfs}/cleanup
#!/bin/bash
rm -rf /root/.bash_history
apt-get clean -y
apt-get autoclean -y
apt-get autoremove -y
rm -f cleanup
EOF
chmod +x ${rootfs}/cleanup
LANG=C chroot ${rootfs} /cleanup
#
# Reduce size by delete some files
#
mkdir -p ${work_dir}/tmp
cp -R ${rootfs}/usr/share/locale/en\@* ${work_dir}/tmp/ && rm -rf ${rootfs}/usr/share/locale/* && mv ${work_dir}/tmp/en\@* ${rootfs}/usr/share/locale/
rm -rf ${rootfs}/var/cache/debconf/*-old && rm -rf ${rootfs}/var/lib/apt/lists/* && rm -rf ${rootfs}/usr/share/doc/*
sync
sleep 3
# The 'qemu-arm-static' will occurpy some device resource. It will cause the 'umount' don't work.
# Because the ${rootfs}/dev/ is occupied by qemu-arm-static.
# So, before umount all device, we must kill the 'qemu-arm-static' process.
ps -ef | grep qemu-arm-static | awk '{print $2}' | xargs kill -9
sleep 2
umount ${rootfs}/proc
sleep 2
umount ${rootfs}/dev/pts
sleep 2
umount ${rootfs}/dev/
sleep 2
#
# If you want to let x86 system execute armhf docker container, you should keep qemu-arm-static in the docker image
#
#rm -rf ${rootfs}/usr/bin/qemu-arm-static
#sleep 2
# Generate rootfs tar-ball
sync
rm -rf $output_dir/rootfs.tar.gz
( cd ${rootfs}; tar -zcvf ${output_dir}/rootfs.tar.gz *; )
# Remove work dir
rm -rf ${work_dir}
echo "Finished !!"