forked from pimusicbox/pimusicbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_rpi_sd_card.sh
195 lines (153 loc) · 4.71 KB
/
build_rpi_sd_card.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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/bin/bash
# build your own Raspberry Pi SD card
#
# by Klaus M Pfeiffer, http://blog.kmp.or.at/ , 2012-06-24
# 2012-06-24
# just checking for how partitions are called on the system (thanks to Ricky Birtles and Luke Wilkinson)
# using http.debian.net as debian mirror, see http://rgeissert.blogspot.co.at/2012/06/introducing-httpdebiannet-debians.html
# tested successfully in debian squeeze and wheezy VirtualBox
# added hint for lvm2
# added debconf-set-selections for kezboard
# corrected bug in writing to etc/modules
# 2012-06-16
# improoved handling of local debian mirror
# added hint for dosfstools (thanks to Mike)
# added vchiq & snd_bcm2835 to /etc/modules (thanks to Tony Jones)
# take the value fdisk suggests for the boot partition to start (thanks to Mike)
# 2012-06-02
# improoved to directly generate an image file with the help of kpartx
# added deb_local_mirror for generating images with correct sources.list
# 2012-05-27
# workaround for https://github.com/Hexxeh/rpi-update/issues/4 just touching /boot/start.elf before running rpi-update
# 2012-05-20
# back to wheezy, http://bugs.debian.org/672851 solved, http://packages.qa.debian.org/i/ifupdown/news/20120519T163909Z.html
# 2012-05-19
# stage3: remove eth* from /lib/udev/rules.d/75-persistent-net-generator.rules
# initial
# you need at least
# apt-get install binfmt-support qemu qemu-user-static debootstrap kpartx lvm2 dosfstools
deb_mirror="http://http.debian.net/debian"
#deb_local_mirror="http://debian.kmp.or.at:3142/debian"
bootsize="64M"
deb_release="wheezy"
device=$1
buildenv="/root/rpi"
rootfs="${buildenv}/rootfs"
bootfs="${rootfs}/boot"
mydate=`date +%Y%m%d`
if [ "$deb_local_mirror" == "" ]; then
deb_local_mirror=$deb_mirror
fi
image=""
if [ $EUID -ne 0 ]; then
echo "this tool must be run as root"
exit 1
fi
if ! [ -b $device ]; then
echo "$device is not a block device"
exit 1
fi
if [ "$device" == "" ]; then
echo "no block device given, just creating an image"
mkdir -p $buildenv
image="${buildenv}/rpi_basic_${deb_release}_${mydate}.img"
dd if=/dev/zero of=$image bs=1MB count=1000
device=`losetup -f --show $image`
echo "image $image created and mounted as $device"
else
dd if=/dev/zero of=$device bs=512 count=1
fi
fdisk $device << EOF
n
p
1
+$bootsize
t
c
n
p
2
w
EOF
if [ "$image" != "" ]; then
losetup -d $device
device=`kpartx -va $image | sed -E 's/.*(loop[0-9])p.*/\1/g' | head -1`
device="/dev/mapper/${device}"
bootp=${device}p1
rootp=${device}p2
else
if ! [ -b ${device}1 ]; then
bootp=${device}p1
rootp=${device}p2
if ! [ -b ${bootp} ]; then
echo "uh, oh, something went wrong, can't find bootpartition neither as ${device}1 nor as ${device}p1, exiting."
exit 1
fi
else
bootp=${device}1
rootp=${device}2
fi
fi
mkfs.vfat $bootp
mkfs.ext4 $rootp
mkdir -p $rootfs
mount $rootp $rootfs
cd $rootfs
debootstrap --foreign --arch armel $deb_release $rootfs $deb_local_mirror
cp /usr/bin/qemu-arm-static usr/bin/
LANG=C chroot $rootfs /debootstrap/debootstrap --second-stage
mount $bootp $bootfs
echo "deb $deb_local_mirror $deb_release main contrib non-free
" > etc/apt/sources.list
echo "dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait" > boot/cmdline.txt
echo "proc /proc proc defaults 0 0
/dev/mmcblk0p1 /boot vfat defaults 0 0
" > etc/fstab
echo "raspberrypi" > etc/hostname
echo "auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
" > etc/network/interfaces
echo "vchiq
snd_bcm2835
" >> etc/modules
echo "console-common console-data/keymap/policy select Select keymap from full list
console-common console-data/keymap/full select de-latin1-nodeadkeys
" > debconf.set
echo "#!/bin/bash
debconf-set-selections /debconf.set
rm -f /debconf.set
apt-get update
apt-get -y install git-core binutils ca-certificates
wget http://goo.gl/1BOfJ -O /usr/bin/rpi-update
chmod +x /usr/bin/rpi-update
mkdir -p /lib/modules/3.1.9+
touch /boot/start.elf
rpi-update
apt-get -y install locales console-common ntp openssh-server less vim
echo \"root:raspberry\" | chpasswd
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
" > third-stage
chmod +x third-stage
LANG=C chroot $rootfs /third-stage
echo "deb $deb_mirror $deb_release main contrib non-free
" > etc/apt/sources.list
echo "#!/bin/bash
aptitude update
aptitude clean
apt-get clean
rm -f cleanup
" > cleanup
chmod +x cleanup
LANG=C chroot $rootfs /cleanup
cd
umount $bootp
umount $rootp
if [ "$image" != "" ]; then
kpartx -d $image
echo "created image $image"
fi
echo "done."