Skip to content

Commit db8c34a

Browse files
committed
Add a build mode to the installer to facilitate partition dump creation in build environment
1 parent 552b57d commit db8c34a

File tree

3 files changed

+102
-23
lines changed

3 files changed

+102
-23
lines changed

build_image.sh

+14
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,20 @@ if [ "$IMAGE_TYPE" = "onie" ]; then
3535
./onie-mk-demo.sh $TARGET_PLATFORM $TARGET_MACHINE $TARGET_PLATFORM-$TARGET_MACHINE-$ONIEIMAGE_VERSION \
3636
installer platform/$TARGET_MACHINE/platform.conf $OUTPUT_ONIE_IMAGE OS $IMAGE_VERSION $ONIE_IMAGE_PART_SIZE \
3737
$ONIE_INSTALLER_PAYLOAD
38+
39+
## Generate a compressed 8GB partition dump that can be used to 'dd' in-lieu of using the onie-nos-installer
40+
## The 'build' install mode of the installer is used to generate this dump.
41+
if [[ "$TARGET_MACHINE" == "broadcom" ]] && [[ -n "$DELL_Z9100_PLATFORM_MODULE_VERSION" || -n "$DELL_S6100_PLATFORM_MODULE_VERSION" ]]; then
42+
sudo chmod a+x $OUTPUT_ONIE_IMAGE
43+
sudo ./$OUTPUT_ONIE_IMAGE
44+
45+
if [ -r /tmp/sonic-${TARGET_MACHINE}_8GB_dd.img.gz ]; then
46+
sudo mv /tmp/sonic-${TARGET_MACHINE}_8GB_dd.img.gz target
47+
else
48+
echo "/tmp/sonic-${TARGET_MACHINE}_8GB_dd.img.gz not found !\n"
49+
fi
50+
fi
51+
3852
## Use 'aboot' as target machine category which includes Aboot as bootloader
3953
elif [ "$IMAGE_TYPE" = "aboot" ]; then
4054
echo "Build Aboot installer"

files/image_config/platform/rc.local

+20-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,30 @@
1111
#
1212
# By default this script does nothing.
1313

14+
sonic_version=$(cat /etc/sonic/sonic_version.yml | grep build_version | cut -f2 -d" ")
15+
16+
if [ -f /host/image-$sonic_version/platform/migration ]; then
17+
18+
# Extract the machine.conf from ONIE
19+
if [ ! -e /host/machine.conf ]; then
20+
onie_dev=$(blkid | grep ONIE-BOOT | head -n 1 | awk '{print $1}' | sed -e 's/:.*$//')
21+
mkdir -p /mnt/onie-boot
22+
mount $onie_dev /mnt/onie-boot
23+
24+
if [ ! -e /mnt/onie-boot/onie/grub/grub-machine.cfg ]; then
25+
echo "/mnt/onie-boot/onie/grub/grub-machine.cfg not found" >> /etc/migration.log
26+
else
27+
grep "=" /mnt/onie-boot/onie/grub/grub-machine.cfg > /host/machine.conf
28+
fi
29+
fi
30+
31+
rm /host/image-$sonic_version/platform/migration
32+
fi
33+
1434
. /host/machine.conf
1535

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

18-
sonic_version=$(cat /etc/sonic/sonic_version.yml | grep build_version | cut -f2 -d" ")
19-
2038
if [ -f /host/image-$sonic_version/platform/firsttime ]; then
2139

2240
if [ -n "$aboot_platform" ]; then

installer/x86_64/install.sh

+68-21
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,25 @@ _trap_push true
2424
set -e
2525
cd $(dirname $0)
2626

27+
if [ -d "/etc/sonic" ]; then
28+
echo "Installing SONiC in SONiC"
29+
install_env="sonic"
30+
elif grep -Fxqs "DISTRIB_ID=onie" /etc/lsb-release > /dev/null
31+
then
32+
echo "Installing SONiC in ONIE"
33+
install_env="onie"
34+
else
35+
echo "Installing SONiC in BUILD"
36+
install_env="build"
37+
fi
38+
39+
if [ -r ./machine.conf ]; then
2740
. ./machine.conf
41+
fi
42+
43+
if [ -r ./onie-image.conf ]; then
2844
. ./onie-image.conf
45+
fi
2946

