From 444f60356455a1d1ef75b887ca2042dbab95f497 Mon Sep 17 00:00:00 2001 From: Andriy Moroz Date: Mon, 27 Mar 2017 12:00:02 +0300 Subject: [PATCH 1/8] SONiC-to-SONiC update --- build_debian.sh | 7 +- .../build_templates/sonic_debian_extension.j2 | 11 ++ files/image_config/platform/rc.local | 10 +- files/initramfs-tools/union-mount.j2 | 8 +- installer/x86_64/install.sh | 163 ++++++++++++------ slave.mk | 1 - 6 files changed, 133 insertions(+), 67 deletions(-) diff --git a/build_debian.sh b/build_debian.sh index 9840280fc849..882ff31fe496 100755 --- a/build_debian.sh +++ b/build_debian.sh @@ -126,6 +126,8 @@ sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/hooks/mke2fs ## Hook into initramfs: after partition mount and loop file mount ## 1. Prepare layered file system ## 2. Bind-mount docker working directory (docker aufs cannot work over aufs rootfs) +GIT_REVISION=$(git rev-parse --short HEAD) +sed -i -e "s/%%GIT_REVISION%%/$GIT_REVISION/g" files/initramfs-tools/union-mount sudo cp files/initramfs-tools/union-mount $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-bottom/union-mount sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-bottom/union-mount sudo cp files/initramfs-tools/union-fsck $FILESYSTEM_ROOT/etc/initramfs-tools/hooks/union-fsck @@ -195,7 +197,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 @@ -271,7 +274,7 @@ built_by: $USER@$BUILD_HOSTNAME EOF if [ -f sonic_debian_extension.sh ]; then - ./sonic_debian_extension.sh $FILESYSTEM_ROOT $PLATFORM_DIR + ./sonic_debian_extension.sh $FILESYSTEM_ROOT $PLATFORM_DIR $GIT_REVISION fi ## Clean up apt diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index 77fcd1f38655..b29d23b6590c 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -8,6 +8,10 @@ ## PARAMETERS: ## FILESYSTEM_ROOT ## Path to debian file system root directory +## PLATFORM_DIR +## Path to debian platform directory +## GIT_REVISION +## Current build git revision FILESYSTEM_ROOT=$1 [ -n "$FILESYSTEM_ROOT" ] || { @@ -21,6 +25,12 @@ PLATFORM_DIR=$2 exit 1 } +GIT_REVISION=$3 +[ -n "$GIT_REVISION" ] || { + echo "Error: no or empty GIT_REVISION argument" + exit 1 +} + ## Enable debug output for script set -x -e @@ -175,6 +185,7 @@ sudo rm -f $FILESYSTEM_ROOT/usr/sbin/policy-rc.d ## copy platform rc.local sudo cp $IMAGE_CONFIGS/platform/rc.local $FILESYSTEM_ROOT/etc/ +sudo sed -i -e "s/%%GIT_REVISION%%/$GIT_REVISION/g" $FILESYSTEM_ROOT/etc/rc.local {% if installer_images.strip() -%} {% for image in installer_images.strip().split(' ') -%} diff --git a/files/image_config/platform/rc.local b/files/image_config/platform/rc.local index eccba516e694..29b2782e9715 100755 --- a/files/image_config/platform/rc.local +++ b/files/image_config/platform/rc.local @@ -15,7 +15,7 @@ echo "install platform dependent packages at the first boot time" -if [ -f /host/platform/firsttime ]; then +if [ -f /host/image-%%GIT_REVISION%%/platform/firsttime ]; then if [ -n "$aboot_platform" ]; then platform=$aboot_platform @@ -23,17 +23,17 @@ if [ -f /host/platform/firsttime ]; then platform=$onie_platform else echo "Unknown sonic platform" - rm /host/platform/firsttime + rm /host/image-%%GIT_REVISION%%/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-%%GIT_REVISION%%/platform/$platform ]; then + dpkg -i /host/image-%%GIT_REVISION%%/platform/$platform/*.deb fi - rm /host/platform/firsttime + rm /host/image-%%GIT_REVISION%%/platform/firsttime fi exit 0 diff --git a/files/initramfs-tools/union-mount.j2 b/files/initramfs-tools/union-mount.j2 index 2ff58ec949f9..dc14bf1af18b 100644 --- a/files/initramfs-tools/union-mount.j2 +++ b/files/initramfs-tools/union-mount.j2 @@ -6,17 +6,17 @@ 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} +mkdir -p ${rootmnt}/host/image-%%GIT_REVISION%%/rw +mount -n -o dirs=${rootmnt}/host/image-%%GIT_REVISION%%/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-%%GIT_REVISION%%/{{ 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-%%GIT_REVISION%%/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 diff --git a/installer/x86_64/install.sh b/installer/x86_64/install.sh index 94c3fcc1c3a8..ecbf50ac7e42 100755 --- a/installer/x86_64/install.sh +++ b/installer/x86_64/install.sh @@ -5,9 +5,7 @@ # # SPDX-License-Identifier: GPL-2.0 -# Function definitions -# wc -l -line_count() { return $(echo $1 | wc -l); } +SONIC_IMAGE_DIR_PREFIX="image" # Appends a command to a trap, which is needed because default trap behavior is to replace # previous trap for the same signal @@ -55,7 +53,17 @@ ONIE_PLATFORM_EXTRA_CMDLINE_LINUX="" # Default var/log device size in MB VAR_LOG_SIZE=4096 -[ -r platforms/$onie_platform ] && source platforms/$onie_platform + +# simple detect whether script was run in SONiC +# TODO: think of some other marker +aufs_mnt=$(cat /proc/mounts | grep aufs || true) + +if [ -z "$aufs_mnt" ]; then + environment="onie" + [ -r platforms/$onie_platform ] && source platforms/$onie_platform +else + environment="sonic" +fi # Install demo on same block device as ONIE onie_dev=$(blkid | grep ONIE-BOOT | head -n 1 | awk '{print $1}' | sed -e 's/:.*$//') @@ -110,7 +118,7 @@ git_revision="%%GIT_REVISION%%" timestamp="$(date -u +%Y%m%d)" demo_volume_label="SONiC-${demo_type}" -demo_volume_revision_label="SONiC-${demo_type}-${git_revision}" +demo_volume_revision_label="SONiC-${demo_type}" # auto-detect whether BIOS or UEFI if [ -d "/sys/firmware/efi/efivars" ] ; then @@ -119,19 +127,22 @@ else firmware="bios" fi -# determine ONIE partition type -onie_partition_type=$(${onie_bin} onie-sysinfo -t) -# demo partition size in MB -demo_part_size="%%ONIE_IMAGE_PART_SIZE%%" -if [ "$firmware" = "uefi" ] ; then - create_demo_partition="create_demo_uefi_partition" -elif [ "$onie_partition_type" = "gpt" ] ; then - create_demo_partition="create_demo_gpt_partition" -elif [ "$onie_partition_type" = "msdos" ] ; then - create_demo_partition="create_demo_msdos_partition" -else - echo "ERROR: Unsupported partition type: $onie_partition_type" - exit 1 +if [ "$environment" != "sonic" ]; then + # determine ONIE partition type + onie_partition_type=$(${onie_bin} onie-sysinfo -t) + # demo partition size in MB + demo_part_size="%%ONIE_IMAGE_PART_SIZE%%" + if [ "$firmware" = "uefi" ] ; then + create_demo_partition="create_demo_uefi_partition" + elif [ "$onie_partition_type" = "gpt" ] ; then + create_demo_partition="create_demo_gpt_partition" + elif [ "$onie_partition_type" = "msdos" ] ; then + create_demo_partition="create_demo_msdos_partition" + else + echo "ERROR: Unsupported partition type: $onie_partition_type" + exit 1 + fi + echo "Part: $onie_partition_type" fi # Creates a new partition for the DEMO OS. @@ -381,49 +392,67 @@ demo_install_uefi_grub() } -eval $create_demo_partition $blk_dev -demo_dev=$(echo $blk_dev | sed -e 's/\(mmcblk[0-9]\)/\1p/')$demo_part +if [ "$environment" != "sonic" ]; then + eval $create_demo_partition $blk_dev + demo_dev=$(echo $blk_dev | sed -e 's/\(mmcblk[0-9]\)/\1p/')$demo_part -# Make filesystem -mkfs.ext4 -L $demo_volume_label $demo_dev + # Make filesystem + mkfs.ext4 -L $demo_volume_revision_label $demo_dev -# Mount demo filesystem -demo_mnt=$(${onie_bin} mktemp -d) || { - echo "Error: Unable to create file system mount point" - exit 1 -} -trap_push "${onie_bin} fuser -km $demo_mnt || ${onie_bin} umount $demo_mnt || ${onie_bin} rmdir $demo_mnt || true" -${onie_bin} mount -t ext4 -o defaults,rw $demo_dev $demo_mnt || { - echo "Error: Unable to mount $demo_dev on $demo_mnt" + # Mount demo filesystem + demo_mnt=$(${onie_bin} mktemp -d) || { + echo "Error: Unable to create file system mount point" + exit 1 + } + trap_push "${onie_bin} fuser -km $demo_mnt || ${onie_bin} umount $demo_mnt || ${onie_bin} rmdir $demo_mnt || true" + ${onie_bin} mount -t ext4 -o defaults,rw $demo_dev $demo_mnt || { + echo "Error: Unable to mount $demo_dev on $demo_mnt" + exit 1 + } +else + demo_mnt="/host" +fi + +sonic_dir="$SONIC_IMAGE_DIR_PREFIX-$git_revision" + +echo "Installing SONiC to $demo_mnt/$sonic_dir" +mkdir $demo_mnt/$sonic_dir || { + echo "Error: Unable to create sonic directory" exit 1 } # Decompress the file for the file system directly to the partition -unzip $ONIE_INSTALLER_PAYLOAD -d $demo_mnt +unzip $ONIE_INSTALLER_PAYLOAD -d $demo_mnt/$sonic_dir -if [ -f $demo_mnt/$FILESYSTEM_DOCKERFS ]; then - cd $demo_mnt && mkdir -p $DOCKERFS_DIR && tar xf $FILESYSTEM_DOCKERFS -C $DOCKERFS_DIR && rm -f $FILESYSTEM_DOCKERFS; cd $OLDPWD +if [ -f $demo_mnt/$sonic_dir/$FILESYSTEM_DOCKERFS ]; then + cd $demo_mnt/$sonic_dir && mkdir -p $DOCKERFS_DIR && tar xf $FILESYSTEM_DOCKERFS -C $DOCKERFS_DIR && rm -f $FILESYSTEM_DOCKERFS; cd $OLDPWD fi # Create loop device for /var/log to limit its size to $VAR_LOG_SIZE MB -if [ "$VAR_LOG_SIZE" != "0" ]; then - mkdir -p $demo_mnt/disk-img - dd if=/dev/zero of=$demo_mnt/disk-img/var-log.ext4 count=$((2048*$VAR_LOG_SIZE)) - mkfs.ext4 -q $demo_mnt/disk-img/var-log.ext4 -F +if [ ! -f $demo_mnt/disk-img/var-log.ext4 ]; then + if [ "$VAR_LOG_SIZE" != "0" ]; then + mkdir -p $demo_mnt/disk-img + dd if=/dev/zero of=$demo_mnt/disk-img/var-log.ext4 count=$((2048*$VAR_LOG_SIZE)) + mkfs.ext4 -q $demo_mnt/disk-img/var-log.ext4 -F + fi +else + echo "Log file system already exists. Skipping..." fi -# Store machine description in target file system -cp /etc/machine.conf $demo_mnt +if [ "$environment" != "sonic" ]; then + # Store machine description in target file system + cp /etc/machine.conf $demo_mnt -# Store installation log in target file system -rm -f $onie_initrd_tmp/tmp/onie-support.tar.bz2 -${onie_bin} onie-support /tmp -mv $onie_initrd_tmp/tmp/onie-support.tar.bz2 $demo_mnt + # Store installation log in target file system + rm -f $onie_initrd_tmp/tmp/onie-support.tar.bz2 + ${onie_bin} onie-support /tmp + mv $onie_initrd_tmp/tmp/onie-support.tar.bz2 $demo_mnt/$sonic_dir/ -if [ "$firmware" = "uefi" ] ; then - demo_install_uefi_grub "$demo_mnt" "$blk_dev" -else - demo_install_grub "$demo_mnt" "$blk_dev" + if [ "$firmware" = "uefi" ] ; then + demo_install_uefi_grub "$demo_mnt" "$blk_dev" + else + demo_install_grub "$demo_mnt" "$blk_dev" + fi fi # Create a minimal grub.cfg that allows for: @@ -485,7 +514,14 @@ fi # Add a menu entry for the DEMO OS # Note: assume that apparmor is supported in the kernel -demo_grub_entry="$demo_volume_revision_label" +demo_grub_entry="$demo_volume_revision_label-${git_revision}" +if [ "$environment" = "sonic" ]; then + running_sonic_revision=$(cat /etc/sonic/sonic_version.yml | grep build_version | cut -f2 -d" ") + old_grub_menuentry=$(cat /host/grub/grub.cfg | sed "/$running_sonic_revision/,/}/!d") + demo_dev=$(echo $old_grub_menuentry | sed -e "s/.*root\=\(.*\)rw.*/\1/") + grub_menuentry=$(cat /host/grub/grub.cfg | sed "/menuentry ONIE/,/}/!d") +fi + cat <> $grub_cfg menuentry '$demo_grub_entry' { search --no-floppy --label --set=root $demo_volume_label @@ -494,21 +530,38 @@ menuentry '$demo_grub_entry' { 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 /$sonic_dir/boot/vmlinuz-3.16.0-4-amd64 root=$demo_dev rw $GRUB_CMDLINE_LINUX \ + loop=$sonic_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 + initrd /$sonic_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 [ "$environment" != "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_grub_menuentry +$grub_menuentry +EOF +fi -mkdir -p $onie_initrd_tmp/$demo_mnt/grub cp $grub_cfg $onie_initrd_tmp/$demo_mnt/grub/grub.cfg +# Remove extra SONiC image if any +if [ "$environment" = "sonic" ]; then + for f in /$demo_mnt/$SONIC_IMAGE_DIR_PREFIX* ; do + if [ -d $f ] && [ "$f" != "/$demo_mnt/$SONIC_IMAGE_DIR_PREFIX-$running_sonic_revision" ] && [ "$f" != "/$demo_mnt/$sonic_dir" ]; then + echo "Removing old SONiC installation $f" + rm -rf $f + fi + done +fi + cd / echo "Installed SONiC base image $demo_volume_revision_label successfully" diff --git a/slave.mk b/slave.mk index fbfa9f28fa35..3bfefad663de 100644 --- a/slave.mk +++ b/slave.mk @@ -341,7 +341,6 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : .platform export installer_start_scripts="$(foreach docker, $($*_DOCKERS),$(addsuffix .sh, $($(docker)_CONTAINER_NAME)))" export installer_services="$(foreach docker, $($*_DOCKERS),$(addsuffix .service, $($(docker)_CONTAINER_NAME)))" export installer_extra_files="$(foreach docker, $($*_DOCKERS), $(foreach file, $($(docker)_BASE_IMAGE_FILES), $($(docker)_PATH)/base_image_files/$(file)))" - j2 -f env files/initramfs-tools/union-mount.j2 onie-image.conf > files/initramfs-tools/union-mount j2 -f env files/initramfs-tools/arista-convertfs.j2 onie-image.conf > files/initramfs-tools/arista-convertfs From 48c0816c1360535fb465de9f6a4e4781ed3eff56 Mon Sep 17 00:00:00 2001 From: Andriy Moroz Date: Mon, 3 Apr 2017 16:55:54 +0300 Subject: [PATCH 2/8] Fixed PR comments --- installer/x86_64/install.sh | 40 ++++++++++++++++++++----------------- slave.mk | 1 + 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/installer/x86_64/install.sh b/installer/x86_64/install.sh index ecbf50ac7e42..9e26513ff296 100755 --- a/installer/x86_64/install.sh +++ b/installer/x86_64/install.sh @@ -53,16 +53,13 @@ ONIE_PLATFORM_EXTRA_CMDLINE_LINUX="" # Default var/log device size in MB VAR_LOG_SIZE=4096 - -# simple detect whether script was run in SONiC -# TODO: think of some other marker -aufs_mnt=$(cat /proc/mounts | grep aufs || true) - -if [ -z "$aufs_mnt" ]; then +if [ -d "/etc/sonic" ]; then + echo "Running in SONiC" + environment="sonic" +else + echo "Running NOT in SONiC" environment="onie" [ -r platforms/$onie_platform ] && source platforms/$onie_platform -else - environment="sonic" fi # Install demo on same block device as ONIE @@ -118,7 +115,7 @@ git_revision="%%GIT_REVISION%%" timestamp="$(date -u +%Y%m%d)" demo_volume_label="SONiC-${demo_type}" -demo_volume_revision_label="SONiC-${demo_type}" +demo_volume_revision_label="SONiC-${demo_type}-${git_revision}" # auto-detect whether BIOS or UEFI if [ -d "/sys/firmware/efi/efivars" ] ; then @@ -397,7 +394,7 @@ if [ "$environment" != "sonic" ]; then demo_dev=$(echo $blk_dev | sed -e 's/\(mmcblk[0-9]\)/\1p/')$demo_part # Make filesystem - mkfs.ext4 -L $demo_volume_revision_label $demo_dev + mkfs.ext4 -L $demo_volume_label $demo_dev # Mount demo filesystem demo_mnt=$(${onie_bin} mktemp -d) || { @@ -416,10 +413,17 @@ fi sonic_dir="$SONIC_IMAGE_DIR_PREFIX-$git_revision" echo "Installing SONiC to $demo_mnt/$sonic_dir" -mkdir $demo_mnt/$sonic_dir || { - echo "Error: Unable to create sonic directory" - exit 1 -} + +# Create target directory or clean it up if exists +if [ -d $demo_mnt/$sonic_dir ]; then + echo "Directory $demo_mnt/$sonic_dir/ already exists. Cleaning up..." + rm -rf $demo_mnt/$sonic_dir/* +else + mkdir $demo_mnt/$sonic_dir || { + echo "Error: Unable to create sonic directory" + exit 1 + } +fi # Decompress the file for the file system directly to the partition unzip $ONIE_INSTALLER_PAYLOAD -d $demo_mnt/$sonic_dir @@ -514,7 +518,7 @@ fi # Add a menu entry for the DEMO OS # Note: assume that apparmor is supported in the kernel -demo_grub_entry="$demo_volume_revision_label-${git_revision}" +demo_grub_entry="$demo_volume_revision_label" if [ "$environment" = "sonic" ]; then running_sonic_revision=$(cat /etc/sonic/sonic_version.yml | grep build_version | cut -f2 -d" ") old_grub_menuentry=$(cat /host/grub/grub.cfg | sed "/$running_sonic_revision/,/}/!d") @@ -525,7 +529,7 @@ fi cat <> $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 @@ -533,7 +537,7 @@ menuentry '$demo_grub_entry' { linux /$sonic_dir/boot/vmlinuz-3.16.0-4-amd64 root=$demo_dev rw $GRUB_CMDLINE_LINUX \ loop=$sonic_dir/$FILESYSTEM_SQUASHFS loopfstype=squashfs \ apparmor=1 security=apparmor $ONIE_PLATFORM_EXTRA_CMDLINE_LINUX - echo 'Loading $demo_volume_revision_label $demo_type initial ramdisk ...' + echo 'Loading $demo_volume_label $demo_type initial ramdisk ...' initrd /$sonic_dir/boot/initrd.img-3.16.0-4-amd64 } EOF @@ -564,4 +568,4 @@ fi cd / -echo "Installed SONiC base image $demo_volume_revision_label successfully" +echo "Installed SONiC base image $demo_volume_label successfully" diff --git a/slave.mk b/slave.mk index 3bfefad663de..fbfa9f28fa35 100644 --- a/slave.mk +++ b/slave.mk @@ -341,6 +341,7 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : .platform export installer_start_scripts="$(foreach docker, $($*_DOCKERS),$(addsuffix .sh, $($(docker)_CONTAINER_NAME)))" export installer_services="$(foreach docker, $($*_DOCKERS),$(addsuffix .service, $($(docker)_CONTAINER_NAME)))" export installer_extra_files="$(foreach docker, $($*_DOCKERS), $(foreach file, $($(docker)_BASE_IMAGE_FILES), $($(docker)_PATH)/base_image_files/$(file)))" + j2 -f env files/initramfs-tools/union-mount.j2 onie-image.conf > files/initramfs-tools/union-mount j2 -f env files/initramfs-tools/arista-convertfs.j2 onie-image.conf > files/initramfs-tools/arista-convertfs From abca80b33786fa1ec3a11db5ce7f20902e766d10 Mon Sep 17 00:00:00 2001 From: Andriy Moroz Date: Tue, 4 Apr 2017 14:17:53 +0300 Subject: [PATCH 3/8] Fixed PR comments 2 --- installer/x86_64/install.sh | 98 +++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 47 deletions(-) diff --git a/installer/x86_64/install.sh b/installer/x86_64/install.sh index 9e26513ff296..b048eb1a375d 100755 --- a/installer/x86_64/install.sh +++ b/installer/x86_64/install.sh @@ -54,11 +54,11 @@ ONIE_PLATFORM_EXTRA_CMDLINE_LINUX="" VAR_LOG_SIZE=4096 if [ -d "/etc/sonic" ]; then - echo "Running in SONiC" - environment="sonic" + echo "Installing SONiC in SONiC" + install_env="sonic" else - echo "Running NOT in SONiC" - environment="onie" + echo "Installing SONiC in ONIE" + install_env="onie" [ -r platforms/$onie_platform ] && source platforms/$onie_platform fi @@ -124,7 +124,7 @@ else firmware="bios" fi -if [ "$environment" != "sonic" ]; then +if [ "$install_env" != "sonic" ]; then # determine ONIE partition type onie_partition_type=$(${onie_bin} onie-sysinfo -t) # demo partition size in MB @@ -389,7 +389,9 @@ demo_install_uefi_grub() } -if [ "$environment" != "sonic" ]; then +image_dir="$SONIC_IMAGE_DIR_PREFIX-$git_revision" + +if [ "$install_env" != "sonic" ]; then eval $create_demo_partition $blk_dev demo_dev=$(echo $blk_dev | sed -e 's/\(mmcblk[0-9]\)/\1p/')$demo_part @@ -408,49 +410,62 @@ if [ "$environment" != "sonic" ]; then } else demo_mnt="/host" + running_sonic_revision=$(cat /etc/sonic/sonic_version.yml | grep build_version | cut -f2 -d" ") + # Remove extra SONiC image if any + for f in /$demo_mnt/$SONIC_IMAGE_DIR_PREFIX* ; do + if [ -d $f ] && [ "$f" != "/$demo_mnt/$SONIC_IMAGE_DIR_PREFIX-$running_sonic_revision" ] && [ "$f" != "/$demo_mnt/$image_dir" ]; then + echo "Removing old SONiC installation $f" + rm -rf $f + fi + done fi -sonic_dir="$SONIC_IMAGE_DIR_PREFIX-$git_revision" - -echo "Installing SONiC to $demo_mnt/$sonic_dir" +echo "Installing SONiC to $demo_mnt/$image_dir" # Create target directory or clean it up if exists -if [ -d $demo_mnt/$sonic_dir ]; then - echo "Directory $demo_mnt/$sonic_dir/ already exists. Cleaning up..." - rm -rf $demo_mnt/$sonic_dir/* +if [ -d $demo_mnt/$image_dir ]; then + echo "Directory $demo_mnt/$image_dir/ already exists. Cleaning up..." + rm -rf $demo_mnt/$image_dir/* else - mkdir $demo_mnt/$sonic_dir || { - echo "Error: Unable to create sonic directory" + mkdir $demo_mnt/$image_dir || { + echo "Error: Unable to create SONiC directory" exit 1 } fi # Decompress the file for the file system directly to the partition -unzip $ONIE_INSTALLER_PAYLOAD -d $demo_mnt/$sonic_dir +unzip $ONIE_INSTALLER_PAYLOAD -d $demo_mnt/$image_dir -if [ -f $demo_mnt/$sonic_dir/$FILESYSTEM_DOCKERFS ]; then - cd $demo_mnt/$sonic_dir && mkdir -p $DOCKERFS_DIR && tar xf $FILESYSTEM_DOCKERFS -C $DOCKERFS_DIR && rm -f $FILESYSTEM_DOCKERFS; cd $OLDPWD +if [ -f $demo_mnt/$image_dir/$FILESYSTEM_DOCKERFS ]; then + cd $demo_mnt/$image_dir && mkdir -p $DOCKERFS_DIR && tar xf $FILESYSTEM_DOCKERFS -C $DOCKERFS_DIR && rm -f $FILESYSTEM_DOCKERFS; cd $OLDPWD fi # Create loop device for /var/log to limit its size to $VAR_LOG_SIZE MB -if [ ! -f $demo_mnt/disk-img/var-log.ext4 ]; then - if [ "$VAR_LOG_SIZE" != "0" ]; then - mkdir -p $demo_mnt/disk-img - dd if=/dev/zero of=$demo_mnt/disk-img/var-log.ext4 count=$((2048*$VAR_LOG_SIZE)) - mkfs.ext4 -q $demo_mnt/disk-img/var-log.ext4 -F +if [ -f $demo_mnt/disk-img/var-log.ext4 ]; then + current_log_size_mb=$(ls -l --block-size=M $demo_mnt/disk-img/var-log.ext4 | cut -f5 -d" ") + if [ "$current_log_size_mb" = "$VAR_LOG_SIZE"M ]; then + echo "Log file system already exists. Size: ${VAR_LOG_SIZE}MB" + VAR_LOG_SIZE=0 + else + rm -rf $demo_mnt/disk-img fi -else - echo "Log file system already exists. Skipping..." fi -if [ "$environment" != "sonic" ]; then +if [ "$VAR_LOG_SIZE" != "0" ]; then + echo "Creating new log file system. Size: ${VAR_LOG_SIZE}MB" + mkdir -p $demo_mnt/disk-img + dd if=/dev/zero of=$demo_mnt/disk-img/var-log.ext4 count=$((2048*$VAR_LOG_SIZE)) + mkfs.ext4 -q $demo_mnt/disk-img/var-log.ext4 -F +fi + +if [ "$install_env" != "sonic" ]; then # Store machine description in target file system cp /etc/machine.conf $demo_mnt # Store installation log in target file system rm -f $onie_initrd_tmp/tmp/onie-support.tar.bz2 ${onie_bin} onie-support /tmp - mv $onie_initrd_tmp/tmp/onie-support.tar.bz2 $demo_mnt/$sonic_dir/ + mv $onie_initrd_tmp/tmp/onie-support.tar.bz2 $demo_mnt/$image_dir/ if [ "$firmware" = "uefi" ] ; then demo_install_uefi_grub "$demo_mnt" "$blk_dev" @@ -519,11 +534,10 @@ fi # Add a menu entry for the DEMO OS # Note: assume that apparmor is supported in the kernel demo_grub_entry="$demo_volume_revision_label" -if [ "$environment" = "sonic" ]; then - running_sonic_revision=$(cat /etc/sonic/sonic_version.yml | grep build_version | cut -f2 -d" ") - old_grub_menuentry=$(cat /host/grub/grub.cfg | sed "/$running_sonic_revision/,/}/!d") - demo_dev=$(echo $old_grub_menuentry | sed -e "s/.*root\=\(.*\)rw.*/\1/") - grub_menuentry=$(cat /host/grub/grub.cfg | sed "/menuentry ONIE/,/}/!d") +if [ "$install_env" = "sonic" ]; then + old_sonic_menuentry=$(cat /host/grub/grub.cfg | sed "/$running_sonic_revision/,/}/!d") + demo_dev=$(echo $old_sonic_menuentry | sed -e "s/.*root\=\(.*\)rw.*/\1/") + onie_menuentry=$(cat /host/grub/grub.cfg | sed "/menuentry ONIE/,/}/!d") fi cat <> $grub_cfg @@ -534,38 +548,28 @@ menuentry '$demo_grub_entry' { if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi insmod part_msdos insmod ext2 - linux /$sonic_dir/boot/vmlinuz-3.16.0-4-amd64 root=$demo_dev rw $GRUB_CMDLINE_LINUX \ - loop=$sonic_dir/$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_label $demo_type initial ramdisk ...' - initrd /$sonic_dir/boot/initrd.img-3.16.0-4-amd64 + initrd /$image_dir/boot/initrd.img-3.16.0-4-amd64 } EOF -if [ "$environment" != "sonic" ]; then +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_grub_menuentry -$grub_menuentry +$old_sonic_menuentry +$onie_menuentry EOF fi cp $grub_cfg $onie_initrd_tmp/$demo_mnt/grub/grub.cfg -# Remove extra SONiC image if any -if [ "$environment" = "sonic" ]; then - for f in /$demo_mnt/$SONIC_IMAGE_DIR_PREFIX* ; do - if [ -d $f ] && [ "$f" != "/$demo_mnt/$SONIC_IMAGE_DIR_PREFIX-$running_sonic_revision" ] && [ "$f" != "/$demo_mnt/$sonic_dir" ]; then - echo "Removing old SONiC installation $f" - rm -rf $f - fi - done -fi - cd / echo "Installed SONiC base image $demo_volume_label successfully" From 057c414e032339bf02dc4b2806c3b070f46babe4 Mon Sep 17 00:00:00 2001 From: Andriy Moroz Date: Tue, 4 Apr 2017 17:10:38 +0300 Subject: [PATCH 4/8] Updated path for arista aboot image --- build_debian.sh | 4 +++- build_image.sh | 1 + files/Aboot/boot0.j2 | 24 +++++++++++------------ files/initramfs-tools/arista-convertfs.j2 | 2 +- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/build_debian.sh b/build_debian.sh index 882ff31fe496..a549718870bf 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 +GIT_REVISION=$(git rev-parse --short HEAD) + ## 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/%%GIT_REVISION%%/$GIT_REVISION/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 @@ -126,7 +129,6 @@ sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/hooks/mke2fs ## Hook into initramfs: after partition mount and loop file mount ## 1. Prepare layered file system ## 2. Bind-mount docker working directory (docker aufs cannot work over aufs rootfs) -GIT_REVISION=$(git rev-parse --short HEAD) sed -i -e "s/%%GIT_REVISION%%/$GIT_REVISION/g" files/initramfs-tools/union-mount sudo cp files/initramfs-tools/union-mount $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-bottom/union-mount sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-bottom/union-mount diff --git a/build_image.sh b/build_image.sh index 7ac3085463dd..292171951d17 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/%%GIT_REVISION%%/$GIT_REVISION/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..6e0bfe61f836 100644 --- a/files/Aboot/boot0.j2 +++ b/files/Aboot/boot0.j2 @@ -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-%%GIT_REVISION%%); do if [ $f != "${swipath##*/}" ] && [ $f != "boot-config" ]; then - rm -rf "$target_path/$f" + rm -rf "$target_path/image-%%GIT_REVISION%%/$f" fi done ## Unzip the image - unzip -oq "$swipath" -x boot0 -d "$target_path" + unzip -oq "$swipath" -x boot0 -d "$target_path/image-%%GIT_REVISION%%" ## Remove installer swi as it has lots of redundunt contents rm -f $swipath @@ -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-%%GIT_REVISION%%/{{ DOCKERFS_DIR }}" ## extract docker archive - tar xf "$target_path/{{ FILESYSTEM_DOCKERFS }}" -C "$target_path/{{ DOCKERFS_DIR }}" + tar xf "$target_path/image-%%GIT_REVISION%%/{{ FILESYSTEM_DOCKERFS }}" -C "$target_path/image-%%GIT_REVISION%%/{{ DOCKERFS_DIR }}" ## clean up docker archive - rm -f "$target_path/{{ FILESYSTEM_DOCKERFS }}" + rm -f "$target_path/image-%%GIT_REVISION%%/{{ 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-%%GIT_REVISION%%/{{ ABOOT_BOOT_IMAGE }}" "$swipath" ## sync disk operations sync @@ -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-%%GIT_REVISION%%/$kernel_params" ]; then + cat "$target_path/image-%%GIT_REVISION%%/$kernel_params" >>/tmp/append fi # setting root partition if not overridden by kernel-params @@ -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-%%GIT_REVISION%%/.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-%%GIT_REVISION%%/$initrd" +kernel_path="$target_path/image-%%GIT_REVISION%%/$kernel" cmdline="$(tr '\n' ' ' Date: Wed, 12 Apr 2017 17:21:37 +0300 Subject: [PATCH 5/8] Adopted sonic version implementation --- build_debian.sh | 8 +++---- build_image.sh | 2 +- files/Aboot/boot0.j2 | 24 +++++++++---------- .../build_templates/sonic_debian_extension.j2 | 11 --------- files/image_config/platform/rc.local | 12 ++++++---- files/initramfs-tools/arista-convertfs.j2 | 2 +- files/initramfs-tools/union-mount.j2 | 8 +++---- installer/x86_64/install.sh | 17 ++++++------- onie-mk-demo.sh | 6 ++--- 9 files changed, 39 insertions(+), 51 deletions(-) diff --git a/build_debian.sh b/build_debian.sh index a549718870bf..ba5469a77cf4 100755 --- a/build_debian.sh +++ b/build_debian.sh @@ -116,11 +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 -GIT_REVISION=$(git rev-parse --short HEAD) +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/%%GIT_REVISION%%/$GIT_REVISION/g" files/initramfs-tools/arista-convertfs +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 @@ -129,7 +129,7 @@ sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/hooks/mke2fs ## Hook into initramfs: after partition mount and loop file mount ## 1. Prepare layered file system ## 2. Bind-mount docker working directory (docker aufs cannot work over aufs rootfs) -sed -i -e "s/%%GIT_REVISION%%/$GIT_REVISION/g" files/initramfs-tools/union-mount +sed -i -e "s/%%IMAGE_VERSION%%/$IMAGE_VERSION/g" files/initramfs-tools/union-mount sudo cp files/initramfs-tools/union-mount $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-bottom/union-mount sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-bottom/union-mount sudo cp files/initramfs-tools/union-fsck $FILESYSTEM_ROOT/etc/initramfs-tools/hooks/union-fsck @@ -276,7 +276,7 @@ built_by: $USER@$BUILD_HOSTNAME EOF if [ -f sonic_debian_extension.sh ]; then - ./sonic_debian_extension.sh $FILESYSTEM_ROOT $PLATFORM_DIR $GIT_REVISION + ./sonic_debian_extension.sh $FILESYSTEM_ROOT $PLATFORM_DIR fi ## Clean up apt diff --git a/build_image.sh b/build_image.sh index 292171951d17..a275c383c45d 100755 --- a/build_image.sh +++ b/build_image.sh @@ -45,7 +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/%%GIT_REVISION%%/$GIT_REVISION/g" 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 6e0bfe61f836..8b95dde9c651 100644 --- a/files/Aboot/boot0.j2 +++ b/files/Aboot/boot0.j2 @@ -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/image-%%GIT_REVISION%%); do + for f in $(ls -A $target_path/image-%%IMAGE_VERSION%%); do if [ $f != "${swipath##*/}" ] && [ $f != "boot-config" ]; then - rm -rf "$target_path/image-%%GIT_REVISION%%/$f" + rm -rf "$target_path/image-%%IMAGE_VERSION%%/$f" fi done ## Unzip the image - unzip -oq "$swipath" -x boot0 -d "$target_path/image-%%GIT_REVISION%%" + unzip -oq "$swipath" -x boot0 -d "$target_path/image-%%IMAGE_VERSION%%" ## Remove installer swi as it has lots of redundunt contents rm -f $swipath @@ -59,19 +59,19 @@ extract_image() { ## vfat does not support symbol link if [ $rootfs_type != "vfat" ]; then - mkdir -p "$target_path/image-%%GIT_REVISION%%/{{ DOCKERFS_DIR }}" + mkdir -p "$target_path/image-%%IMAGE_VERSION%%/{{ DOCKERFS_DIR }}" ## extract docker archive - tar xf "$target_path/image-%%GIT_REVISION%%/{{ FILESYSTEM_DOCKERFS }}" -C "$target_path/image-%%GIT_REVISION%%/{{ 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/image-%%GIT_REVISION%%/{{ 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/image-%%GIT_REVISION%%/{{ ABOOT_BOOT_IMAGE }}" "$swipath" + mv "$target_path/image-%%IMAGE_VERSION%%/{{ ABOOT_BOOT_IMAGE }}" "$swipath" ## sync disk operations sync @@ -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/image-%%GIT_REVISION%%/$kernel_params" ]; then - cat "$target_path/image-%%GIT_REVISION%%/$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 @@ -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/image-%%GIT_REVISION%%/.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/image-%%GIT_REVISION%%/$initrd" -kernel_path="$target_path/image-%%GIT_REVISION%%/$kernel" +initrd_path="$target_path/image-%%IMAGE_VERSION%%/$initrd" +kernel_path="$target_path/image-%%IMAGE_VERSION%%/$kernel" cmdline="$(tr '\n' ' ' Date: Thu, 13 Apr 2017 16:53:36 +0300 Subject: [PATCH 6/8] Some code refinements --- build_debian.sh | 1 - files/initramfs-tools/union-mount.j2 | 9 +++++---- installer/x86_64/install.sh | 5 +++++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/build_debian.sh b/build_debian.sh index ba5469a77cf4..7d763a46f2e5 100755 --- a/build_debian.sh +++ b/build_debian.sh @@ -129,7 +129,6 @@ sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/hooks/mke2fs ## Hook into initramfs: after partition mount and loop file mount ## 1. Prepare layered file system ## 2. Bind-mount docker working directory (docker aufs cannot work over aufs rootfs) -sed -i -e "s/%%IMAGE_VERSION%%/$IMAGE_VERSION/g" files/initramfs-tools/union-mount sudo cp files/initramfs-tools/union-mount $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-bottom/union-mount sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-bottom/union-mount sudo cp files/initramfs-tools/union-fsck $FILESYSTEM_ROOT/etc/initramfs-tools/hooks/union-fsck diff --git a/files/initramfs-tools/union-mount.j2 b/files/initramfs-tools/union-mount.j2 index 5dffd04cd25e..1a27d77b1720 100644 --- a/files/initramfs-tools/union-mount.j2 +++ b/files/initramfs-tools/union-mount.j2 @@ -6,17 +6,18 @@ case $1 in esac ## Mount the aufs file system: rw layer over squashfs -mkdir -p ${rootmnt}/host/image-%%IMAGE_VERSION%%/rw -mount -n -o dirs=${rootmnt}/host/image-%%IMAGE_VERSION%%/rw:${rootmnt}=ro -t aufs root-aufs ${rootmnt} +image_dir=$(cat /proc/cmdline | sed -e 's/BOOT_IMAGE=\/\(.*\)\/boot\(.*\)/\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/image-%%IMAGE_VERSION%%/{{ 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/image-%%IMAGE_VERSION%%/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 diff --git a/installer/x86_64/install.sh b/installer/x86_64/install.sh index f2198ef7d0f1..29d8e8348ba4 100755 --- a/installer/x86_64/install.sh +++ b/installer/x86_64/install.sh @@ -408,6 +408,11 @@ if [ "$install_env" != "sonic" ]; then else demo_mnt="/host" running_sonic_revision=$(cat /etc/sonic/sonic_version.yml | grep build_version | cut -f2 -d" ") + # Prevent installing existing SONiC if it is running + if [ "$image_dir" = "image-$running_sonic_revision" ]; then + echo "Error: Unable to install SONiC version $running_sonic_revision. Running SONiC has the same version" + exit 1 + fi # Remove extra SONiC images if any for f in $demo_mnt/image-* ; do if [ -d $f ] && [ "$f" != "$demo_mnt/image-$running_sonic_revision" ] && [ "$f" != "$demo_mnt/$image_dir" ]; then From cf97eae0e307c59e614d139af5ef3478629bf916 Mon Sep 17 00:00:00 2001 From: Andriy Moroz Date: Fri, 14 Apr 2017 10:44:53 +0300 Subject: [PATCH 7/8] Updated onie/not onie check (comment-293994504) --- installer/x86_64/install.sh | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/installer/x86_64/install.sh b/installer/x86_64/install.sh index 29d8e8348ba4..e08895524625 100755 --- a/installer/x86_64/install.sh +++ b/installer/x86_64/install.sh @@ -72,35 +72,13 @@ cur_part=$(cat /proc/mounts | awk "{ if(\$2==\"/\") print \$1 }" | grep $blk_dev } # If running in ONIE -if [ "$onie_dev" = "$cur_part" ] || [ -z "$cur_part" ]; then +if [ "$install_env" = "onie" ]; then # The onie bin tool prefix onie_bin= # The persistent ONIE directory location onie_root_dir=/mnt/onie-boot/onie # The onie file system root onie_initrd_tmp=/ -# Else running in normal Linux -else - # Mount ONIE-BOOT partition - onie_mnt=$(mktemp -d) || { - echo "Error: Unable to create file system mount point" - exit 1 - } - trap_push "fuser -km $onie_mnt || umount $onie_mnt || rmdir $onie_mnt || true" - mount $onie_dev $onie_mnt - onie_root_dir=$onie_mnt/onie - - # Mount initrd inside ONIE-BOOT partition - onie_initrd_tmp=$(mktemp -d) || { - echo "Error: Unable to create file system mount point" - exit 1 - } - trap_push "rm -rf $onie_initrd_tmp || true" - cd $onie_initrd_tmp - # Note: use wildcard in filename below to prevent hard-code version - cat $onie_mnt/onie/initrd.img-*-onie | unxz | cpio -id - cd - - onie_bin="chroot $onie_initrd_tmp" fi # The build system prepares this script by replacing %%DEMO-TYPE%% From faaf1067d5336ae2974e26f01803b2965d4a238d Mon Sep 17 00:00:00 2001 From: Guohan Lu Date: Thu, 20 Apr 2017 02:57:51 +0000 Subject: [PATCH 8/8] support multi-image installation on aboot --- files/Aboot/boot0.j2 | 34 +++++++++++++---------- files/initramfs-tools/arista-convertfs.j2 | 6 +++- files/initramfs-tools/union-mount.j2 | 2 +- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/files/Aboot/boot0.j2 b/files/Aboot/boot0.j2 index 8b95dde9c651..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 @@ -42,14 +43,16 @@ parse_environment_config() { extract_image() { ## Remove all the other unnecssary files except swi file, boot-config - for f in $(ls -A $target_path/image-%%IMAGE_VERSION%%); do + for f in $(ls -A $target_path); do if [ $f != "${swipath##*/}" ] && [ $f != "boot-config" ]; then - rm -rf "$target_path/image-%%IMAGE_VERSION%%/$f" + rm -rf "$target_path/$f" fi done + mkdir "$image_path" + ## Unzip the image - unzip -oq "$swipath" -x boot0 -d "$target_path/image-%%IMAGE_VERSION%%" + 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/image-%%IMAGE_VERSION%%/{{ DOCKERFS_DIR }}" + mkdir -p "$image_path/{{ DOCKERFS_DIR }}" ## extract docker archive - tar xf "$target_path/image-%%IMAGE_VERSION%%/{{ FILESYSTEM_DOCKERFS }}" -C "$target_path/image-%%IMAGE_VERSION%%/{{ DOCKERFS_DIR }}" + tar xf "$image_path/{{ FILESYSTEM_DOCKERFS }}" -C "$image_path/{{ DOCKERFS_DIR }}" ## clean up docker archive - rm -f "$target_path/image-%%IMAGE_VERSION%%/{{ 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/image-%%IMAGE_VERSION%%/{{ 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/image-%%IMAGE_VERSION%%/$kernel_params" ]; then - cat "$target_path/image-%%IMAGE_VERSION%%/$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/image-%%IMAGE_VERSION%%/.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/image-%%IMAGE_VERSION%%/$initrd" -kernel_path="$target_path/image-%%IMAGE_VERSION%%/$kernel" +initrd_path="$image_path/$initrd" +kernel_path="$image_path/$kernel" cmdline="$(tr '\n' ' '