[aboot]: refactor boot0.j2 to support one image SONiC-to-SONiC upgrade (#557)

* [aboot]: refactor boot0.j2 to support one image upgrade

* support sonic_installer in aboot
This commit is contained in:
lguohan 2017-05-01 15:16:33 -07:00 committed by GitHub
parent 611de29ef7
commit 72a039b1de
2 changed files with 23 additions and 18 deletions

View File

@ -24,7 +24,7 @@ kernel_params=kernel-params
aboot_machine="arista_unknown"
target_path=/mnt/flash
[ -z "$target_path" ] && target_path=/mnt/flash
image_path="$target_path/image-%%IMAGE_VERSION%%"
# expect the swi to be a non empty file
@ -41,15 +41,18 @@ parse_environment_config() {
done
}
extract_image() {
clean_flash() {
## Remove all the other unnecssary files except swi file, boot-config
for f in $(ls -A $target_path); do
if [ $f != "${swipath##*/}" ] && [ $f != "boot-config" ]; then
rm -rf "$target_path/$f"
fi
done
}
mkdir "$image_path"
extract_image() {
mkdir -p "$image_path"
## Unzip the image
unzip -oq "$swipath" -x boot0 -d "$image_path"
@ -58,10 +61,10 @@ extract_image() {
rm -f $swipath
## detect rootfs type
rootfs_type=`grep /mnt/flash /proc/mounts | cut -d' ' -f3`
rootfs_type=`grep " $target_path " /proc/mounts | cut -d' ' -f3`
## vfat does not support symbol link
if [ $rootfs_type != "vfat" ]; then
if [ -n "$sonic_upgrade" ] || [ "$rootfs_type" != "vfat" ]; then
mkdir -p "$image_path/{{ DOCKERFS_DIR }}"
## extract docker archive
@ -70,15 +73,12 @@ extract_image() {
## clean up docker archive
rm -f "$image_path/{{ FILESYSTEM_DOCKERFS }}"
else
echo "/mnt/flash is $rootfs_type, extract {{ FILESYSTEM_DOCKERFS }} in later stage"
echo "$target_path is $rootfs_type, extract {{ FILESYSTEM_DOCKERFS }} in later stage"
fi
## use new reduced-size boot swi
echo "SWI=flash:image-%%IMAGE_VERSION%%/{{ ABOOT_BOOT_IMAGE }}" > "$target_path/boot-config"
## remove original boot swi
rm -f "$swipath"
## sync disk operations
sync
}
@ -120,6 +120,17 @@ platform_specific() {
fi
}
# check the hash file in the image, and determine to install or just skip
GIT_REVISION=$(unzip -p "$swipath" .imagehash)
LOCAL_IMAGEHASH=$(cat $image_path/.imagehash 2>/dev/null || true)
if [ "$GIT_REVISION" != "$LOCAL_IMAGEHASH" ]; then
[ -z "$sonic_upgrade" ] && clean_flash
extract_image
fi
[ -z "$sonic_upgrade" ] || exit 0
# build the new cmdline
echo "$append" >/tmp/append
parse_environment_config >>/tmp/append
cat /etc/cmdline | sed "/^\(${bootconfigvars// /\|}\|crashkernel\|loglevel\|ignore_loglevel\)\(\$\|=\)/d;/^\$/d" >>/tmp/append
@ -129,6 +140,8 @@ echo "rw loop=image-%%IMAGE_VERSION%%/fs.squashfs loopfstype=squashfs apparmor=1
# process platform specific operations
platform_specific
[ -e ${taget_path}/machine.conf ] || write_machine_config
# use extra parameters from kernel-params hook if the file exists
if [ -f "$image_path/$kernel_params" ]; then
cat "$image_path/$kernel_params" >>/tmp/append
@ -141,14 +154,6 @@ if ! grep -q "root=" /tmp/append; then
echo "root=$rootdev" >>/tmp/append
fi
# check the hash file in the image, and determine to install or just skip
GIT_REVISION=$(unzip -p "$swipath" .imagehash)
LOCAL_IMAGEHASH=$(cat $image_path/.imagehash 2>/dev/null || true)
if [ "$GIT_REVISION" != "$LOCAL_IMAGEHASH" ]; then
extract_image
write_machine_config
fi
# chainloading using kexec
initrd_path="$image_path/$initrd"
kernel_path="$image_path/$kernel"

@ -1 +1 @@
Subproject commit 790aa8380d2fb8fce0097a27556a415e69441f14
Subproject commit 452df11df5a47e1d646e5ce846757112b526694f