Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SONiC-to-SONiC update #464

Merged
merged 9 commits into from
Apr 22, 2017
Merged
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
24 changes: 12 additions & 12 deletions files/Aboot/boot0.j2
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ parse_environment_config() {

extract_image() {
## Remove all the other unnecssary files except swi file, boot-config
for f in $(ls -A $target_path); do
for f in $(ls -A $target_path/image-%%IMAGE_VERSION%%); do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding image-%%IMAGE_VERSION%% everywhere it could be cleaner to just define a variable and use it instead of target_path where needs be.
image_path="$target_path/image-%%IMAGE_VERSION%%"

if [ $f != "${swipath##*/}" ] && [ $f != "boot-config" ]; then
rm -rf "$target_path/$f"
rm -rf "$target_path/image-%%IMAGE_VERSION%%/$f"
fi
done

## Unzip the image
unzip -oq "$swipath" -x boot0 -d "$target_path"
unzip -oq "$swipath" -x boot0 -d "$target_path/image-%%IMAGE_VERSION%%"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to create this path. I tested, and here are the errors.

ls: /mnt/flash/image-andriymoroz-mlnx-master.0-cf97eae: No such file or directory
+ unzip -oq /mnt/flash/sonic-aboot-broadcom.swi -x boot0 -d /mnt/flash/image-andriymoroz-mlnx-master.0-cf97eae
unzip: chdir(/mnt/flash/image-andriymoroz-mlnx-master.0-cf97eae): No such file or directory


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

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

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

## clean up docker archive
rm -f "$target_path/{{ FILESYSTEM_DOCKERFS }}"
rm -f "$target_path/image-%%IMAGE_VERSION%%/{{ 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"
mv "$target_path/image-%%IMAGE_VERSION%%/{{ ABOOT_BOOT_IMAGE }}" "$swipath"

## sync disk operations
sync
Expand Down Expand Up @@ -124,8 +124,8 @@ echo "rw loop=fs.squashfs loopfstype=squashfs apparmor=1 security=apparmor quiet
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 "$target_path/image-%%IMAGE_VERSION%%/$kernel_params" ]; then
cat "$target_path/image-%%IMAGE_VERSION%%/$kernel_params" >>/tmp/append
fi

# setting root partition if not overridden by kernel-params
Expand All @@ -137,15 +137,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 $target_path/image-%%IMAGE_VERSION%%/.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="$target_path/image-%%IMAGE_VERSION%%/$initrd"
kernel_path="$target_path/image-%%IMAGE_VERSION%%/$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
2 changes: 1 addition & 1 deletion files/initramfs-tools/arista-convertfs.j2
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,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-%%IMAGE_VERSION%%/{{ FILESYSTEM_DOCKERFS }} ] && rm -rf $root_mnt/image-%%IMAGE_VERSION%%/{{ DOCKERFS_DIR }} && mkdir $root_mnt/image-%%IMAGE_VERSION%%/{{ DOCKERFS_DIR }} && tar xzf $tmp_mnt/image-%%IMAGE_VERSION%%/{{ FILESYSTEM_DOCKERFS }} -C $root_mnt/image-%%IMAGE_VERSION%%/{{ DOCKERFS_DIR }} && rm -f $tmp_mnt/image-%%IMAGE_VERSION%%/{{ FILESYSTEM_DOCKERFS }}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment about having a temporary variable apply here.

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/BOOT_IMAGE=\/\(.*\)\/boot\(.*\)/\1/')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aboot0 does not pass BOOT_IMAGE in the cmdline, need to add that.

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change is going to break the arista aboot image.

if you search DOCKERFS_DIR, it is also used in files/initramfs-tools/arista-convertfs.j2 and files/Aboot/boot0.j2

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not need this commit to support sonic-to-sonic on arista aboot platform, but it is better not to break the existing func.

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