-
Notifications
You must be signed in to change notification settings - Fork 0
/
multipi4
182 lines (157 loc) · 4.8 KB
/
multipi4
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
#!/usr/bin/env bash
set -x
setup() {
usbdevice="$1"
raspbianliteimg="$2"
loopdevice=$(losetup --show -Pf "$raspbianliteimg")
mkdir -p raspbianboot
mkdir -p raspbian
mkdir -p {usb1,usb2,usb3}
mount -o ro ${loopdevice}p1 raspbianboot
mount -o ro ${loopdevice}p2 raspbian
mount ${usbdevice}1 usb1
mount ${usbdevice}2 usb2
mount ${usbdevice}3 usb3
cp -r raspbianboot/* usb1/
rsync -a raspbian/ usb3/
wget -O usb3/etc/fstab https://github.com/raspberrypisig/usb-msd-raspberrypi-multios/raw/master/fstab
wget https://github.com/raspberrypi/rpi-eeprom/releases/download/v2020.05.28-137ad/usb-msd-boot-firmware.zip
unzip -o -d usb1 usb-msd-boot-firmware.zip
wget -O usb1/config.txt https://github.com/raspberrypisig/usb-msd-raspberrypi-multios/raw/master/partition1/config.txt
wget -O usb1/cmdline.txt https://github.com/raspberrypisig/usb-msd-raspberrypi-multios/raw/master/cmdline.txt
cp -r usb1/* usb2/
wget -O usb2/config.txt https://github.com/raspberrypisig/usb-msd-raspberrypi-multios/raw/master/partition2/config.txt
wget -O usb3/OS-CHOOSER.sh https://github.com/raspberrypisig/usb-msd-raspberrypi-multios/raw/master/OS-CHOOSER.sh
chmod +x usb3/OS-CHOOSER.sh
wget -O usb3/etc/systemd/system/oschooser.service https://github.com/raspberrypisig/usb-msd-raspberrypi-multios/raw/master/oschooser.service
wget -O usb3/firstboot.sh https://github.com/raspberrypisig/usb-msd-raspberrypi-multios/raw/master/firstboot.sh
chmod +x usb3/firstboot.sh
cp usb3/etc/rc.local usb3/etc/rc.local.original
echo -e '#!/usr/bin/env bash\n/firstboot.sh\nexit 0' > usb3/etc/rc.local
umount {usb1,usb2,usb3,raspbianboot,raspbian}
losetup -D $loopdevice
}
fromimg() {
osimg="$1"
bootpart="$2"
linuxpart="$3"
name="$4"
loopdevice=$(losetup --show -Pf "$osimg")
mkdir -p osboot
mkdir -p os
mkdir -p usbboot
mkdir -p usblinux
mount -o ro ${loopdevice}p1 osboot
mount -o ro ${loopdevice}p2 os
mount $bootpart usbboot
mount $linuxpart usblinux
cp -r ./osboot/* usbboot/
rsync -a os/ usblinux/
wget -O usblinux/etc/fstab https://github.com/raspberrypisig/usb-msd-raspberrypi-multios/raw/master/fstab
#escaped_bootpart=$(sed 's/\//\\\//g' <<< $bootpart)
#escaped_linuxpart=$(sed 's/\//\\\//g' <<< $linuxpart)
bootpartnumber="${bootpart//[^0-9]}"
linuxpartnumber="${linuxpart//[^0-9]}"
sed -i -r "s/\/dev\/sda1/\/dev\/sda$bootpartnumber/" usblinux/etc/fstab
sed -i -r "s/\/dev\/sda3/\/dev\/sda$linuxpartnumber/" usblinux/etc/fstab
echo "$name" > usbboot/NAME
umount {usbboot,usblinux,osboot,os}
losetup -D $loopdevice
rm -rf {usbboot,usblinux,os,osboot}
}
fromsd() {
sd="$1"
bootpart="$2"
linuxpart="$3"
name="$4"
mkdir -p osboot
mkdir -p os
mkdir -p usbboot
mkdir -p usblinux
mount -o ro ${sd}p1 osboot
mount -o ro ${sd}p2 os
mount $bootpart usbboot
mount $linuxpart usblinux
cp -r ./osboot/* usbboot/
rsync -a os/ usblinux/
wget -O usblinux/etc/fstab https://github.com/raspberrypisig/usb-msd-raspberrypi-multios/raw/master/fstab
#escaped_bootpart=$(sed 's/\//\\\//g' <<< $bootpart)
#escaped_linuxpart=$(sed 's/\//\\\//g' <<< $linuxpart)
bootpartnumber="${bootpart//[^0-9]}"
linuxpartnumber="${linuxpart//[^0-9]}"
sed -i -r "s/\/dev\/sda1/\/dev\/sda$bootpartnumber/" usblinux/etc/fstab
sed -i -r "s/\/dev\/sda3/\/dev\/sda$linuxpartnumber/" usblinux/etc/fstab
echo "$name" > usbboot/NAME
umount {usbboot,usblinux,osboot,os}
rm -rf {usbboot,usblinux,os,osboot}
}
ubuntufromimg() {
osimg="$1"
bootpart="$2"
linuxpart="$3"
name="$4"
arm64bit=${5:-0}
if [ $arm64bit -eq 1 ];
then
kernel=vmlinux
else
kernel=vmlinuz
fi
loopdevice=$(losetup --show -Pf "$osimg")
mkdir -p osboot
mkdir -p os
mkdir -p usbboot
mkdir -p usblinux
mount -o ro ${loopdevice}p1 osboot
mount -o ro ${loopdevice}p2 os
mount $bootpart usbboot
mount $linuxpart usblinux
cp -r ./osboot/* usbboot/
rsync -a os/ usblinux/
touch usblinux/etc/cloud/cloud-init.disabled
cat <<EOF > usbboot/config.txt
[all]
device_tree_address=0x03000000
kernel=$kernel
initramfs initrd.img followkernel
arm_64bit=$arm64bit
EOF
bootpartnumber="${bootpart//[^0-9]}"
linuxpartnumber="${linuxpart//[^0-9]}"
sed -i -r "s/LABEL=system-boot/\/dev\/sda$bootpartnumber/" usblinux/etc/fstab
sed -i -r "s/LABEL=writable/\/dev\/sda$linuxpartnumber/" usblinux/etc/fstab
echo "$name" > usbboot/NAME
umount {usbboot,usblinux,osboot,os}
losetup -D $loopdevice
rm -rf {usbboot,usblinux,os,osboot}
}
case "$1" in
"setup")
shift
setup "$@"
;;
"add")
shift
case "$1" in
"fromimg")
shift
fromimg "$@"
;;
"fromsd")
shift
fromsd "$@"
;;
esac
;;
"addubuntu")
shift
ubuntufromimg "$@"
;;
"addubuntu64")
shift
ubuntufromimg "$@" 1
;;
*)
echo help
;;
esac