3047
echo "ONIE Installer: platform: $platform"
3148

@@ -40,7 +57,7 @@ if [ -r /etc/machine.conf ]; then
4057
. /etc/machine.conf
4158
elif [ -r /host/machine.conf ]; then
4259
. /host/machine.conf
43-
else
60+
elif [ "$install_env" != "build" ]; then
4461
echo "cannot find machine.conf"
4562
exit 1
4663
fi
@@ -58,26 +75,20 @@ ONIE_PLATFORM_EXTRA_CMDLINE_LINUX=""
5875
# Default var/log device size in MB
5976
VAR_LOG_SIZE=4096
6077

61-
if [ -d "/etc/sonic" ]; then
62-
echo "Installing SONiC in SONiC"
63-
install_env="sonic"
64-
else
65-
echo "Installing SONiC in ONIE"
66-
install_env="onie"
67-
fi
68-
6978
[ -r platforms/$onie_platform ] && . platforms/$onie_platform
7079

7180
# Install demo on same block device as ONIE
72-
onie_dev=$(blkid | grep ONIE-BOOT | head -n 1 | awk '{print $1}' | sed -e 's/:.*$//')
73-
blk_dev=$(echo $onie_dev | sed -e 's/[1-9][0-9]*$//' | sed -e 's/\([0-9]\)\(p\)/\1/')
74-
# Note: ONIE has no mount setting for / with device node, so below will be empty string
75-
cur_part=$(cat /proc/mounts | awk "{ if(\$2==\"/\") print \$1 }" | grep $blk_dev || true)
81+
if [ "$install_env" != "build" ]; then
82+
onie_dev=$(blkid | grep ONIE-BOOT | head -n 1 | awk '{print $1}' | sed -e 's/:.*$//')
83+
blk_dev=$(echo $onie_dev | sed -e 's/[1-9][0-9]*$//' | sed -e 's/\([0-9]\)\(p\)/\1/')
84+
# Note: ONIE has no mount setting for / with device node, so below will be empty string
85+
cur_part=$(cat /proc/mounts | awk "{ if(\$2==\"/\") print \$1 }" | grep $blk_dev || true)
86+
fi
7687

77-
[ -b "$blk_dev" ] || {
88+
if [ "$install_env" != "build" ] && [ ! -b "$blk_dev" ]; then
7889
echo "Error: Unable to determine block device of ONIE install"
7990
exit 1
80-
}
91+
fi
8192

8293
# If running in ONIE
8394
if [ "$install_env" = "onie" ]; then
@@ -108,7 +119,7 @@ else
108119
firmware="bios"
109120
fi
110121

