diff --git a/build_debian.sh b/build_debian.sh index 9840280fc849..7d763a46f2e5 100755 --- a/build_debian.sh +++ b/build_debian.sh @@ -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 @@ -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 diff --git a/build_image.sh b/build_image.sh index 7ac3085463dd..a275c383c45d 100755 --- a/build_image.sh +++ b/build_image.sh @@ -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 diff --git a/files/Aboot/boot0.j2 b/files/Aboot/boot0.j2 index 6460ddbbecfc..42bf0719bff9 100644 --- a/files/Aboot/boot0.j2 +++ b/files/Aboot/boot0.j2 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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' ' ' > $grub_cfg menuentry '$demo_grub_entry' { search --no-floppy --label --set=root $demo_volume_label - echo 'Loading $demo_volume_revision_label $demo_type kernel ...' + echo 'Loading $demo_volume_label $demo_type kernel ...' insmod gzio if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi insmod part_msdos insmod ext2 - linux /boot/vmlinuz-3.16.0-4-amd64 root=$demo_dev rw $GRUB_CMDLINE_LINUX \ - loop=$FILESYSTEM_SQUASHFS loopfstype=squashfs \ + linux /$image_dir/boot/vmlinuz-3.16.0-4-amd64 root=$demo_dev rw $GRUB_CMDLINE_LINUX \ + loop=$image_dir/$FILESYSTEM_SQUASHFS loopfstype=squashfs \ apparmor=1 security=apparmor $ONIE_PLATFORM_EXTRA_CMDLINE_LINUX - echo 'Loading $demo_volume_revision_label $demo_type initial ramdisk ...' - initrd /boot/initrd.img-3.16.0-4-amd64 + echo 'Loading $demo_volume_label $demo_type initial ramdisk ...' + initrd /$image_dir/boot/initrd.img-3.16.0-4-amd64 } EOF -# Add menu entries for ONIE -- use the grub fragment provided by the -# ONIE distribution. -$onie_root_dir/grub.d/50_onie_grub >> $grub_cfg +if [ "$install_env" != "sonic" ]; then + # Add menu entries for ONIE -- use the grub fragment provided by the + # ONIE distribution. + $onie_root_dir/grub.d/50_onie_grub >> $grub_cfg + mkdir -p $onie_initrd_tmp/$demo_mnt/grub +else +cat <> $grub_cfg +$old_sonic_menuentry +$onie_menuentry +EOF +fi -mkdir -p $onie_initrd_tmp/$demo_mnt/grub cp $grub_cfg $onie_initrd_tmp/$demo_mnt/grub/grub.cfg cd / -echo "Installed SONiC base image $demo_volume_revision_label successfully" +echo "Installed SONiC base image $demo_volume_label successfully" diff --git a/onie-mk-demo.sh b/onie-mk-demo.sh index 8997fa8c8317..91d6d1b3ceb2 100755 --- a/onie-mk-demo.sh +++ b/onie-mk-demo.sh @@ -12,7 +12,7 @@ installer_dir=$4 platform_conf=$5 output_file=$6 demo_type=$7 -git_revision=$8 +image_version=$8 onie_image_part_size=$9 shift 9 @@ -29,7 +29,7 @@ if [ ! -d $installer_dir/$arch ] || \ exit 1 fi -[ -n "$git_revision" ] || { +[ -n "$image_version" ] || { echo "Error: Invalid git revisions" exit 1 } @@ -85,7 +85,7 @@ EXTRA_CMDLINE_LINUX=`echo $EXTRA_CMDLINE_LINUX | sed -e 's/[\/&]/\\\&/g'` # Tailor the demo installer for OS mode or DIAG mode sed -i -e "s/%%DEMO_TYPE%%/$demo_type/g" \ - -e "s/%%GIT_REVISION%%/$git_revision/g" \ + -e "s/%%IMAGE_VERSION%%/$image_version/g" \ -e "s/%%ONIE_IMAGE_PART_SIZE%%/$onie_image_part_size/" \ -e "s/%%EXTRA_CMDLINE_LINUX%%/$EXTRA_CMDLINE_LINUX/" \ $tmp_installdir/install.sh || clean_up 1