Skip to content

Commit

Permalink
[aboot]: refactor boot0.j2 to support one image SONiC-to-SONiC upgrade (
Browse files Browse the repository at this point in the history
#557)

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

* support sonic_installer in aboot
  • Loading branch information
lguohan committed May 1, 2017
1 parent 611de29 commit 72a039b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
39 changes: 22 additions & 17 deletions files/Aboot/boot0.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

extract_image() {

mkdir "$image_path"
mkdir -p "$image_path"

## Unzip the image
unzip -oq "$swipath" -x boot0 -d "$image_path"
Expand All @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/sonic-utilities

0 comments on commit 72a039b

Please sign in to comment.