-
Notifications
You must be signed in to change notification settings - Fork 4
/
create_rpi2_image
executable file
·828 lines (712 loc) · 21.8 KB
/
create_rpi2_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
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
#!/bin/bash
# Last update: 2015-03-12
# *****************************************************
# !! 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 "Creating TinyAstro image for RaspBerry Pi 2"
echo "========================================================"
echo ""
_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
cd $_DIR
# =====================================================
# ==== P A R A M E T E R S ============================
# =====================================================
# *****************************************************
# Set the base name of your image. *
# Distro name is automaticaty appended *
# --------------------------------------------------- *
# IF image_name="", image file won't be created, *
# instalation will be created in local directories *
# linux-$distro & boot-$distro *
# YOU CAN CREATE THE IMAGE LATER RUNNING: *
# sudo ./image_from_dir <directory> [yes|no] *
# yes|no - create or not ext4 only system *
# --------------------------------------------------- *
# IF image_name is BLOCK DEVICE (/dev/sdX) *
# LINUX filesystem will be created directly on it *
# Partition must exist ! *
# IF _format="" partition will NOT be formated *
# otherwyse it will be formated with specified format *
# *****************************************************
image_name="TinyAstro"
# *****************************************************
# Filesystem type for linux partition *
# *****************************************************
#_format="btrfs"
_format="ext4"
# =====================================================
# IF YOU WANT TO HAVE BOOT FILES ON EXT4 PARTITION =
# AND NOT ON SEPARATE FAT16 PARTITION =
# set _boot_on_ext4="yes" and =
# FAT partitin won't be created =
# =====================================================
_boot_on_ext4=""
# *****************************************************
# SD Card partitions sizes in MB (1024 * 1024 bytes) *
# *****************************************************
fatsize=64
linuxsize=3072
# *****************************************************
# Set file systems uuid's for boot and fstab
# *****************************************************
vfatuuid="6E355356"
ext4uuid="e139ce78-9841-40fe-8823-96a304a09859"
# ******************************************************
# If you want to xz compress the image and make md5sum *
# set _compress="yes" *
# ******************************************************
_compress="no"
# *****************************************************
# Select ubuntu/debian distribution and repository *
# SELECT ONLY ONE distro AND ONE repo *
# *****************************************************
# === Ubuntu ===
#distro="precise"
#distro="trusty"
#distro="utopic"
#distro="vivid"
distro="wily"
repo="http://ports.ubuntu.com/ubuntu-ports"
# ******************************************************
# Which board you want to build the image *
# ******************************************************
BOARD=RPi2
# ^^^^ P A R A M E T E R S ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
if [ "${_format}" = "btrfs" ]; then
_boot_on_ext4="no"
fi
#whre is the rootfs
rfs=./rfs
# === CHECK DESTINATION ============================================
if [ ! "${image_name}" = "" ]; then
if [ -b $image_name ] && [ "${_boot_on_ext4}" = "yes" ]; then
# === ON BLOCK DEVICE ======================================
echo "Creating filesystem on block device ${image_name} for ${BOARD}..."
sdcard=""
odir="_mnt"
bootdir="boot-$distro-sd"
_boot_on_ext4="yes"
_directsd="yes"
# ==========================================================
else
# === ON IMAGE FILE ======================
if [ "${_boot_on_ext4}" = "yes" ] ; then
sdcard="$image_name-$distro-$BOARD-nofat.img"
else
sdcard="$image_name-$distro-$BOARD.img"
fi
odir="linux-$image_name-$distro-$BOARD"
bootdir="$odir/boot"
# ========================================
fi
else
# === IN LOCAL DIRECTORY ===
sdcard=""
odir="linux-$distro"
bootdir="boot-$distro"
vfatuuid="6E35-5356"
ext4uuid="e139ce78-9841-40fe-8823-96a304a09859"
# ==========================
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="-o loop"
fi
# ======================================================================
# IF CREATING ON IMMAGE, PREPARE SD CARD IMAGE FOR ODROID - UBUNTU BOOT
# ----------------------------------------------------------------------
if [ ! "${sdcard}" = "" ]; then
echo "Using disk image \"$sdcard\""
# remove old image files
rm ${sdcard} > /dev/null 2>&1
rm ${sdcard}1 > /dev/null 2>&1
rm ${sdcard}2 > /dev/null 2>&1
if [ "${_compress}" = "yes" ]; then
rm ${sdcard}.md5sum > /dev/null 2>&1
rm ${sdcard}.xz > /dev/null 2>&1
rm ${sdcard}.xz.md5sum > /dev/null 2>&1
fi
if [ $linuxsize -eq 0 ]; then
linuxsize=2560
fi
if [ "${_boot_on_ext4}" = "yes" ] ; then
_ersz=$(expr $linuxsize + 2)
else
_ersz=$(expr $fatsize + $linuxsize + 2)
fi
echo "Creating bootable SD card image $sdcard, please wait ..."
echo ""
dd if=/dev/zero of=${sdcard} bs=1M count=$_ersz > /dev/null 2>&1
echo "Creating partition images, please wait ..."
if [ "${_boot_on_ext4}" = "yes" ] ; then
dd if=/dev/zero of=${sdcard}1 bs=1M count=$linuxsize > /dev/null 2>&1
else
dd if=/dev/zero of=${sdcard}1 bs=1M count=$fatsize > /dev/null 2>&1
dd if=/dev/zero of=${sdcard}2 bs=1M count=$linuxsize > /dev/null 2>&1
fi
sync
sleep 2
# Create msdos partition table
echo ""
echo "Creating new filesystem on $sdcard..."
echo -e "o\nw" | fdisk ${sdcard} > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR."
exit 0
fi
sync
echo " New filesystem created on SD card."
echo ""
echo "Partitioning SD card $sdcard..."
if [ "${_boot_on_ext4}" = "yes" ] ; then
echo " Creating ext4"
sext4=3072
if [ $linuxsize == 0 ]; then
eext4=""
else
eext4=$(expr $linuxsize \* 1024 \* 1024 / 512 + $sext4 - 1)
fi
echo -e "n\np\n1\n$sext4\n$eext4\nt\n83\nw" | fdisk ${sdcard} > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR."
exit 0
fi
else
sfat=2048
efat=$(expr $fatsize \* 1024 \* 1024 / 512 + $sfat - 1)
echo " Creating fat & ext4"
sext4=$(expr $efat + 1)
if [ $linuxsize == 0 ]; then
eext4=""
else
eext4=$(expr $linuxsize \* 1024 \* 1024 / 512 + $sext4 - 1)
fi
echo -e "n\np\n1\n$sfat\n$efat\nn\np\n2\n$sext4\n$eext4\nt\n1\n6\nt\n2\n83\nw" | fdisk ${sdcard} > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR."
exit 0
fi
fi
echo " OK."
sync
sleep 2
#echo -e "p\nq\n" | fdisk ${sdcard}
echo ""
if [ ! "${_boot_on_ext4}" = "yes" ] ; then
echo "Formating fat partition ..."
mkfs -t vfat -n BOOT -i $vfatuuid ${sdcard}1 > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR formating fat partition."
exit 0
fi
#vfatuuid=`blkid -s UUID -o value ${sdcard}1`
echo " fat partition formated."
echo "Formating linux partition, please wait ..."
if [ "${_format}" = "btrfs" ] ; then
# format as btrfs
mkfs.btrfs -f -L $distro ${sdcard}2 > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR formating btrfs partition."
exit 1
fi
else
mkfs -F -t ext4 -L $distro -U $ext4uuid ${sdcard}2 > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR formating ext4 partition."
exit 1
fi
#tune2fs -o journal_data_writeback ${sdcard}2 > /dev/null 2>&1
#if [ $? -ne 0 ]; then
# echo "ERROR tuning ext4 partition."
# exit 0
#fi
#tune2fs -O ^has_journal ${sdcard}2 > /dev/null 2>&1
#if [ $? -ne 0 ]; then
# echo "ERROR tuning ext4 partition."
# exit 0
#fi
fi
#ext4uuid=`blkid -s UUID -o value ${sdcard}2`
else
echo "Formating linux partition, please wait ..."
if [ "${_format}" = "btrfs" ] ; then
# format as btrfs
mkfs.btrfs -f -L $distro ${sdcard}2 > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR formating btrfs partition."
exit 1
fi
else
mkfs -F -t ext4 -L $distro -U $ext4uuid ${sdcard}1 > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR formating ext4 partition."
exit 0
fi
#tune2fs -o journal_data_writeback ${sdcard}1 > /dev/null 2>&1
#if [ $? -ne 0 ]; then
# echo "ERROR tuning ext4 partition."
# exit 0
#fi
#tune2fs -O ^has_journal ${sdcard}1 > /dev/null 2>&1
#if [ $? -ne 0 ]; then
# echo "ERROR tuning ext4 partition."
# exit 0
#fi
fi
#ext4uuid=`blkid -s UUID -o value ${sdcard}1`
fi
echo " linux partition formated."
dd if=${sdcard} of=${sdcard}u bs=512 count=2048 > /dev/null 2>&1
rm ${sdcard}
else
echo "Creating root filesistem in local directory $odir..."
fi
# ======================================================================
# Prepare directories
if [ ! -d $odir ]; then
mkdir -p $odir
fi
sync
# =============================================
# IF USING PHISICAL PARTITION, FORMAT AND MOUNT
# =============================================
if [ "${_directsd}" = "yes" ] ; then
umount $image_name > /dev/null 2>&1
if [ "${_format}" = "ext4" ] ; then
# ** formating as ext4
if ! mkfs.ext4 -F -L linux_e ${image_name} > /dev/null 2>&1; then
echo "ERROR formating $image_name."
exit 1
fi
partprobe -s ${image_name} > /dev/null 2>&1
fi
if [ "${_format}" = "btrfs" ] ; then
# format as btrfs
if ! mkfs.btrfs -f -L linux_b ${image_name} > /dev/null 2>&1; then
echo "ERROR formating $image_name."
exit 1
fi
partprobe -s ${image_name} > /dev/null 2>&1
if ! mount -o compress=lzo $image_name $odir; then
echo "ERROR mounting $image_name."
exit 1
fi
else
# do not format, only mount
if ! mount $image_name $odir; then
echo "ERROR mounting $image_name."
exit 1
fi
fi
ext4uuid=`blkid -s UUID -o value ${image_name}`
echo "${image_name} mounted to ${odir}."
rm -rf $odir/* > /dev/null 2>&1
sync
else
umount $odir > /dev/null 2>&1
sleep 1
fi
# ===========================================
# 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 ${_mntopt} ${sdcard}2 $odir; then
echo "ERROR mounting partitions..."
umount $bootdir
exit 1
fi
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 ! mount ${sdcard}1 $bootdir; then
echo "ERROR mounting partitions..."
exit 1
fi
echo "SD Card partitions mounted to $odir & $bootdir"
else
if ! mount ${_mntopt} ${sdcard}1 $odir; then
echo "ERROR mounting partitions..."
if [ ! "${_boot_on_ext4}" = "yes" ] ; then
umount $bootdir
fi
exit 1
fi
fi
echo "SD Card partition mounted to $odir"
fi
#===================================================================================================================
# =========================
# DEBOOTSTRAP UBUNTU DISTRO
# =========================
echo ""
if [ ! -d $rfs ] ; then
echo "No rfs found, please create rfs first."
exit 0
fi
echo "Copy rootfs from $rfs to $odir ......"
rsync -r -t -p -o -g -x --delete -l -H -D --numeric-ids -s --stats $rfs/* $odir/
pid=$!
proc_wait $pid "please wait"
if [ $_excode -ne 0 ]; then
echo "ERROR IN COPY FILE!"
exit 0
fi
# script to resize sdcard
cp ./common/fs_resize $odir
chmod +x $odir/fs_resize
# make necessary directories and copy some files
mkdir -p $odir/etc/default > /dev/null 2>&1
mkdir -p $odir/usr/local/bin
cp /etc/timezone $odir/etc
cp wallpaper.png $odir/ > /dev/null 2>&1
#*********************
# ** CONFIGURE NETWORK
#*********************
set_network() {
mkdir -p $odir/etc/network
cat >> $odir/etc/network/interfaces << _EOF_
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.1.250
netmask 255.255.255.0
gateway 192.168.1.1
#WIFI AP
allow-hotplug wlan0
auto wlan0
iface wlan0 inet static
address 10.0.0.1
netmask 255.255.255.0
_EOF_
#cat >> $odir/etc/init/eth0.conf << _EOF_
#start on net-device-added INTERFACE=eth0
#task
#exec ifup eth0
#_EOF_
cat >> $odir/etc/hostapd/ap.conf << _EOF_
# This is the name of the WiFi interface we configured above
interface=wlan0
# Use the nl80211 driver with the brcmfmac driver
driver=nl80211
# This is the name of the network
ssid=Pi3-AP
# Use the 2.4GHz band
hw_mode=g
# Use channel 6
channel=6
# Enable 802.11n
ieee80211n=1
# Enable WMM
wmm_enabled=1
# Enable 40MHz channels with 20ns guard interval
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
# Accept all MAC addresses
macaddr_acl=0
# Use WPA authentication
auth_algs=1
# Require clients to know the network name
ignore_broadcast_ssid=0
# Use WPA2
wpa=2
# Use a pre-shared key
wpa_key_mgmt=WPA-PSK
# The network passphrase
wpa_passphrase=astronomy
# Use AES, instead of TKIP
rsn_pairwise=CCMP
_EOF_
cat >> $odir/etc/hostapd/ap_rtl8192cu.conf << _EOF_
#ssid=TinyAstro
wpa_passphrase=astronomy
ctrl_interface=/var/run/hostapd
interface=wlan0
#bridge=br0
driver=rtl871xdrv
hw_mode=g
channel=6
wpa=2
beacon_int=100
hw_mode=g
ieee80211n=1
wme_enabled=1
ht_capab=[SHORT-GI-20][SHORT-GI-40][HT40+]
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
max_num_sta=8
#wpa_group_rekey=86400
_EOF_
cat >> $odir/etc/dnsmasq.conf << _EOF_
interface=wlan0
dhcp-range=10.0.0.2,10.0.0.5,255.255.255.0,12h
_EOF_
}
# *************************************************
# ** Some tricks to make everything work
# *************************************************
do_tricks() {
# **********************************************
# ADJUST rc.local for some tuning
cat > $odir/etc/rc.local << _EOF_
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
if [ -f /first_boot ] ; then
RAND_NAME=\$(openssl rand -base64 8)
echo "ssid=TinyAstro_\$RAND_NAME" >> /etc/hostapd/ap.conf
echo "ssid=TinyAstro_\$RAND_NAME" >> /etc/hostapd/ap_rtl8192cu.conf
dpkg -i /cofi.deb
rm -f /cofi.deb
rm -f /first_boot
var=\$(bash /fs_resize)
rm /fs_resize
reboot
fi
rtl8192cu=""
brcmwifi=""
for wlan in \$(ls /sys/class/net | grep wlan)
do
tmp=\$(ethtool -i \$wlan | head -n 1 | awk '{print \$2}')
if [ "\$tmp" = "rtl8192cu" ]; then
rtl8192cu=\$wlan
elif [ "\$tmp" = "brcmfmac" ]; then
brcmwifi=\$wlan
fi
done
if [ ! -z "\$brcmwifi" ]; then
ifdown \$brcmwifi
sed -i 's/wlan[0-9]/'\$brcmwifi'/' /etc/network/interfaces
ifup \$brcmwifi
sed -i 's/^\(interface=\).*/\1'\$brcmwifi'/' /etc/hostapd/ap.conf
hostapd -B /etc/hostapd/ap.conf & > /dev/null 2>&1
sed -i 's/^\(interface=\).*/\1'\$brcmwifi'/' /etc/dnsmasq.conf
service dnsmasq restart
elif [ ! -z "\$rtl8192cu" ]; then
ifdown \$rtl8192cu
sed -i 's/wlan[0-9]/'\$rtl8192cu'/' /etc/network/interfaces
ifup \$rtl8192cu
sed -i 's/^\(interface=\).*/\1'\$rtl8192cu'/' /etc/hostapd/ap_rtl8192cu.conf
hostapd_rtl -B /etc/hostapd/ap_rtl8192cu.conf & > /dev/null 2>&1
sed -i 's/^\(interface=\).*/\1'\$rtl8192cu'/' /etc/dnsmasq.conf
service dnsmasq restart
fi
su astro -c "startx -- :1 -config xorg.dummy.conf &"
su astro -c "x11vnc -display :1 -forever &"
/home/astro/tools/ddserver &
hciattach /dev/ttyAMA0 bcm43xx 921600 noflow -
hciattach /dev/ttyAMA0 bcm43xx 921600 noflow -
exit 0
_EOF_
cat >> $odir/lib/systemd/system/rc-local.service << _EOF_
[Install]
WantedBy=multi-user.target
_EOF_
# *****************************
# Setup tmux to show the cursor
cat > $odir/home/$USER/.tmux.conf << _EOF_
setw -ga terminal-overrides ',*:Cc=\E[?120;%p1%s;240c:Cr=\E[?120;0;240c:civis=\E[?25l:cnorm=\E[?25h:cvvis=\E[?25h,'
set -g status-bg black
set -g status-fg white
_EOF_
# ******************************************
# ADJUST .bashrc to start tmux in fb console
cat >> $odir/home/$USER/.bashrc << _EOF_
if [ "\$TERM" = "linux" ]; then
if [[ ! \$TERM =~ screen ]]; then
exec tmux
fi
fi
_EOF_
# *********************************************
# Enable serial console and 3 virtual terminals
#cat > $odir/etc/init/ttyAMA0.conf << _EOF_
## ttyAMA0 - getty
##
## This service maintains a getty on ttyS0 from the point the system is
## started until it is shut down again.
#
#start on stopped rc or RUNLEVEL=[12345]
#stop on runlevel [!12345]
#
#respawn
#exec /sbin/getty -L 115200 ttyAMA0 vt102
#_EOF_
#
#rm $odir/etc/init/tty4.conf
#rm $odir/etc/init/tty5.conf
#rm $odir/etc/init/tty6.conf
#
}
set_network
do_tricks
# Mount host system
function mount_system() {
mount -t proc none $odir/proc
mount -t sysfs none $odir/sys
mount -o bind /dev $odir/dev
mount -o bind /dev/pts $odir/dev/pts
}
# Unmount host system
function umount_system() {
umount -f $odir/dev/pts
umount -f $odir/proc
umount -f $odir/sys
umount -r $odir/dev
}
mount_system
cp ./chroot_script_rpi2 $odir/chroot_script_rpi2
chroot $odir /bin/bash /chroot_script_rpi2
umount_system
rm $odir/chroot_script_rpi2
#copy firmware
cp ./rpi/brcmfmac43430-sdio.* $odir/lib/firmware/brcm/
mkdir -p $odir/etc/firmware
cp ./rpi/BCM43430A1.hcd $odir/etc/firmware/
sync
rm -rf $odir/dev/*
rm -rf $odir/proc/*
rm -rf $odir/run/*
rm -rf $odir/sys/*
rm -rf $odir/tmp/*
touch $odir/first_boot
echo ""
# ***************
# Create fstab
# ***************
#echo "Creating \"fstab\""
#echo "# Odroid fstab" > $odir/etc/fstab
#echo "" >> $odir/etc/fstab
#if [ "${_format}" = "btrfs" ] ; then
# echo "UUID=$ext4uuid / btrfs noatime,nodiratime,compress=lzo 0 1" >> $odir/etc/fstab
#else
## echo "#UUID=$ext4uuid / ext4 errors=remount-ro,noatime,nodiratime,data=writeback 0 1" >> $odir/etc/fstab
# echo "UUID=$ext4uuid / ext4 errors=remount-ro,noatime,nodiratime 0 1" >> $odir/etc/fstab
#fi
#if [ ! "${_boot_on_ext4}" = "yes" ] ; then
# echo "/dev/mmcblk0p1 /boot/firmware vfat defaults,rw,owner,flush,umask=000 0 0" >> $odir/etc/fstab
#fi
#echo "tmpfs /tmp tmpfs nodev,nosuid,mode=1777 0 0" >> $odir/etc/fstab
# IF CREATING IMAGE unmount and create final image
if [ ! "${sdcard}" = "" ]; then
if [ ! "${_boot_on_ext4}" = "yes" ] ; then
if ! umount $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 $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
rm -f ./${sdcard}1 ./${sdcard}2 ./${sdcard}u
tar cJvf ./tinyastro_${BOARD}.tar.xz ./${sdcard} ./README
rm -f ./${sdcard}
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 ${BOARD} 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 ${BOARD} $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 "UPDATE \"/etc/fstab\" AND \"boot.ini\" WITH SDCard PARTITIONS UUID's if necessary!"
echo ""
echo "Or create SDCard image running:"
echo " sudo ./image_from_dir $odir [yes|no]"
echo " yes|no - create or not ext4 only system"
fi
echo ""
echo "You can chroot into \"$odir\" to make additional changes:"
if [ "${_directsd}" = "yes" ] ; then
echo " mount $image_name $odir"
fi
echo " chroot $odir /usr/bin/qemu-arm-static -cpu cortex-a9 /bin/bash"
fi
echo ""
exit 0