-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall.sh
executable file
·181 lines (145 loc) · 3.67 KB
/
install.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
#!/bin/bash
TARGET_ARCH=armhf
: ${TARGET_DIST=buster}
: ${DEB_MIRROR=http://deb.debian.org/debian/}
: ${PACKAGES=firmware-brcm80211,e2fsprogs,vim,u-boot-tools,cpufrequtils,initramfs-tools,xfsprogs,ssh}
: ${USE_LVM=yes}
: ${ROOT_SIZE=2048M}
: ${SWAP_SIZE=1024M}
: ${ROOTFS_TYPE=ext4}
: ${DISKLABEL_TYPE=dos}
: ${DISKLABEL_FIRST_LBA=2048}
DTB=
case "$ROOTFS_TYPE" in
ext4)
mkrootfs="mkfs.ext4 -F"
;;
xfs)
mkrootfs="mkfs.xfs -f"
;;
*)
echo "Root filesystem type '$ROOTFS_TYPE' not supported"
exit 1
;;
esac
CLEANUP=( )
cleanup() {
set +e
if [ ${#CLEANUP[*]} -gt 0 ]; then
LAST_ELEMENT=$((${#CLEANUP[*]}-1))
REVERSE_INDEXES=$(seq ${LAST_ELEMENT} -1 0)
for i in $REVERSE_INDEXES; do
${CLEANUP[$i]}
done
fi
}
trap cleanup EXIT
get_uuid()
{
blkid -o value -s UUID $1
}
set -e
if [ $# -ne 2 ]; then
echo "Usage: $0 <board> <device>"
echo "Board can be one of:"
ls -1 boards | grep -v '^common$' | sed -e 's/^/ /'
exit 1
fi
board="$1"
dev="$2"
. boards/common/install.sh
hook pre_partitioning
(
echo "label: $DISKLABEL_TYPE"
echo "first-lba: $DISKLABEL_FIRST_LBA"
if [ "$USE_LVM" = yes ]; then
cat <<-EOF
,256M,83,*
,,8e,*
EOF
else
echo ",256M,83,*"
if [ "$SWAP_SIZE" -gt 0 ]; then
echo ",$SWAP_SIZE,82"
fi
echo ",$ROOT_SIZE"
fi
) | flock $dev sfdisk -f -u S $dev
hook post_partitioning
sleep 1
_devices=($(lsblk -n -o name -p -r $dev))
bootdev=${_devices[1]}
swapdev=
if [ "$USE_LVM" = yes ]; then
physdev=${_devices[2]}
vgname="$board-$RANDOM"
vgcreate -f "$vgname" "$physdev"
CLEANUP+=("vgchange -a n $vgname")
if [ "$SWAP_SIZE" -gt 0 ]; then
lvcreate --yes -W y -n swap -L $SWAP_SIZE $vgname
swapdev="/dev/$vgname/swap"
fi
lvcreate --yes -W y -n root -L $ROOT_SIZE $vgname
rootdev="/dev/$vgname/root"
PACKAGES="$PACKAGES,lvm2"
else
if [ "$SWAP_SIZE" -gt 0 ]; then
swapdev=${_devices[2]}
rootdev=${_devices[3]}
else
rootdev=${_devices[2]}
fi
fi
mkfs.ext3 -F $bootdev
tune2fs -o discard $bootdev
swapuuid=
if [ -n "$swapdev" ]; then
mkswap -f $swapdev
swapuuid=$(get_uuid $swapdev)
fi
$mkrootfs $rootdev
bootuuid=$(get_uuid $bootdev)
rootuuid=$(get_uuid $rootdev)
rootdir=$(mktemp -d)
CLEANUP+=("rmdir $rootdir")
mount $rootdev $rootdir
CLEANUP+=("umount $rootdir")
mkdir $rootdir/boot
mount -o nobarrier $bootdev $rootdir/boot
CLEANUP+=("umount $rootdir/boot")
export LC_ALL=C LANGUAGE=C LANG=C
export DEBIAN_FRONTEND=noninteractive
export DEBCONF_NONINTERACTIVE_SEEN=true
tar cf - --owner=root:0 --group=root:0 -C boards/common/root . | tar xf - --no-same-permissions -C "$rootdir"
if [ -d "$BOARD_DIR/root" ]; then
tar cf - --owner=root:0 --group=root:0 -C "$BOARD_DIR/root" . | tar xf - --no-same-permissions -C "$rootdir"
fi
# generate bootEnv.txt
echo "root=UUID=$rootuuid" > "$rootdir/boot/bootEnv.txt"
hook pre_debootstrap
debootstrap --components=main,contrib,non-free --arch $TARGET_ARCH $TARGET_DIST $rootdir $DEB_MIRROR
chroot $rootdir apt-get install -f -y ${PACKAGES//,/ }
# generate boot.scr
chroot $rootdir mkimage -T script -A arm -d /boot/boot.cmd /boot/boot.scr
hook post_debootstrap
hook install_kernel
# prepare dtb
mkdir -p $rootdir/boot/dtb
if [ -n "$DTB" ]; then
cp $rootdir$DTB $rootdir/boot/dtb/
fi
echo "$board" > $rootdir/etc/hostname
cat <<EOF > $rootdir/etc/fstab
UUID=$bootuuid /boot ext3 rw 0 2
UUID=$rootuuid / $ROOTFS_TYPE rw 0 1
EOF
if [ -n "$swapuuid" ]; then
echo "UUID=$swapuuid none swap sw 0 0" >> $rootdir/etc/fstab
fi
echo 'GOVERNOR="conservative"' > $rootdir/etc/default/cpufrequtils
echo "root:pi" | chroot $rootdir chpasswd
chroot $rootdir systemctl enable systemd-timesyncd
U_BOOT="$BOARD_DIR/u-boot-sunxi-with-spl.bin"
if [ -f "$U_BOOT" ]; then
dd if="$U_BOOT" of=$dev bs=1k seek=8
fi