Skip to content

Commit b1adc03

Browse files
Geoffroy Van Cutsemlirui34
authored andcommitted
Update doc/getting-started/gsg_quick_setup.sh
1. Add text to the script usages and inform people to run script with root access. 2. Add logic to determine the right ESP. 3. remove unset proxy line. 4. Add reboot operation after upgrade SOS. 5. Handle multiple efi partition while it's detected. Co-Authored-By: lirui34 <48583653+lirui34@users.noreply.github.com>
1 parent 65ed6c6 commit b1adc03

File tree

1 file changed

+133
-63
lines changed

1 file changed

+133
-63
lines changed

doc/getting-started/gsg_quick_setup.sh

Lines changed: 133 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,97 @@
11
#!/bin/bash
22
# Copyright (C) 2019 Intel Corporation.
33
# SPDX-License-Identifier: BSD-3-Clause
4-
# This script is aim to setup or upgrade sos & uos automatically.
4+
#
5+
# This script is aim to quick setup sos and uos automatically.
6+
# You can also use this to upgrade sos with a specified clear linux version.
7+
# Also you should know that system may have boot problems once the script is running failed
8+
# since it will modify various system parameters with full root access.
9+
#
10+
# Usages:
11+
# Upgrade sos to 28100
12+
# sudo <script> -t 28100
13+
# Upgrade sos to 28100 with specified proxy server
14+
# sudo <script> -t 28100 -p <your proxy server>:<port>
15+
# Upgrade uos to 28100 with specified proxy server
16+
# sudo <script> -t 28100 -p <your proxy server>:<port> -u
17+
# Upgrade uos to 28100 without downloading uos image, you should put uos image in /root directory previously.
18+
# sudo <script> -t 28100 -u -s
519

6-
# switch for download uos function
7-
skip_download_uos=0
8-
# turn on if you need to setup uos
9-
upgrade_uos=0
1020

1121
function print_help()
1222
{
1323
echo "Usage:"
1424
echo "Launch this script as: sudo $0 -t 28100"
1525
echo -e "\t-t to specify clear linux version for upgrading"
16-
echo "-p to specify a proxy server"
17-
echo "-m to use swupd mirror url"
18-
echo "-u to upgrade uos, if you just upgrade sos using this script, you'd better to manually reboot sos then continue to use this function."
19-
echo "-s, skip downloading uos; if enabled, you have to download uos img firstly before upgrading, default is off"
26+
echo -e "\t-p to specify a proxy server"
27+
echo -e "\t-m to use swupd mirror url"
28+
echo -e "\t-u to upgrade UOS."
29+
echo -e "\t-s, skip downloading uos; if enabled, you have to download uos img firstly before upgrading, default is off"
2030
exit 1
2131
}
2232

33+
# switch for download uos function
34+
skip_download_uos=0
35+
# turn on if you need to setup uos
36+
upgrade_uos=0
37+
38+
# acrn.conf path
39+
acrn_conf_path=/usr/share/acrn/samples/nuc/acrn.conf
40+
# acrn.efi path
41+
acrn_efi_path=/usr/lib/acrn/acrn.efi
42+
2343
function upgrade_sos()
2444
{
25-
# setup mirror, proxy env if specified parameters to p & m opt.
26-
swupd mirror -u
45+
# setup mirror and proxy url while specified with m and p options
2746
if [[ -n $mirror ]]; then
28-
echo "Add swupd mirror..."
47+
echo "Setting swupd mirror to: $mirror"
2948
swupd mirror -s $mirror
3049
fi
31-
unset https_proxy
3250
if [[ -n $proxy ]]; then
33-
echo "Add proxy..."
51+
echo "Setting proxy to: $proxy"
3452
export https_proxy=$proxy
3553
fi
36-
echo "disable auto update..."
54+
55+
# get partitions
56+
type_efi=EFI\ System
57+
partition_number=`fdisk -l | grep "$type_efi" | awk -F' ' '{print $1}' | wc -l`
58+
if [ $partition_number != "1" ]; then
59+
echo "Multiple partitions detected."
60+
c=0
61+
for i in `fdisk -l | grep "$type_efi" | awk -F' ' '{print $1}'`; do
62+
if [[ ! -z $efi_partition ]]; then break; fi
63+
c=$((c+1))
64+
echo "$c. $i"
65+
while true; do
66+
read -p "Do you wish to setup on this partition ? (Y/N)" yn
67+
case $yn in
68+
[Yy]* ) efi_partition=$i; break;;
69+
[Nn]* ) break;;
70+
* ) echo "Please input yes or no.";;
71+
esac
72+
done
73+
done
74+
else
75+
efi_partition=`fdisk -l | grep "$type_efi" | awk -F' ' '{print $1}'`
76+
fi
77+
78+
if [[ -z $efi_partition ]]; then echo "You didn't choose a partition, please try it again."; exit 1; fi
79+
efi_mount_point=`findmnt $efi_partition -n | cut -d' ' -f1`
80+
root_partition=`echo $efi_partition | sed 's/[0-9]$/3/g'`
81+
partition=`echo $efi_partition | sed 's/[0-9]$//g'`
82+
# unmount efi partition if it's already mounted
83+
if [[ -n $efi_mount_point ]]; then
84+
echo "Unmount EFI partition: $efi_mount_point..."
85+
umount $efi_mount_point
86+
fi
87+
88+
echo "Disable auto update..."
3789
swupd autoupdate --disable
3890

