doc: Add industry argument for auto setup script

Also fix efibootmgr not set correct issue.

Signed-off-by: lirui34 <ruix.li@intel.com>
This commit is contained in:
lirui34 2019-10-25 19:42:27 +08:00 committed by wenlingz
parent fd821d55bc
commit bbc228e6b3

View File

@ -2,29 +2,30 @@
# Copyright (C) 2019 Intel Corporation.
# SPDX-License-Identifier: BSD-3-Clause
#
# This script provides a quick and automatic setup of the SOS or UOS.
# This script provides a quick and automatic setup of the Service VM or User VM.
# You should run this script with root privilege since it will modify various system parameters.
#
# Usages:
# Upgrade SOS to 31080 without reboot, it's highly recommended so that you can check configurations after upgrade SOS.
# Upgrade Service VM to 31080 without reboot, it's highly recommended so that you can check configurations after upgrade Service VM.
# sudo <script> -s 31080 -d
# Upgrade SOS to 31080 with specified proxy server
# Upgrade Service VM to 31080 with specified proxy server
# sudo <script> -s 31080 -p <your proxy server>:<port>
# Upgrade UOS to 31080 with specified proxy server
# Upgrade User VM to 31080 with specified proxy server
# sudo <script> -u 31080 -p <your proxy server>:<port>
# Upgrade UOS to 31080 without downloading UOS image, you should put UOS image in /root directory previously.
# Upgrade User VM to 31080 without downloading User VM image, you should put User VM image in /root directory previously.
# sudo <script> -u 31080 -k
function print_help()
{
echo "Usage:"
echo "Launch this script as: sudo $0 -s 31080"
echo -e "\t-s to upgrade SOS"
echo -e "\t-u to upgrade UOS"
echo -e "\t-s to upgrade Service VM"
echo -e "\t-u to upgrade User VM"
echo -e "\t-p to specify a proxy server (HTTPS)"
echo -e "\t-m to use swupd mirror url"
echo -e "\t-k to skip downloading UOS; if enabled, you have to download UOS img firstly before upgrading, default is off"
echo -e "\t-d to disable reboot device so that you can check the configurations after upgrading SOS"
echo -e "\t-k to skip downloading User VM; if enabled, you have to download User VM img firstly before upgrading, default is off"
echo -e "\t-d to disable reboot device so that you can check the configurations after upgrading Service VM"
echo -e "\t-i to set up Service VM with industry scenario"
echo -e "\t-e to specify EFI System Partition (ESP), default: /dev/sda1"
echo -e "\n\t<Note>:"
echo -e "\tThis script is using /dev/sda1 as default EFI System Partition (ESP)."
@ -36,7 +37,7 @@ function print_help()
# get clear linux version previously
source /etc/os-release
# switcher for download UOS function
# switcher for download User VM function
skip_download_uos=0
# switcher for disabling reboot device
disable_reboot=0
@ -46,11 +47,11 @@ acrn_efi_path=/usr/lib/acrn/acrn.nuc6cayh.sdc.efi
function upgrade_sos()
{
# Check SOS version
[[ `echo $sos_ver | awk '{print length($0)}'` -ne 5 ]] && echo "Please input right SOS version to upgrade" && exit 1
# Check Service VM version
[[ `echo $sos_ver | awk '{print length($0)}'` -ne 5 ]] && echo "Please input right Service VM version to upgrade" && exit 1
[[ $VERSION_ID -gt $sos_ver ]] && echo "You're trying to install an older version of Clear Linux." && exit 1
echo "Upgrading SOS..."
echo "Upgrading Service VM..."
# setup mirror and proxy url while specified with m and p options
[[ -n $mirror ]] && echo "Setting swupd mirror to: $mirror" && swupd mirror -s $mirror
@ -63,9 +64,9 @@ function upgrade_sos()
echo "Disable auto update..."
swupd autoupdate --disable 2>/dev/null
# Compare with current clear linux and skip upgrade SOS if get the same version.
# Compare with current clear linux and skip upgrade Service VM if get the same version.
if [[ $VERSION_ID -eq $sos_ver ]]; then
echo "Clear Linux version $sos_ver is already installed. Continuing to setup SOS..."
echo "Clear Linux version $sos_ver is already installed. Continuing to setup Service VM..."
else
echo "Upgrading Clear Linux version from $VERSION_ID to $sos_ver ..."
swupd repair --picky -V $sos_ver 2>/dev/null
@ -87,9 +88,21 @@ function upgrade_sos()
fi
cp -a $acrn_efi_path /mnt/EFI/acrn/acrn.efi
if [[ $? -ne 0 ]]; then echo "Fail to copy $acrn_efi_path" && exit 1; fi
new_kernel=`ls /mnt/EFI/org.clearlinux/*sos* -tl | grep kernel | head -n1 | awk -F'/' '{print $5}'`
new_kernel=${new_kernel#kernel-}
echo "Getting latest Service OS kernel version: $new_kernel"
echo "Add default (5 seconds) boot wait time."
clr-boot-manager set-timeout 5 || { echo "Faild to add default boot wait time" && exit 1; }
clr-boot-manager update
echo "Set $new_kernel as default boot kernel."
clr-boot-manager set-kernel $new_kernel || { echo "Fail to set $new_kernel as default boot kernel." && exit 1; }
echo "Check ACRN efi boot event"
check_acrn_bootefi=`efibootmgr | grep ACRN`
if [[ "$check_acrn_bootefi" -ge "ACRN" ]]; then
check_acrn_bootefi=`efibootmgr | grep ACRN | wc -l`
if [[ "$check_acrn_bootefi" -ge 1 ]]; then
echo "Clean all ACRN efi boot event"
efibootmgr | grep ACRN | cut -d'*' -f1 | cut -d't' -f2 | xargs -i efibootmgr -b {} -B >/dev/null
fi
@ -103,21 +116,10 @@ function upgrade_sos()
echo "Add new ACRN efi boot event"
efibootmgr -c -l "\EFI\acrn\acrn.efi" -d $partition -p 1 -L "ACRN" >/dev/null
new_kernel=`ls /mnt/EFI/org.clearlinux/*sos* -tl | grep kernel | head -n1 | awk -F'/' '{print $5}'`
new_kernel=${new_kernel#kernel-}
echo "Getting latest Service OS kernel version: $new_kernel"
echo "Add default (5 seconds) boot wait time."
clr-boot-manager set-timeout 5 || { echo "Faild to add default boot wait time" && exit 1; }
clr-boot-manager update
echo "Set $new_kernel as default boot kernel."
clr-boot-manager set-kernel $new_kernel || { echo "Fail to set $new_kernel as default boot kernel." && exit 1; }
echo "Service OS setup done!"
else
echo "Fail to upgrade SOS to $sos_ver."
echo "Please try upgrade SOS with this command:"
echo "Fail to upgrade Service VM to $sos_ver."
echo "Please try upgrade Service VM with this command:"
echo "swupd update -V $sos_ver"
exit 1
fi
@ -129,29 +131,29 @@ function upgrade_sos()
function upgrade_uos()
{
# Check UOS version
[[ `echo $uos_ver | awk '{print length($0)}'` -ne 5 ]] && echo "Please input right UOS version to upgrade" && exit 1
# Check User VM version
[[ `echo $uos_ver | awk '{print length($0)}'` -ne 5 ]] && echo "Please input right User VM version to upgrade" && exit 1
echo "Upgrading UOS..."
echo "Upgrading User VM..."
# UOS download link
# User VM download link
uos_image_link="https://download.clearlinux.org/releases/$uos_ver/clear/clear-$uos_ver-kvm.img.xz"
# Set proxy if needed.
[[ -n $proxy ]] && echo "Setting proxy to: $proxy" && export https_proxy=$proxy
# Corrupt script if /mnt is already mounted.
if [[ ! -z `findmnt /mnt -n` ]]; then
echo "/mnt is already mounted, please unmount it if you want to continue upgrade UOS."
echo "/mnt is already mounted, please unmount it if you want to continue upgrade User VM."
exit 1
fi
# Do upgrade UOS process.
# Do upgrade User VM process.
if [[ $skip_download_uos != 1 ]]; then
cd ~
echo "Downloading UOS image: $uos_image_link"
echo "Downloading User VM image: $uos_image_link"
curl $uos_image_link -o clear-$uos_ver-kvm.img.xz
if [[ $? -ne 0 ]]; then
echo "Download UOS failed."
echo "Download User VM failed."
rm clear-$uos_ver-kvm.img.xz
exit 1
fi
@ -161,19 +163,19 @@ function upgrade_uos()
uos_img=$(find ~/ -name clear-$uos_ver-kvm.img)
if [[ -f $uos_img ]] && [[ -f $uos_img.xz ]]; then echo "Moving $uos_img to $uos_img.old."; mv $uos_img $uos_img.old; fi
if [[ ! -f $uos_img_xz ]] && [[ ! -f $uos_img ]]; then
echo "You should download UOS clear-$uos_ver-kvm.img.xz file firstly." && exit 1
echo "You should download User VM clear-$uos_ver-kvm.img.xz file firstly." && exit 1
fi
if [[ -f $uos_img_xz ]]; then
echo "Unxz UOS file: $uos_img_xz"
echo "Unxz User VM file: $uos_img_xz"
unxz $uos_img_xz
uos_img=`echo $uos_img_xz | sed 's/.xz$//g'`
fi
echo "Get UOS image: $uos_img"
echo "Get User VM image: $uos_img"
uos_loop_device=`losetup -f -P --show $uos_img`
mount ${uos_loop_device}p3 /mnt || { echo "Fail to mount UOS rootfs partition" && exit 1; }
mount ${uos_loop_device}p1 /mnt/boot || { echo "Fail to mount UOS EFI partition" && exit 1; }
mount ${uos_loop_device}p3 /mnt || { echo "Fail to mount User VM rootfs partition" && exit 1; }
mount ${uos_loop_device}p1 /mnt/boot || { echo "Fail to mount User VM EFI partition" && exit 1; }
echo "Install kernel-iot-lts2018 to $uos_img"
swupd bundle-add --path=/mnt kernel-iot-lts2018 || { echo "Fail to install kernel-iot-lts2018" && exit 1; }
@ -190,14 +192,14 @@ function upgrade_uos()
cp -r /usr/share/acrn/samples/nuc/launch_uos.sh ~/launch_uos_$uos_ver.sh
sed -i "s/\(virtio-blk.*\)\/home\/clear\/uos\/uos.img/\1$(echo $uos_img | sed "s/\//\\\\\//g")/" ~/launch_uos_$uos_ver.sh
[[ -z `grep $uos_img ~/launch_uos_$uos_ver.sh` ]] && echo "Fail to replace uos image in launch script: ~/launch_uos_$uos_ver.sh" && exit 1
echo "Upgrade UOS done..."
echo "Now you can run this command to start UOS..."
echo "Upgrade User VM done..."
echo "Now you can run this command to start User VM..."
echo "sudo /root/launch_uos_$uos_ver.sh"
exit
}
# Set script options.
while getopts "s:u:p:m:e:kdh" opt
while getopts "s:u:p:m:e:kdhi" opt
do
case "$opt" in
s) sos_ver="$OPTARG"
@ -216,6 +218,8 @@ do
;;
h) print_help
;;
i) acrn_efi_path=/usr/lib/acrn/acrn.kbl-nuc-i7.industry.efi
;;
?) print_help
;;
esac
@ -225,5 +229,5 @@ done
[[ $EUID -ne 0 ]] && echo "You have to run script as root." && exit 1
[[ -z $1 ]] && print_help
[[ -z $efi_partition ]] && efi_partition=/dev/sda1 || echo "Setting EFI System partition to: $efi_partition..."
[[ -n $sos_ver && -n $uos_ver ]] && echo "You should select upgrading SOS or UOS" && exit 1
[[ -n $sos_ver && -n $uos_ver ]] && echo "You should select upgrading Service VM or User VM" && exit 1
[[ -n $uos_ver ]] && upgrade_uos || upgrade_sos