111-
if [ "$install_env" != "sonic" ]; then
122+
if [ "$install_env" = "onie" ]; then
112123
# determine ONIE partition type
113124
onie_partition_type=$(${onie_bin} onie-sysinfo -t)
114125
# demo partition size in MB
@@ -310,6 +321,7 @@ demo_install_grub()
310321
cat $grub_install_log && rm -f $grub_install_log
311322
exit 1
312323
}
324+
313325
rm -f $grub_install_log
314326
315327
# restore immutable flag on the core.img file as discussed
@@ -374,7 +386,7 @@ demo_install_uefi_grub()
374386
375387
image_dir="image-$image_version"
376388
377-
if [ "$install_env" != "sonic" ]; then
389+
if [ "$install_env" = "onie" ]; then
378390
eval $create_demo_partition $blk_dev
379391
demo_dev=$(echo $blk_dev | sed -e 's/\(mmcblk[0-9]\)/\1p/')$demo_part
380392
@@ -391,7 +403,8 @@ if [ "$install_env" != "sonic" ]; then
391403
echo "Error: Unable to mount $demo_dev on $demo_mnt"
392404
exit 1
393405
}
394-
else
406+
407+
elif [ "$install_env" = "sonic" ]; then
395408
demo_mnt="/host"
396409
running_sonic_revision=$(cat /etc/sonic/sonic_version.yml | grep build_version | cut -f2 -d" ")
397410
# Prevent installing existing SONiC if it is running
@@ -406,6 +419,20 @@ else
406419
rm -rf $f
407420
fi
408421
done
422+
else
423+
TARGET_MACHINE=`grep machine ./machine.conf | cut -d '=' -f 2`
424+
demo_mnt="build_dd_image_mnt"
425+
426+
#remove older partition dump
427+
rm -f /tmp/sonic-${TARGET_MACHINE}_8GB_dd.img.gz
428+
429+
echo "Creating sonic-${TARGET_MACHINE}_8GB_dd.img..."
430+
fallocate -l 8G /tmp/sonic-${TARGET_MACHINE}_8GB_dd.img
431+
mkfs.ext4 /tmp/sonic-${TARGET_MACHINE}_8GB_dd.img
432+
433+
echo "Mounting /tmp/sonic-${TARGET_MACHINE}_8GB_dd.img on $demo_mnt..."
434+
mkdir $demo_mnt
435+
mount -t auto -o loop /tmp/sonic-${TARGET_MACHINE}_8GB_dd.img $demo_mnt
409436
fi
410437
411438
echo "Installing SONiC to $demo_mnt/$image_dir"
@@ -424,6 +451,12 @@ fi
424451
# Decompress the file for the file system directly to the partition
425452
unzip -o $ONIE_INSTALLER_PAYLOAD -x "$FILESYSTEM_DOCKERFS" -d $demo_mnt/$image_dir
426453
454+
# Indicate that this filesystem is being generated using the installer on the build server
455+
# to facilitate migration from a 3rd party OS into SONiC
456+
if [ "$install_env" = "build" ]; then
457+
touch $demo_mnt/$image_dir/platform/migration
458+
fi
459+
427460
TAR_EXTRA_OPTION="--numeric-owner"
428461
mkdir -p $demo_mnt/$image_dir/$DOCKERFS_DIR
429462
unzip -op $ONIE_INSTALLER_PAYLOAD "$FILESYSTEM_DOCKERFS" | tar xz $TAR_EXTRA_OPTION -f - -C $demo_mnt/$image_dir/$DOCKERFS_DIR
@@ -446,7 +479,7 @@ if [ "$VAR_LOG_SIZE" != "0" ]; then
446479
mkfs.ext4 -q $demo_mnt/disk-img/var-log.ext4 -F
447480
fi
448481
449-
if [ "$install_env" != "sonic" ]; then
482+
if [ "$install_env" = "onie" ]; then
450483
# Store machine description in target file system
451484
cp /etc/machine.conf $demo_mnt
452485
@@ -471,6 +504,14 @@ fi
471504
grub_cfg=$(mktemp)
472505
trap_push "rm $grub_cfg || true"
473506
507+
# These parameters will be initialized post migration
508+
if [ "$install_env" = "build" ]; then
509+
CONSOLE_PORT="CONSOLE_PORT"
510+
CONSOLE_DEV="CONSOLE_DEV"
511+
CONSOLE_SPEED="CONSOLE_SPEED"
512+
demo_dev="ROOT_DEV"
513+
fi
514+
474515
# Set a few GRUB_xxx environment variables that will be picked up and
475516
# used by the 50_onie_grub script. This is similiar to what an OS
476517
# would specify in /etc/default/grub.
@@ -547,7 +588,7 @@ menuentry '$demo_grub_entry' {
547588
}
548589
EOF
549590
550-
if [ "$install_env" != "sonic" ]; then
591+
if [ "$install_env" = "onie" ]; then
551592
# Add menu entries for ONIE -- use the grub fragment provided by the
552593
# ONIE distribution.
553594
$onie_root_dir/grub.d/50_onie_grub >> $grub_cfg
@@ -559,7 +600,13 @@ $onie_menuentry
559600
EOF
560601
fi
561602
562-
cp $grub_cfg $onie_initrd_tmp/$demo_mnt/grub/grub.cfg
603+
if [ "$install_env" = "build" ]; then
604+
cp $grub_cfg $demo_mnt/$image_dir/platform/grub.cfg.migration
605+
gzip /tmp/sonic-${TARGET_MACHINE}_8GB_dd.img
606+
umount $demo_mnt
607+
else
608+
cp $grub_cfg $onie_initrd_tmp/$demo_mnt/grub/grub.cfg
609+
fi
563610
564611
cd /
565612

0 commit comments

Comments
 (0)