diff --git a/build_image.sh b/build_image.sh index a275c383c45d..2d229c2d194b 100755 --- a/build_image.sh +++ b/build_image.sh @@ -14,11 +14,8 @@ IMAGE_VERSION=$(. functions.sh && sonic_get_version) -if [ "$IMAGE_TYPE" = "onie" ]; then - echo "Build ONIE installer" - mkdir -p `dirname $OUTPUT_ONIE_IMAGE` - sudo rm -f $OUTPUT_ONIE_IMAGE - +generate_onie_installer_image() +{ # Copy platform-specific ONIE installer config files where onie-mk-demo.sh expects them rm -rf ./installer/x86_64/platforms/ mkdir -p ./installer/x86_64/platforms/ @@ -27,6 +24,11 @@ if [ "$IMAGE_TYPE" = "onie" ]; then if [ -f ./device/$VENDOR/$PLATFORM/installer.conf ]; then cp ./device/$VENDOR/$PLATFORM/installer.conf ./installer/x86_64/platforms/$PLATFORM fi + + if [ "$IMAGE_TYPE" = "raw" ] && [ -f ./device/$VENDOR/$PLATFORM/nos_to_sonic_grub.cfg ]; then + sed -i -e "s/%%IMAGE_VERSION%%/$IMAGE_VERSION/g" ./device/$VENDOR/$PLATFORM/nos_to_sonic_grub.cfg + echo "IMAGE_VERSION is $IMAGE_VERSION" + fi done done @@ -35,6 +37,50 @@ if [ "$IMAGE_TYPE" = "onie" ]; then ./onie-mk-demo.sh $TARGET_PLATFORM $TARGET_MACHINE $TARGET_PLATFORM-$TARGET_MACHINE-$ONIEIMAGE_VERSION \ installer platform/$TARGET_MACHINE/platform.conf $OUTPUT_ONIE_IMAGE OS $IMAGE_VERSION $ONIE_IMAGE_PART_SIZE \ $ONIE_INSTALLER_PAYLOAD +} + +if [ "$IMAGE_TYPE" = "onie" ]; then + echo "Build ONIE installer" + mkdir -p `dirname $OUTPUT_ONIE_IMAGE` + sudo rm -f $OUTPUT_ONIE_IMAGE + + generate_onie_installer_image + +## Build a raw partition dump image using the ONIE installer that can be +## used to dd' in-lieu of using the onie-nos-installer. Used while migrating +## into SONiC from other NOS. +elif [ "$IMAGE_TYPE" = "raw" ]; then + + echo "Build RAW image" + mkdir -p `dirname $OUTPUT_RAW_IMAGE` + sudo rm -f $OUTPUT_RAW_IMAGE + + generate_onie_installer_image + + echo "Creating SONiC raw partition : $OUTPUT_RAW_IMAGE of size $RAW_IMAGE_DISK_SIZE MB" + fallocate -l "$RAW_IMAGE_DISK_SIZE"M $OUTPUT_RAW_IMAGE + + ## Generate a compressed 8GB partition dump that can be used to 'dd' in-lieu of using the onie-nos-installer + ## Run the installer + ## The 'build' install mode of the installer is used to generate this dump. + sudo chmod a+x $OUTPUT_ONIE_IMAGE + sudo ./$OUTPUT_ONIE_IMAGE + + [ -r $OUTPUT_RAW_IMAGE ] || { + echo "Error : $OUTPUT_RAW_IMAGE not generated!" + exit 1 + } + + gzip $OUTPUT_RAW_IMAGE + + [ -r $OUTPUT_RAW_IMAGE.gz ] || { + echo "Error : gzip $OUTPUT_RAW_IMAGE failed!" + exit 1 + } + + mv $OUTPUT_RAW_IMAGE.gz $OUTPUT_RAW_IMAGE + echo "The compressed raw image is in $OUTPUT_RAW_IMAGE" + ## Use 'aboot' as target machine category which includes Aboot as bootloader elif [ "$IMAGE_TYPE" = "aboot" ]; then echo "Build Aboot installer" diff --git a/device/dell/x86_64-dell_s6100_c2538-r0/nos_to_sonic_grub.cfg b/device/dell/x86_64-dell_s6100_c2538-r0/nos_to_sonic_grub.cfg new file mode 100644 index 000000000000..058b1a9ea118 --- /dev/null +++ b/device/dell/x86_64-dell_s6100_c2538-r0/nos_to_sonic_grub.cfg @@ -0,0 +1,44 @@ +# +# Grub config to launch SONiC +# with ONIE boot option + +insmod serial +# Initialize USB-Serial com2 port +serial --unit=1 --speed=9600 +#Serial port config;Defaults: COM1,9600 +serial --unit=0 --speed=9600 +terminal_output serial_com0 +terminal_input serial_com0 +#terminfo added to prevent text wrap issue. +terminfo -g 80x100 serial_com0 +terminfo -g 80x100 serial_com1 + +echo -n "Press Esc to stop autoboot ... " +if sleep --verbose --interruptible 5 ; then + insmod gzio + insmod part_msdos + insmod ext2 + set root='(hd0,gpt8)' + linux /image-%%IMAGE_VERSION%%/boot/vmlinuz-3.16.0-4-amd64 root=/dev/sda8 rw console=tty0 console=ttyS1,9600n8 loop=image-%%IMAGE_VERSION%%/fs.squashfs loopfstype=squashfs apparmor=1 security=apparmor + initrd /image-%%IMAGE_VERSION%%/boot/initrd.img-3.16.0-4-amd64 + boot +else + menuentry 'SONiC' { + insmod gzio + insmod part_msdos + insmod ext2 + set root='(hd0,gpt8)' + linux /image-%%IMAGE_VERSION%%/boot/vmlinuz-3.16.0-4-amd64 root=/dev/sda8 rw console=tty0 console=ttyS1,9600n8 loop=image-%%IMAGE_VERSION%%/fs.squashfs loopfstype=squashfs apparmor=1 security=apparmor + initrd /image-%%IMAGE_VERSION%%/boot/initrd.img-3.16.0-4-amd64 + boot + } + + menuentry 'ONIE' { + insmod force10 + onieboot + } + + menuentry 'DELL-DIAG' { + delldiagboot + } +fi diff --git a/device/dell/x86_64-dell_z9100_c2538-r0/nos_to_sonic_grub.cfg b/device/dell/x86_64-dell_z9100_c2538-r0/nos_to_sonic_grub.cfg new file mode 100644 index 000000000000..058b1a9ea118 --- /dev/null +++ b/device/dell/x86_64-dell_z9100_c2538-r0/nos_to_sonic_grub.cfg @@ -0,0 +1,44 @@ +# +# Grub config to launch SONiC +# with ONIE boot option + +insmod serial +# Initialize USB-Serial com2 port +serial --unit=1 --speed=9600 +#Serial port config;Defaults: COM1,9600 +serial --unit=0 --speed=9600 +terminal_output serial_com0 +terminal_input serial_com0 +#terminfo added to prevent text wrap issue. +terminfo -g 80x100 serial_com0 +terminfo -g 80x100 serial_com1 + +echo -n "Press Esc to stop autoboot ... " +if sleep --verbose --interruptible 5 ; then + insmod gzio + insmod part_msdos + insmod ext2 + set root='(hd0,gpt8)' + linux /image-%%IMAGE_VERSION%%/boot/vmlinuz-3.16.0-4-amd64 root=/dev/sda8 rw console=tty0 console=ttyS1,9600n8 loop=image-%%IMAGE_VERSION%%/fs.squashfs loopfstype=squashfs apparmor=1 security=apparmor + initrd /image-%%IMAGE_VERSION%%/boot/initrd.img-3.16.0-4-amd64 + boot +else + menuentry 'SONiC' { + insmod gzio + insmod part_msdos + insmod ext2 + set root='(hd0,gpt8)' + linux /image-%%IMAGE_VERSION%%/boot/vmlinuz-3.16.0-4-amd64 root=/dev/sda8 rw console=tty0 console=ttyS1,9600n8 loop=image-%%IMAGE_VERSION%%/fs.squashfs loopfstype=squashfs apparmor=1 security=apparmor + initrd /image-%%IMAGE_VERSION%%/boot/initrd.img-3.16.0-4-amd64 + boot + } + + menuentry 'ONIE' { + insmod force10 + onieboot + } + + menuentry 'DELL-DIAG' { + delldiagboot + } +fi diff --git a/files/image_config/platform/rc.local b/files/image_config/platform/rc.local index 49b2ed6e1b69..8b8db4a261c3 100755 --- a/files/image_config/platform/rc.local +++ b/files/image_config/platform/rc.local @@ -11,6 +11,27 @@ # # By default this script does nothing. +# If the machine.conf is absent, it indicates that the unit booted +# into SONiC from another NOS. Extract the machine.conf from ONIE. +if [ ! -e /host/machine.conf ]; then + onie_dev=$(blkid | grep ONIE-BOOT | head -n 1 | awk '{print $1}' | sed -e 's/:.*$//') + mkdir -p /mnt/onie-boot + mount $onie_dev /mnt/onie-boot + onie_grub_cfg=/mnt/onie-boot/onie/grub/grub-machine.cfg + + if [ ! -e $onie_grub_cfg ]; then + echo "$onie_grub_cfg not found" >> /etc/migration.log + else + . ./$onie_grub_cfg + grep = $onie_grub_cfg | sed -e 's/onie_//' -e 's/=.*$//' | while read var ; do + eval val='$'onie_$var + echo "onie_${var}=${val}" >> /host/machine.conf + done + fi + + umount /mnt/onie-boot +fi + . /host/machine.conf echo "install platform dependent packages at the first boot time" diff --git a/installer/sharch_body.sh b/installer/sharch_body.sh index 8260d0fd00e6..d22fe26b6998 100644 --- a/installer/sharch_body.sh +++ b/installer/sharch_body.sh @@ -27,6 +27,7 @@ echo " OK." # Untar and launch install script in a tmpfs cur_wd=$(pwd) +export cur_wd archive_path=$(realpath "$0") tmp_dir=$(mktemp -d) if [ "$(id -u)" = "0" ] ; then diff --git a/installer/x86_64/install.sh b/installer/x86_64/install.sh index ca8c4d3e47e7..ad1cc3691fbf 100755 --- a/installer/x86_64/install.sh +++ b/installer/x86_64/install.sh @@ -24,8 +24,25 @@ _trap_push true set -e cd $(dirname $0) +if [ -d "/etc/sonic" ]; then + echo "Installing SONiC in SONiC" + install_env="sonic" +elif grep -Fxqs "DISTRIB_ID=onie" /etc/lsb-release > /dev/null +then + echo "Installing SONiC in ONIE" + install_env="onie" +else + echo "Installing SONiC in BUILD" + install_env="build" +fi + +if [ -r ./machine.conf ]; then . ./machine.conf +fi + +if [ -r ./onie-image.conf ]; then . ./onie-image.conf +fi echo "ONIE Installer: platform: $platform" @@ -40,7 +57,7 @@ if [ -r /etc/machine.conf ]; then . /etc/machine.conf elif [ -r /host/machine.conf ]; then . /host/machine.conf -else +elif [ "$install_env" != "build" ]; then echo "cannot find machine.conf" exit 1 fi @@ -58,26 +75,20 @@ ONIE_PLATFORM_EXTRA_CMDLINE_LINUX="" # Default var/log device size in MB VAR_LOG_SIZE=4096 -if [ -d "/etc/sonic" ]; then - echo "Installing SONiC in SONiC" - install_env="sonic" -else - echo "Installing SONiC in ONIE" - install_env="onie" -fi - [ -r platforms/$onie_platform ] && . platforms/$onie_platform # Install demo on same block device as ONIE -onie_dev=$(blkid | grep ONIE-BOOT | head -n 1 | awk '{print $1}' | sed -e 's/:.*$//') -blk_dev=$(echo $onie_dev | sed -e 's/[1-9][0-9]*$//' | sed -e 's/\([0-9]\)\(p\)/\1/') -# Note: ONIE has no mount setting for / with device node, so below will be empty string -cur_part=$(cat /proc/mounts | awk "{ if(\$2==\"/\") print \$1 }" | grep $blk_dev || true) - -[ -b "$blk_dev" ] || { - echo "Error: Unable to determine block device of ONIE install" - exit 1 -} +if [ "$install_env" != "build" ]; then + onie_dev=$(blkid | grep ONIE-BOOT | head -n 1 | awk '{print $1}' | sed -e 's/:.*$//') + blk_dev=$(echo $onie_dev | sed -e 's/[1-9][0-9]*$//' | sed -e 's/\([0-9]\)\(p\)/\1/') + # Note: ONIE has no mount setting for / with device node, so below will be empty string + cur_part=$(cat /proc/mounts | awk "{ if(\$2==\"/\") print \$1 }" | grep $blk_dev || true) + + [ -b "$blk_dev" ] || { + echo "Error: Unable to determine block device of ONIE install" + exit 1 + } +fi # If running in ONIE if [ "$install_env" = "onie" ]; then @@ -108,7 +119,7 @@ else firmware="bios" fi -if [ "$install_env" != "sonic" ]; then +if [ "$install_env" = "onie" ]; then # determine ONIE partition type onie_partition_type=$(${onie_bin} onie-sysinfo -t) # demo partition size in MB @@ -310,6 +321,7 @@ demo_install_grub() cat $grub_install_log && rm -f $grub_install_log exit 1 } + rm -f $grub_install_log # restore immutable flag on the core.img file as discussed @@ -374,7 +386,7 @@ demo_install_uefi_grub() image_dir="image-$image_version" -if [ "$install_env" != "sonic" ]; then +if [ "$install_env" = "onie" ]; then eval $create_demo_partition $blk_dev demo_dev=$(echo $blk_dev | sed -e 's/\(mmcblk[0-9]\)/\1p/')$demo_part @@ -391,7 +403,8 @@ if [ "$install_env" != "sonic" ]; then echo "Error: Unable to mount $demo_dev on $demo_mnt" exit 1 } -else + +elif [ "$install_env" = "sonic" ]; then 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 @@ -406,6 +419,15 @@ else rm -rf $f fi done +else + demo_mnt="build_raw_image_mnt" + demo_dev=$cur_wd/"%%OUTPUT_RAW_IMAGE%%" + + mkfs.ext4 $demo_dev + + echo "Mounting $demo_dev on $demo_mnt..." + mkdir $demo_mnt + mount -t auto -o loop $demo_dev $demo_mnt fi echo "Installing SONiC to $demo_mnt/$image_dir" @@ -446,7 +468,7 @@ if [ "$VAR_LOG_SIZE" != "0" ]; then mkfs.ext4 -q $demo_mnt/disk-img/var-log.ext4 -F fi -if [ "$install_env" != "sonic" ]; then +if [ "$install_env" = "onie" ]; then # Store machine description in target file system cp /etc/machine.conf $demo_mnt @@ -547,7 +569,7 @@ menuentry '$demo_grub_entry' { } EOF -if [ "$install_env" != "sonic" ]; then +if [ "$install_env" = "onie" ]; 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 @@ -559,7 +581,11 @@ $onie_menuentry EOF fi -cp $grub_cfg $onie_initrd_tmp/$demo_mnt/grub/grub.cfg +if [ "$install_env" = "build" ]; then + umount $demo_mnt +else + cp $grub_cfg $onie_initrd_tmp/$demo_mnt/grub/grub.cfg +fi cd / diff --git a/onie-image.conf b/onie-image.conf index f12e23f7414b..b6564feb1a41 100644 --- a/onie-image.conf +++ b/onie-image.conf @@ -27,6 +27,12 @@ DOCKERFS_DIR=docker ## Output file name for onie installer OUTPUT_ONIE_IMAGE=target/sonic-$TARGET_MACHINE.bin +### Output file name for raw image +OUTPUT_RAW_IMAGE=target/sonic-$TARGET_MACHINE.raw + +### Raw image size in MB +RAW_IMAGE_DISK_SIZE=8192 + ## Output file name for aboot installer OUTPUT_ABOOT_IMAGE=target/sonic-aboot-$TARGET_MACHINE.swi diff --git a/onie-mk-demo.sh b/onie-mk-demo.sh index 91d6d1b3ceb2..b8418d79a678 100755 --- a/onie-mk-demo.sh +++ b/onie-mk-demo.sh @@ -83,11 +83,16 @@ cp onie-image.conf $tmp_installdir # sed. Special chars are: \ / & EXTRA_CMDLINE_LINUX=`echo $EXTRA_CMDLINE_LINUX | sed -e 's/[\/&]/\\\&/g'` +output_raw_image=$(cat onie-image.conf | grep OUTPUT_RAW_IMAGE | cut -f2 -d"=") +[ -z "$TARGET_MACHINE" ] && output_raw_image=$(echo $output_raw_image | sed -e 's/$TARGET_MACHINE/$machine/g') +output_raw_image=$(eval echo $output_raw_image) + # Tailor the demo installer for OS mode or DIAG mode sed -i -e "s/%%DEMO_TYPE%%/$demo_type/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/" \ + -e "s@%%OUTPUT_RAW_IMAGE%%@$output_raw_image@" \ $tmp_installdir/install.sh || clean_up 1 echo -n "." cp -r $* $tmp_installdir || clean_up 1 diff --git a/platform/broadcom/raw-image.mk b/platform/broadcom/raw-image.mk new file mode 100644 index 000000000000..ae93683c543d --- /dev/null +++ b/platform/broadcom/raw-image.mk @@ -0,0 +1,9 @@ +# sonic broadcom raw image installer + +SONIC_RAW_IMAGE = sonic-broadcom.raw +$(SONIC_RAW_IMAGE)_MACHINE = broadcom +$(SONIC_RAW_IMAGE)_IMAGE_TYPE = raw +$(SONIC_RAW_IMAGE)_DEPENDS += $(BRCM_OPENNSL_KERNEL) +$(SONIC_RAW_IMAGE)_INSTALLS += $($(SONIC_ONE_IMAGE)_INSTALLS) +$(SONIC_RAW_IMAGE)_DOCKERS += $(SONIC_INSTALL_DOCKER_IMAGES) +SONIC_INSTALLERS += $(SONIC_RAW_IMAGE) diff --git a/platform/broadcom/rules.mk b/platform/broadcom/rules.mk index 253593b30f2a..30b517f8d385 100755 --- a/platform/broadcom/rules.mk +++ b/platform/broadcom/rules.mk @@ -11,6 +11,7 @@ include $(PLATFORM_PATH)/docker-orchagent-brcm.mk include $(PLATFORM_PATH)/docker-syncd-brcm.mk include $(PLATFORM_PATH)/docker-syncd-brcm-rpc.mk include $(PLATFORM_PATH)/one-image.mk +include $(PLATFORM_PATH)/raw-image.mk include $(PLATFORM_PATH)/one-aboot.mk include $(PLATFORM_PATH)/libsaithrift-dev.mk include $(PLATFORM_PATH)/python-saithrift.mk