3991
# Compare with current clear linux and skip upgrade sos if get the same version.
40-
if [[ $(echo -e `swupd info` | cut -d' ' -f3) -eq $target_version ]]; then
41-
echo "Specified to the same clear linux version, continue to setup sos env."
92+
source /etc/os-release
93+
if [[ $VERSION_ID -eq $target_version ]]; then
94+
echo "Specify with the same clear linux version, continue to setup sos..."
4295
else
4396
echo "Upgrade clear linux version to : $target_version ..."
4497
swupd verify --fix --picky -m $target_version
@@ -49,16 +102,24 @@ if [[ $? -eq 0 ]]; then
49102
echo "Add service-os kernel-iot-lts2018 bundle"
50103
swupd bundle-add service-os kernel-iot-lts2018
51104

52-
echo "mount /dev/sda1 to /mnt"
53-
mount /dev/sda1 /mnt
54-
105+
mount $efi_partition /mnt
55106
echo "Add /mnt/EFI/acrn folder"
56107
mkdir -p /mnt/EFI/acrn
57-
echo "Copy /usr/share/acrn/samples/nuc/acrn.conf /mnt/loader/entries/"
58-
cp -r /usr/share/acrn/samples/nuc/acrn.conf /mnt/loader/entries/
59-
echo "Copy acrn.efi to /mnt/EFI/acrn"
60-
cp -r /usr/lib/acrn/acrn.efi /mnt/EFI/acrn/
61-
108+
echo "Copy $acrn_conf_path /mnt/loader/entries/"
109+
if [[ ! -f $acrn_conf_path ]]; then
110+
echo "Missing acrn.conf file in folder: $acrn_conf_path"
111+
umount /mnt && sync
112+
exit 1
113+
fi
114+
cp -r $acrn_conf_path /mnt/loader/entries/
115+
if [[ $? -ne 0 ]]; then echo "You didn't choose an right EFI partition." && exit 1; fi
116+
echo "Copy $acrn_efi_path to /mnt/EFI/acrn"
117+
if [[ ! -f $acrn_efi_path ]]; then
118+
echo "Missing acrn.efi file in folder: $acrn_efi_path"
119+
umount /mnt && sync
120+
exit 1
121+
fi
122+
cp -r $acrn_efi_path /mnt/EFI/acrn/
62123
echo "Check ACRN efi boot event"
63124
check_acrn_bootefi=`efibootmgr | grep ACRN`
64125
if [[ "$check_arcn_bootefi" -ge "ACRN" ]]; then
@@ -73,22 +134,22 @@ if [[ $? -eq 0 ]]; then
73134
fi
74135

75136
echo "Add new ACRN efi boot event"
76-
efibootmgr -c -l "\EFI\acrn\acrn.efi" -d /dev/sda -p 1 -L "ACRN"
137+
efibootmgr -c -l "\EFI\acrn\acrn.efi" -d $partition -p 1 -L "ACRN"
77138

