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

Add a build mode to the installer to facilitate partition dump #846

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions build_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ 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

Copy link
Collaborator

Choose a reason for hiding this comment

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

in line 17, $IMAGE_TYPE = "onie" or $IMAGE_TYPE = "raw"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Introduced IMAGE_TYPE "raw".

## Generate a compressed 8GB partition dump that can be used to 'dd' in-lieu of using the onie-nos-installer
Copy link
Collaborator

Choose a reason for hiding this comment

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

if IMAGE_TYPE == "raw", then after we build the onie image, we need to install it in a raw device. Here, in the build_image.sh, we should use fallocate to create the disk file and in onie installer, we only do installation in the disk file, after that, we should do gzip here in the build_image.sh.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Note that the build of sonic-broadcom.raw will build the sonic-broadcom.bin and then use it to build the sonic-broadcom.raw.

## The 'build' install mode of the installer is used to generate this dump.
sudo chmod a+x $OUTPUT_ONIE_IMAGE
sudo ./$OUTPUT_ONIE_IMAGE

if [ -r /tmp/sonic-${TARGET_MACHINE}_8GB_dd.img.gz ]; then
sudo mv /tmp/sonic-${TARGET_MACHINE}_8GB_dd.img.gz target
else
echo "/tmp/sonic-${TARGET_MACHINE}_8GB_dd.img.gz not found !\n"
fi

## Use 'aboot' as target machine category which includes Aboot as bootloader
elif [ "$IMAGE_TYPE" = "aboot" ]; then
echo "Build Aboot installer"
Expand Down
22 changes: 20 additions & 2 deletions files/image_config/platform/rc.local
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,30 @@
#
# By default this script does nothing.

sonic_version=$(cat /etc/sonic/sonic_version.yml | grep build_version | cut -f2 -d" ")

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

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

Choose a reason for hiding this comment

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

mount $onie_dev /mnt/onie-boot [](start = 8, length = 30)

please umount /mnt/onie-boot after done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


if [ ! -e /mnt/onie-boot/onie/grub/grub-machine.cfg ]; then
echo "/mnt/onie-boot/onie/grub/grub-machine.cfg not found" >> /etc/migration.log
else
grep "=" /mnt/onie-boot/onie/grub/grub-machine.cfg > /host/machine.conf
fi
fi

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

. /host/machine.conf

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

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
Expand Down
89 changes: 68 additions & 21 deletions installer/x86_64/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
Expand All @@ -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)
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)
fi

[ -b "$blk_dev" ] || {
if [ "$install_env" != "build" ] && [ ! -b "$blk_dev" ]; then
echo "Error: Unable to determine block device of ONIE install"
exit 1
Copy link
Collaborator

Choose a reason for hiding this comment

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

move this into previous block?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

}
fi

# If running in ONIE
if [ "$install_env" = "onie" ]; then
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -406,6 +419,20 @@ else
rm -rf $f
fi
done
else
TARGET_MACHINE=`grep machine ./machine.conf | cut -d '=' -f 2`
demo_mnt="build_dd_image_mnt"

#remove older partition dump
rm -f /tmp/sonic-${TARGET_MACHINE}_8GB_dd.img.gz

echo "Creating sonic-${TARGET_MACHINE}_8GB_dd.img..."
fallocate -l 8G /tmp/sonic-${TARGET_MACHINE}_8GB_dd.img
mkfs.ext4 /tmp/sonic-${TARGET_MACHINE}_8GB_dd.img

echo "Mounting /tmp/sonic-${TARGET_MACHINE}_8GB_dd.img on $demo_mnt..."
mkdir $demo_mnt
mount -t auto -o loop /tmp/sonic-${TARGET_MACHINE}_8GB_dd.img $demo_mnt
fi

echo "Installing SONiC to $demo_mnt/$image_dir"
Expand All @@ -424,6 +451,12 @@ fi
# Decompress the file for the file system directly to the partition
unzip -o $ONIE_INSTALLER_PAYLOAD -x "$FILESYSTEM_DOCKERFS" -d $demo_mnt/$image_dir

# Indicate that this filesystem is being generated using the installer on the build server
# to facilitate migration from a 3rd party OS into SONiC
if [ "$install_env" = "build" ]; then
touch $demo_mnt/$image_dir/platform/migration
fi
Copy link
Collaborator

Choose a reason for hiding this comment

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

I prefer not to introduce this migration flag. In the rc.local, if it is the first time, check if there is /host/machine.conf or not first, if there is no /host/machine.conf, then mount onie and copy the file. We do not really need the migration flag here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed migration flag.


TAR_EXTRA_OPTION="--numeric-owner"
mkdir -p $demo_mnt/$image_dir/$DOCKERFS_DIR
unzip -op $ONIE_INSTALLER_PAYLOAD "$FILESYSTEM_DOCKERFS" | tar xz $TAR_EXTRA_OPTION -f - -C $demo_mnt/$image_dir/$DOCKERFS_DIR
Expand All @@ -446,7 +479,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

Expand All @@ -471,6 +504,14 @@ fi
grub_cfg=$(mktemp)
trap_push "rm $grub_cfg || true"

# These parameters will be initialized post migration
if [ "$install_env" = "build" ]; then
CONSOLE_PORT="CONSOLE_PORT"
CONSOLE_DEV="CONSOLE_DEV"
CONSOLE_SPEED="CONSOLE_SPEED"
demo_dev="ROOT_DEV"
fi

# Set a few GRUB_xxx environment variables that will be picked up and
# used by the 50_onie_grub script. This is similiar to what an OS
# would specify in /etc/default/grub.
Expand Down Expand Up @@ -547,7 +588,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
Expand All @@ -559,7 +600,13 @@ $onie_menuentry
EOF
fi

cp $grub_cfg $onie_initrd_tmp/$demo_mnt/grub/grub.cfg
if [ "$install_env" = "build" ]; then
cp $grub_cfg $demo_mnt/$image_dir/platform/grub.cfg.migration
Copy link
Collaborator

Choose a reason for hiding this comment

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

what is your plan for this grub.cfg.migration? I do not see it is used anywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed all changes pertaining to grub.cfg.migration since /host/machine.conf can be used instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The migration flag was meant to be used to install the grub for SONiC post migration. Since machine.conf can be used, it is now removed.

gzip /tmp/sonic-${TARGET_MACHINE}_8GB_dd.img
Copy link
Collaborator

Choose a reason for hiding this comment

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

do the gzip in the build_image.sh

umount $demo_mnt
else
cp $grub_cfg $onie_initrd_tmp/$demo_mnt/grub/grub.cfg
fi

cd /

Expand Down