Skip to content

Commit

Permalink
[image]: SONiC-to-SONiC update (#464)
Browse files Browse the repository at this point in the history
  • Loading branch information
andriymoroz-mlnx authored and lguohan committed Apr 22, 2017
1 parent 07bc009 commit b549adc
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 107 deletions.
6 changes: 5 additions & 1 deletion build_debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,11 @@ sudo dpkg --root=$FILESYSTEM_ROOT -i target/debs/linux-image-3.16.0-4-amd64_*.de
## Update initramfs for booting with squashfs+aufs
cat files/initramfs-tools/modules | sudo tee -a $FILESYSTEM_ROOT/etc/initramfs-tools/modules > /dev/null

IMAGE_VERSION=$(. functions.sh && sonic_get_version)

## Hook into initramfs: change fs type from vfat to ext4 on arista switches
sudo mkdir -p $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/
sed -i -e "s/%%IMAGE_VERSION%%/$IMAGE_VERSION/g" files/initramfs-tools/arista-convertfs
sudo cp files/initramfs-tools/arista-convertfs $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/arista-convertfs
sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/arista-convertfs
sudo cp files/initramfs-tools/mke2fs $FILESYSTEM_ROOT/etc/initramfs-tools/hooks/mke2fs
Expand Down Expand Up @@ -195,7 +198,8 @@ sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y in
iptables-persistent \
logrotate \
curl \
kexec-tools
kexec-tools \
unzip

## Disable kexec supported reboot which was installed by default
sudo sed -i 's/LOAD_KEXEC=true/LOAD_KEXEC=false/' $FILESYSTEM_ROOT/etc/default/kexec
Expand Down
1 change: 1 addition & 0 deletions build_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ elif [ "$IMAGE_TYPE" = "aboot" ]; then
cp $ONIE_INSTALLER_PAYLOAD $OUTPUT_ABOOT_IMAGE
## Add Aboot boot0 file
j2 -f env files/Aboot/boot0.j2 ./onie-image.conf > files/Aboot/boot0
sed -i -e "s/%%IMAGE_VERSION%%/$IMAGE_VERSION/g" files/Aboot/boot0
pushd files/Aboot && zip -g $OLDPWD/$OUTPUT_ABOOT_IMAGE boot0; popd
pushd files/Aboot && zip -g $OLDPWD/$ABOOT_BOOT_IMAGE boot0; popd
echo "$IMAGE_VERSION" >> .imagehash
Expand Down
30 changes: 18 additions & 12 deletions files/Aboot/boot0.j2
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ kernel_params=kernel-params
aboot_machine="arista_unknown"

target_path=/mnt/flash
image_path="$target_path/image-%%IMAGE_VERSION%%"

# expect the swi to be a non empty file
[ -s "$swipath" ] || exit 1
Expand All @@ -48,8 +49,10 @@ extract_image() {
fi
done

mkdir "$image_path"

## Unzip the image
unzip -oq "$swipath" -x boot0 -d "$target_path"
unzip -oq "$swipath" -x boot0 -d "$image_path"

## Remove installer swi as it has lots of redundunt contents
rm -f $swipath
Expand All @@ -59,19 +62,22 @@ extract_image() {

## vfat does not support symbol link
if [ $rootfs_type != "vfat" ]; then
mkdir -p "$target_path/{{ DOCKERFS_DIR }}"
mkdir -p "$image_path/{{ DOCKERFS_DIR }}"

## extract docker archive
tar xf "$target_path/{{ FILESYSTEM_DOCKERFS }}" -C "$target_path/{{ DOCKERFS_DIR }}"
tar xf "$image_path/{{ FILESYSTEM_DOCKERFS }}" -C "$image_path/{{ DOCKERFS_DIR }}"

## clean up docker archive
rm -f "$target_path/{{ FILESYSTEM_DOCKERFS }}"
rm -f "$image_path/{{ FILESYSTEM_DOCKERFS }}"
else
echo "/mnt/flash is $rootfs_type, extract {{ FILESYSTEM_DOCKERFS }} in later stage"
fi

## replace with boot swi
mv "$target_path/{{ ABOOT_BOOT_IMAGE }}" "$swipath"
## 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 @@ -118,14 +124,14 @@ echo "$append" >/tmp/append
parse_environment_config >>/tmp/append
cat /etc/cmdline | sed "/^\(${bootconfigvars// /\|}\|crashkernel\|loglevel\|ignore_loglevel\)\(\$\|=\)/d;/^\$/d" >>/tmp/append

echo "rw loop=fs.squashfs loopfstype=squashfs apparmor=1 security=apparmor quiet" >>/tmp/append
echo "rw loop=image-%%IMAGE_VERSION%%/fs.squashfs loopfstype=squashfs apparmor=1 security=apparmor quiet" >>/tmp/append

# process platform specific operations
platform_specific

# use extra parameters from kernel-params hook if the file exists
if [ -f "$target_path/$kernel_params" ]; then
cat "$target_path/$kernel_params" >>/tmp/append
if [ -f "$image_path/$kernel_params" ]; then
cat "$image_path/$kernel_params" >>/tmp/append
fi

# setting root partition if not overridden by kernel-params
Expand All @@ -137,15 +143,15 @@ fi

# check the hash file in the image, and determine to install or just skip
GIT_REVISION=$(unzip -p "$swipath" .imagehash)
LOCAL_IMAGEHASH=$(cat $target_path/.imagehash 2>/dev/null || true)
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="$target_path/$initrd"
kernel_path="$target_path/$kernel"
initrd_path="$image_path/$initrd"
kernel_path="$image_path/$kernel"
cmdline="$(tr '\n' ' ' </tmp/append)"

kexec --load --initrd="$initrd_path" --append="$cmdline" "$kernel_path"
Expand Down
12 changes: 7 additions & 5 deletions files/image_config/platform/rc.local
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,27 @@

echo "install platform dependent packages at the first boot time"

if [ -f /host/platform/firsttime ]; then
sonic_version=$(cat /etc/sonic/sonic_version.yml | grep build_version | cut -f2 -d" ")

if [ -f /host/image-$sonic_version/platform/firsttime ]; then

if [ -n "$aboot_platform" ]; then
platform=$aboot_platform
elif [ -n "$onie_platform" ]; then
platform=$onie_platform
else
echo "Unknown sonic platform"
rm /host/platform/firsttime
rm /host/image-$sonic_version/platform/firsttime
exit 0
fi

cp /usr/share/sonic/device/$platform/minigraph.xml /etc/sonic/

if [ -d /host/platform/$platform ]; then
dpkg -i /host/platform/$platform/*.deb
if [ -d /host/image-$sonic_version/platform/$platform ]; then
dpkg -i /host/image-$sonic_version/platform/$platform/*.deb
fi

rm /host/platform/firsttime
rm /host/image-$sonic_version/platform/firsttime
fi

exit 0
6 changes: 5 additions & 1 deletion files/initramfs-tools/arista-convertfs.j2
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ for x in "$@"; do
;;
varlog_size=*)
varlog_size="${x#varlog_size=}"
;;
image_dir=*)
x1="${x#loop=}"
image_dir="${x1%/*}"
esac
done
root_dev="$ROOT"
Expand Down Expand Up @@ -191,7 +195,7 @@ cmd="mount -t ext4 $root_dev $root_mnt"
run_cmd "$cmd" "$err_msg"

err_msg="Error: extract docker directory"
cmd="[ -f $tmp_mnt/{{ FILESYSTEM_DOCKERFS }} ] && rm -rf $root_mnt/{{ DOCKERFS_DIR }} && mkdir $root_mnt/{{ DOCKERFS_DIR }} && tar xzf $tmp_mnt/{{ FILESYSTEM_DOCKERFS }} -C $root_mnt/{{ DOCKERFS_DIR }} && rm -f $tmp_mnt/{{ FILESYSTEM_DOCKERFS }}"
cmd="[ -f $tmp_mnt/$image_dir/{{ FILESYSTEM_DOCKERFS }} ] && rm -rf $root_mnt/$image_dir/{{ DOCKERFS_DIR }} && mkdir -p $root_mnt/$image_dir/{{ DOCKERFS_DIR }} && tar xzf $tmp_mnt/$image_dir/{{ FILESYSTEM_DOCKERFS }} -C $root_mnt/$image_dir/{{ DOCKERFS_DIR }} && rm -f $tmp_mnt/$image_dir/{{ FILESYSTEM_DOCKERFS }}"
run_cmd "$cmd" "$err_msg"

err_msg="Error: copying files form $tmp_mnt to $root_mnt failed"
Expand Down
9 changes: 5 additions & 4 deletions files/initramfs-tools/union-mount.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ case $1 in
esac

## Mount the aufs file system: rw layer over squashfs
mkdir -p ${rootmnt}/host/rw
mount -n -o dirs=${rootmnt}/host/rw:${rootmnt}=ro -t aufs root-aufs ${rootmnt}
image_dir=$(cat /proc/cmdline | sed -e 's/.*loop=\(\S*\)\/.*/\1/')
mkdir -p ${rootmnt}/host/$image_dir/rw
mount -n -o dirs=${rootmnt}/host/$image_dir/rw:${rootmnt}=ro -t aufs root-aufs ${rootmnt}
## Check if the root block device is still there
[ -b ${ROOT} ] || mdev -s
## Mount the raw partition again
mount ${ROOT} ${rootmnt}/host
## Mount the working directory of docker engine in the raw partition, bypass the aufs
mkdir -p ${rootmnt}/var/lib/docker
mount --bind ${rootmnt}/host/{{ DOCKERFS_DIR }} ${rootmnt}/var/lib/docker
mount --bind ${rootmnt}/host/$image_dir/{{ DOCKERFS_DIR }} ${rootmnt}/var/lib/docker
## Mount the boot directory in the raw partition, bypass the aufs
mkdir -p ${rootmnt}/boot
mount --bind ${rootmnt}/host/boot ${rootmnt}/boot
mount --bind ${rootmnt}/host/$image_dir/boot ${rootmnt}/boot
## Mount loop device for /var/log
[ -f ${rootmnt}/host/disk-img/var-log.ext4 ] && mount -t ext4 -o loop,rw ${rootmnt}/host/disk-img/var-log.ext4 ${rootmnt}/var/log
Loading

0 comments on commit b549adc

Please sign in to comment.