78139
echo "Create loader.conf"
79-
rm /mnt/loader/loader.conf && touch /mnt/loader/loader.conf
140+
mv /mnt/loader/loader.conf /mnt/loader/loader.conf.bck && touch /mnt/loader/loader.conf
80141
echo "Add default boot wait time"
81142
echo "timeout 5" > /mnt/loader/loader.conf
82143
echo "Add default boot to ACRN"
83144
echo "default acrn" >> /mnt/loader/loader.conf
84145

85-
echo "Getting latest Service OS kernel version: "
86146
new_kernel=`ls /mnt/EFI/org.clearlinux/*sos* -tl | grep kernel | head -n1 | awk -F'/' '{print $5}'`
87-
echo "Get current sos kernel from acrn.conf file: "
147+
echo "Getting latest Service OS kernel version: $new_kernel"
88148
cur_kernel=`cat /mnt/loader/entries/acrn.conf | sed -n 2p | cut -d'/' -f4`
149+
echo "Getting current Service OS kernel version: $cur_kernel"
89150

90-
echo "Replace root uuid from acrn.conf"
91-
sed -i "s/<UUID of rootfs partition>/`blkid -s PARTUUID -o value /dev/sda3`/g" /mnt/loader/entries/acrn.conf
151+
echo "Replacing root partition uuid in acrn.conf"
152+
sed -i "s/<UUID of rootfs partition>/`blkid -s PARTUUID -o value $root_partition`/g" /mnt/loader/entries/acrn.conf
92153

93154
if [[ "$cur_kernel" == "$new_kernel" ]]; then
94155
echo "No need to replace kernel conf info"
@@ -97,68 +158,77 @@ if [[ $? -eq 0 ]]; then
97158
sed -i "s/$cur_kernel/$new_kernel/g" /mnt/loader/entries/acrn.conf
98159
fi
99160

100-
echo "Sos process done!"
101-
echo " ***** Please reboot device to test on new sos. *****"
161+
echo "Service OS setup done!"
162+
echo "Rebooting Service OS to taking effect changes."
102163
else
103164
echo -e "Fail to upgrade sos $target_clearlinux from mirror url."
104165
fi
105166

106-
echo "Init swupd mirror & proxy"
107-
swupd mirror -u
108-
unset https_proxy
109167
umount /mnt
168+
sync
169+
reboot
110170
}
111171

