-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathcreate_image
executable file
·446 lines (388 loc) · 14.6 KB
/
create_image
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
#!/bin/bash
# Last update: 2015-06-21
# *****************************************************
# !! REMEMBER TO SET PARAMETERS IN FILE "second-stage *
# *****************************************************
if [ "$(id -u)" != "0" ]; then
echo "Script must be run as root !"
exit 0
fi
echo ""
date
echo -e "\033[36m======================================================="
echo -e "Creating Ubuntu/Debian SD Card instalation for OrangePI"
echo -e "=======================================================\033[37m"
echo ""
_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
cd $_DIR
. params.sh
#===================================================================
# ============================================
if [ "${distro}" = "" ]; then
echo "Distribution must be specified."
exit 0
fi
if [ "${repo}" = "" ]; then
echo "Repository must be specified."
exit 0
fi
# ============================================
#===================================================================
_excode=0
# **** show progress *******
proc_wait() {
spin='-\|/'
i=0
while kill -0 $1 2>/dev/null
do
i=$(( (i+1) %4 ))
printf "\r$2 ${spin:$i:1}"
sleep .1
done
_excode=$?
if [ $_excode -eq 0 ]
then
printf "\rOK. \n"
else
printf "\rERROR. \n"
fi
}
# **************************
if [ "${_format}" = "btrfs" ] ; then
_mntopt="-o compress-force=lzo"
else
_mntopt=""
fi
# ===================
. format.sh
# ===================
if [ "${odir}" = "" ] || [ "${bootdir}" = "" ]; then
echo "FATAL ERROR."
exit 1
fi
# ===================
# Prepare directories
# ===================
if [ ! "${_boot_on_ext4}" = "yes" ] ; then
if [ ! -d $bootdir ]; then
mkdir -p $bootdir
fi
rm $bootdir/* > /dev/null 2>&1
sync
umount $bootdir > /dev/null 2>&1
fi
if [ ! -d $odir ]; then
mkdir -p $odir
fi
rm -rf $odir/* > /dev/null 2>&1
sync
umount $odir > /dev/null 2>&1
sleep 1
# ===========================================
# IF USING SD CARD OR IMAGE, MOUNT PARTITIONS
# ===========================================
if [ ! "${sdcard}" = "" ]; then
echo ""
echo "Mounting SD Card partitions..."
if [ ! "${_boot_on_ext4}" = "yes" ] ; then
if ! mount ${sdcard}1 $bootdir; then
echo "ERROR mounting partitions..."
exit 1
fi
if ! mount ${_mntop} ${sdcard}2 $odir; then
echo "ERROR mounting partitions..."
umount $bootdir
exit 1
fi
echo "SD Card partitions mounted to $odir & $bootdir"
else
if ! mount ${_mntop} ${sdcard}1 $odir; then
echo "ERROR mounting partitions..."
if [ ! "${_boot_on_ext4}" = "yes" ] ; then
umount $bootdir
fi
exit 1
fi
echo "SD Card partition mounted to $odir"
fi
fi
#===================================================================================================================
# ========================
# DEBOOTSTRAP LINUX DISTRO
# ========================
echo ""
touch $odir/_$distro
echo "DEBOOTSTRAP, FIRST STAGE"
if [ "${raspbian}" = "yes" ] ; then
debootstrap --arch armhf --foreign --no-check-gpg --include=ca-certificates --verbose --include=wget ${distro} $odir $repo > /dev/null 2>&1 &
else
debootstrap --arch armhf --foreign --verbose --variant=minbase --include=wget ${distro} $odir $repo > /dev/null 2>&1 &
fi
pid=$!
proc_wait $pid "please wait"
if [ $_excode -ne 0 ]; then
echo "ERROR IN DEBOOTSTRAP!"
exit 0
fi
# ***************************
# ** CREATE NEW sources.list:
# ***************************
echo "Creating \"sources.list\""
case ${distro} in
trusty|utopic|precise|vivid|wily*)
cat > $odir/sources.list << _EOF_
deb $repo/ $distro main restricted universe multiverse
deb-src $repo/ $distro main restricted universe multiverse
deb $repo/ $distro-updates main restricted universe multiverse
deb-src $repo/ $distro-updates main restricted universe multiverse
deb $repo/ $distro-security main restricted universe multiverse
deb $repo/ $distro-backports main restricted universe multiverse
_EOF_
;;*)
if [ "${raspbian}" = "yes" ] ; then
cat > $odir/sources.list << _EOF_
deb $repo/ $distro main contrib non-free
deb-src $repo/ $distro main contrib non-free
_EOF_
else
cat > $odir/sources.list << _EOF_
deb $repo/ $distro main contrib non-free
deb-src $repo/ $distro main contrib non-free
deb $repo/ $distro-updates main contrib non-free
deb-src $repo/ $distro-updates main contrib non-free
deb $repo/ $distro-backports main contrib non-free
deb-src $repo/ $distro-backports main contrib non-free
_EOF_
fi
;;esac
#if [ ! "${ONLY_BASE}" = "yes" ] ; then
# echo "deb http://debian.xypron.de/ unstable/all/" >> $odir/sources.list
# echo "deb http://debian.xypron.de/ unstable/armhf/" >> $odir/sources.list
#fi
# ==============================================
# Make necessary directories and copy some files
# ==============================================
mkdir -p $odir/etc/default > /dev/null 2>&1
if [ ! "${_boot_on_ext4}" = "yes" ] ; then
mkdir -p $odir/media/boot
fi
mkdir -p $odir/usr/local/bin
mkdir -p $odir/usr/bin > /dev/null 2>&1
cp /etc/timezone $odir/etc
cp /usr/bin/qemu-arm-static $odir/usr/bin
cp second-stage $odir/second-stage
cp params.sh $odir/params.sh
if [ ! "${ONLY_BASE}" = "yes" ] ; then
cp wallpaper.png $odir/ > /dev/null 2>&1
fi
# =====================================================================================
# Execute debootstram second stage and install base system
# =====================================================================================
# ********************************************************************************
# *** If running on ARM (OrangePI) USE THE LINE WITHOUT "qemu-arm-static" !!! ****
# ********************************************************************************
#if ! chroot $odir /bin/bash /second-stage; then
if ! chroot $odir /usr/bin/qemu-arm-static -cpu cortex-a9 /bin/bash /second-stage; then
mv $odir/install.log . > /dev/null 2>&1
echo "================================================"
echo "ERROR on second-stage, instalation NOT FINISHED."
echo "================================================"
exit 1
fi
if [ ! -f $odir/_OK_ ]; then
mv $odir/install.log . > /dev/null 2>&1
echo "================================================"
echo "ERROR on second-stage, instalation NOT FINISHED."
echo "================================================"
exit 1
fi
#======================================================================================
rm $odir/_OK_ > /dev/null 2>&1
rm $odir/second-stage > /dev/null 2>&1
rm $odir/params.sh > /dev/null 2>&1
mv $odir/install.log ./install-${distro}.log > /dev/null 2>&1
# === Copy scripts ========================
cp fs_resize $odir/usr/local/bin
cp update_boot.sh $odir/usr/local/bin
cp install_to_emmc $odir/usr/local/bin
if [ ! "${ONLY_BASE}" = "yes" ] ; then
cp install_lxde_desktop $odir/usr/local/bin
cp install_mate_desktop $odir/usr/local/bin
cp install_xfce_desktop $odir/usr/local/bin
fi
# =========================================
# === Copy kernel, modules & scripts =============================================
mkdir -p $odir/boot > /dev/null 2>&1
mkdir -p $odir/boot > /dev/null 2>&1
mkdir -p $odir/boot > /dev/null 2>&1
rm -r $odir/boot/* > /dev/null 2>&1
cp orange/uImage_OPI* $odir/boot > /dev/null 2>&1
cp orange/boot0_OPI.fex $odir/boot > /dev/null 2>&1
cp orange/u-boot_OPI*.fex $odir/boot > /dev/null 2>&1
cp install_* $odir/usr/local/bin > /dev/null 2>&1
cp fs_resize $odir/usr/local/bin > /dev/null 2>&1
if [ "${3}" = "opi-2" ] || [ "${4}" = "opi-2" ]; then
cp orange/uImage_OPI-2 $odir/boot/uImage > /dev/null 2>&1
cp orange/script.bin.OPI-2_* $odir/boot > /dev/null 2>&1
if [ ! "${_boot_on_ext4}" = "yes" ] ; then
cp orange/uImage_OPI-2 $bootdir/uImage > /dev/null 2>&1
cp orange/script.bin.OPI-2_1080p60_hdmi $bootdir/script.bin > /dev/null 2>&1
cp orange/script.bin.OPI-2_* $bootdir > /dev/null 2>&1
fi
elif [ "${3}" = "opi-pc" ] || [ "${4}" = "opi-pc" ]; then
cp orange/uImage_OPI-2 $odir/boot/uImage > /dev/null 2>&1
cp orange/script.bin.OPI-PC_* $odir/boot > /dev/null 2>&1
if [ ! "${_boot_on_ext4}" = "yes" ] ; then
cp orange/uImage_OPI-2 $bootdir/uImage > /dev/null 2>&1
cp orange/script.bin.OPI-PC_1080p60_hdmi $bootdir/script.bin > /dev/null 2>&1
cp orange/script.bin.OPI-PC_* $bootdir > /dev/null 2>&1
fi
elif [ "${3}" = "opi-plus" ] || [ "${4}" = "opi-plus" ]; then
cp orange/uImage_OPI-PLUS $odir/boot/uImage > /dev/null 2>&1
cp orange/script.bin.OPI-PLUS_* $odir/boot > /dev/null 2>&1
if [ ! "${_boot_on_ext4}" = "yes" ] ; then
cp orange/uImage_OPI-PLUS $bootdir/uImage > /dev/null 2>&1
cp orange/script.bin.OPI-PLUS_1080p60_hdmi $bootdir/script.bin > /dev/null 2>&1
cp orange/script.bin.OPI-PLUS_* $bootdir > /dev/null 2>&1
fi
else
cp orange/uImage_OPI-2 $odir/boot/uImage > /dev/null 2>&1
cp orange/script.bin.OPI-* $odir/boot > /dev/null 2>&1
if [ ! "${_boot_on_ext4}" = "yes" ] ; then
cp orange/uImage_OPI-2 $bootdir/uImage > /dev/null 2>&1
cp orange/uImage_OPI* $bootdir > /dev/null 2>&1
cp orange/script.bin.OPI-* $bootdir > /dev/null 2>&1
cp orange/script.bin.OPI-2_720p60_hdmi $bootdir/script.bin > /dev/null 2>&1
fi
fi
cp -rf orange/lib/modules $odir/lib > /dev/null 2>&1
cp -rf orange/lib/firmware $odir/lib > /dev/null 2>&1
chown -R root:root $odir/lib/* > /dev/null 2>&1
# ================================================================================
sync
rm -rf $odir/dev/*
rm -rf $odir/proc/*
rm -rf $odir/run/*
rm -rf $odir/sys/*
rm -rf $odir/tmp/*
echo ""
# ***************
# Create fstab
# ***************
echo "Creating \"fstab\""
echo "# OrangePI fstab" > $odir/etc/fstab
if [ "${_format}" = "btrfs" ] ; then
echo "/dev/mmcblk0p2 / btrfs subvolid=0,noatime,nodiratime,compress=lzo 0 1" >> $odir/etc/fstab
else
echo "/dev/mmcblk0p2 / ext4 errors=remount-ro,noatime,nodiratime 0 1" >> $odir/etc/fstab
fi
echo "/dev/mmcblk0p1 /media/boot vfat defaults 0 0" >> $odir/etc/fstab
echo "tmpfs /tmp tmpfs nodev,nosuid,mode=1777 0 0" >> $odir/etc/fstab
sync
# ================================================
# IF CREATING IMAGE unmount and create final image
# ================================================
if [ ! "${sdcard}" = "" ]; then
if [ ! "${_boot_on_ext4}" = "yes" ] ; then
if ! umount -l $bootdir; then
echo "ERROR unmounting fat partition."
exit 0
fi
rm -rf $bootdir/* > /dev/null 2>&1
rmdir $bootdir > /dev/null 2>&1
fi
if ! umount -l $odir; then
echo "ERROR unmounting ext4 partitions."
exit 0
fi
rm -rf $odir/* > /dev/null 2>&1
rmdir $odir > /dev/null 2>&1
sync
echo "Creating SDCard image..."
dd if=${sdcard}u of=${sdcard} > /dev/null 2>&1
if [ -f ${sdcard}1 ]; then
dd if=${sdcard}1 of=${sdcard} bs=1M conv=notrunc oflag=append > /dev/null 2>&1
fi
if [ -f ${sdcard}2 ]; then
dd if=${sdcard}2 of=${sdcard} bs=1M conv=notrunc oflag=append > /dev/null 2>&1
fi
if [ "${_compress}" = "yes" ]; then
echo "Compressing image..."
xz -z -k -9 -f -v $sdcard
md5sum $sdcard > $sdcard.md5sum
md5sum $sdcard.xz > $sdcard.xz.md5sum
fi
fi
if [ "${_directsd}" = "yes" ] ; then
if ! umount $odir; then
echo "ERROR unmounting ext4 partitions."
fi
fi
echo ""
date
echo ""
echo "************************************************************"
echo "Instalation finished."
echo ""
if [ ! "${sdcard}" = "" ]; then
echo "You have bootable OrangePI SD Card image \"${sdcard}\"."
echo "Use dd to copy to your SDCard"
echo " e.g. sudo dd if=$sdcard of=/dev/<your_sdcard> bs=1M"
else
if [ "${_directsd}" = "yes" ] ; then
echo "You have OrangePI $distro instalation on $image_name."
else
if [ ! "${_boot_on_ext4}" = "yes" ] ; then
echo "Copy files from $bootdir to SD Card boot partition"
echo " e.g. cp $bootdir/* <path_to_sdcard_boot_mount>"
echo " and rsync $odir to SD Card ext4 partition."
echo " e.g. sudo rsync -r -t -p -o -g -x -v --progress --delete -l -H -D --numeric-ids -s $PWD/$odir/ <path_to_sdcard_ext4_mount>/"
else
echo "Rsync files from $odir to SD Card ext4 partition"
echo " e.g. sudo rsync -r -t -p -o -g -x -v --progress --delete -l -H -D --numeric-ids -s $PWD/$odir/ <path_to_sdcard_ext4_mount>/"
fi
echo ""
echo "Or create SDCard image running:"
echo " sudo ./image_from_dir $odir <DEVICE|IMAGE>"
fi
echo ""
echo "You can chroot into \"$odir\" to make additional changes:"
if [ "${_directsd}" = "yes" ] ; then
echo " sudo mount $image_name $odir"
fi
echo " sudo chroot $odir /usr/bin/qemu-arm-static -cpu cortex-a9 /bin/bash"
fi
echo ""
echo -e "\033[36m"
echo "************************************************************"
echo "* AFTER BOOTING: *"
echo "* -------------------------------------------------------- *"
echo "* To RESIZE LINUX partition to fill sd card run: *"
echo "* sudo fs_resize *"
echo "* -------------------------------------------------------- *"
echo "* To change the board type / update run: *"
echo "* sudo update_boot.sh *"
echo "* -------------------------------------------------------- *"
echo "* To install to EMMC run: *"
echo "* sudo install_to_emmc *"
echo "* -------------------------------------------------------- *"
echo "* To install desktop run: *"
echo "* sudo install_lxde_desktop *"
echo "* or, for better-looking (wily&vivid&jessie) *"
echo "* sudo install_mate_desktop *"
echo "* DON'T FORGET TO RESIZE SD CARD IF NECESSARY FIRST *"
echo "* -------------------------------------------------------- *"
echo "* To configure your local settings use: *"
echo "* sudo dpkg-reconfigure tzdata *"
echo "* sudo dpkg-reconfigure keyboard-configuration *"
echo "* sudo dpkg-reconfigure console-setup *"
echo "* # change your system's locale entries by modifying *"
echo "* # the file /etc/default/locale (e.g. en_US.UTF-8) *"
echo "* # then run: *"
echo "* sudo locale-gen <your_locale> (e.g en_US.UTF-8) *"
echo "* sudo dpkg-reconfigure locales *"
echo "************************************************************"
echo -e "\033[37m"
date
echo ""
exit 0