112172
function upgrade_uos()
113173
{
114-
# Add proxy if you need to download uos img automatically.
174+
# UOS download link
175+
uos_image_link="https://download.clearlinux.org/releases/$target_version/clear/clear-$target_version-kvm.img.xz"
176+
177+
# Set proxy if needed.
115178
if [[ -n $proxy ]]; then
116-
echo "Add proxy..."
179+
echo "Setting proxy to: $proxy"
117180
export https_proxy=$proxy
118181
fi
119182

183+
if [[ ! -z `findmnt /mnt -n` ]]; then umount /mnt; fi
184+
120185
# Do upgrade uos process.
121186
if [[ $skip_download_uos == 1 ]]; then
122-
uos_img_xz_path=$(find ~/ -name clear-$target_version-kvm.img.xz)
123-
uos_img_path=$(find ~/ -name clear-$target_version-kvm.img)
124-
if [[ ! -f $uos_img_xz_path ]] && [[ ! -f $uos_img_path ]]; then
125-
echo "You should download uos clear-$target_version-kvm.img.xz file firstly." && exit
187+
uos_img_xz=$(find ~/ -name clear-$target_version-kvm.img.xz)
188+
uos_img=$(find ~/ -name clear-$target_version-kvm.img)
189+
if [[ ! -f $uos_img_xz ]] && [[ ! -f $uos_img ]]; then
190+
echo "You should download uos clear-$target_version-kvm.img.xz file firstly." && exit 1
126191
fi
127-
if [[ -f $uos_img_xz_path ]]; then
128-
echo "get uos xz file in: $uos_img_xz_path"
129-
unxz $uos_img_xz_path
130-
uos_img_path=$(find ~/ -name clear-$target_version-kvm.img)
192+
if [[ -f $uos_img_xz ]]; then
193+
echo "Unxz uos file: $uos_img_xz"
194+
unxz $uos_img_xz
195+
uos_img=`echo $uos_img_xz | sed 's/.xz$//g'`
131196
fi
132-
echo "get uos img file in: $uos_img_path"
197+
echo "get uos img file: $uos_img"
133198
if [[ $? -eq 0 ]]; then
134-
losetup -f -P --show $uos_img_path
199+
uos_partition=`losetup -f -P --show $uos_img`p3
135200
else
136201
echo "fail to losetup uos img, please check uos img status" && exit 1
137202
fi
138-
mount /dev/loop0p3 /mnt
203+
mount $uos_partition /mnt
139204
cp -r /usr/lib/modules/"`readlink /usr/lib/kernel/default-iot-lts2018 | awk -F '2018.' '{print $2}'`.iot-lts2018" /mnt/lib/modules
140-
umount /mnt
141-
sync
142205
else
143206
cd ~
144-
curl https://download.clearlinux.org/releases/$target_version/clear/clear-$target_version-kvm.img.xz -o clear-$target_version-kvm.img.xz
207+
echo "Downloading UOS image: $uos_image_link"
208+
curl $uos_image_link -o clear-$target_version-kvm.img.xz
209+
uos_img=clear-$target_version-kvm.img
210+
if [[ -f $uos_img ]] && [[ -f $uos_img.xz ]]; then echo "Moving $uos_img to $uos_img.old."; mv $uos_img $uos_img.old; fi
145211
if [[ $? -eq 0 ]]; then
212+
echo "Unxz UOS image: clear-$target_version-kvm.img.xz"
146213
unxz clear-$target_version-kvm.img.xz
147214
fi
148215
if [[ $? -eq 0 ]]; then
149-
losetup -f -P --show clear-$target_version-kvm.img
216+
uos_partition=`losetup -f -P --show $uos_img`p3
217+
else
218+
echo "Missing UOS file: $uos_img, please check if UOS is exist." && exit 1
150219
fi
151-
mount /dev/loop0p3 /mnt
220+
mount $uos_partition /mnt
152221
cp -r /usr/lib/modules/"`readlink /usr/lib/kernel/default-iot-lts2018 | awk -F '2018.' '{print $2}'`.iot-lts2018" /mnt/lib/modules
153-
umount /mnt
154-
sync
155222
fi
156-
uos_img_path=$(find ~/ -name clear-$target_version-kvm.img)
223+
umount /mnt
224+
losetup -D
225+
sync
226+
157227
cp -r /usr/share/acrn/samples/nuc/launch_uos.sh ~/
158-
sed -i "s/\(virtio-blk.*\)\/home\/clear\/uos\/uos.img/\1$(echo $uos_img_path | sed "s/\//\\\\\//g")/" ~/launch_uos.sh
159-
echo "Upgrade uos done..."
228+
sed -i "s/\(virtio-blk.*\)\/home\/clear\/uos\/uos.img/\1$(echo $uos_img | sed "s/\//\\\\\//g")/" ~/launch_uos.sh
229+
echo "Upgrade UOS done..."
160230
echo "Now you can run below command to start UOS..."
161-
echo "# cd ~/ && ./launch_uos.sh -V 1"
231+
echo "# cd ~/ && ./launch_uos.sh"
162232
}
163233

164234
# Set script options.
@@ -193,14 +263,14 @@ if [[ `echo $target_version | awk '{print length($0)}'` -ne 5 ]]; then
193263
fi
194264

195265
if [[ $upgrade_uos == 1 ]]; then
196-
echo "Start upgrading uos to: $target_version ..."
266+
echo "Upgrading UOS to: $target_version ..."
197267
upgrade_uos
198268
exit
199269
fi
200270

201-
# Exit script if you specified an newer clear linux ver.
271+
# Exit script if you specified an newer clear linux version.
202272
if [[ $(echo -e `swupd info` | cut -d' ' -f3) -gt $target_version ]]; then
203-
echo -e 'No need to upgrade sos.' && exit
273+
echo -e 'No need to upgrade Service OS.' && exit
204274
else
205275
upgrade_sos
206276
exit

0 commit comments

Comments
 (0)