Skip to content

Commit

Permalink
[conf] append nos-config-part for s6100 (#5234)
Browse files Browse the repository at this point in the history
* [conf] append nos-config-part for s6100

* modify rc.local

Signed-off-by: Guohan Lu <[email protected]>

* Update rc.local

Co-authored-by: Blueve <[email protected]>
Co-authored-by: Guohan Lu <[email protected]>
Co-authored-by: Ying Xie <[email protected]>
  • Loading branch information
4 people authored and abdosi committed Sep 19, 2020
1 parent c0b47ad commit 64e04f8
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 57 deletions.
2 changes: 1 addition & 1 deletion device/dell/x86_64-dell_s6100_c2538-r0/installer.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
CONSOLE_PORT=0x2f8
CONSOLE_DEV=1
ONIE_PLATFORM_EXTRA_CMDLINE_LINUX="module_blacklist=gpio_ich"
ONIE_PLATFORM_EXTRA_CMDLINE_LINUX="module_blacklist=gpio_ich nos-config-part=/dev/sda12"
124 changes: 68 additions & 56 deletions files/image_config/platform/rc.local
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ update_mgmt_interface_macaddr() {
fi

# Get the ethtool magic and offset for changing the mac address in the EEPROM
ethtool_magic=$(grep "ethtool_magic" $mgmt_config | awk -F'=' '{print $2}')
ethtool_offset=$(grep "ethtool_offset" $mgmt_config | awk -F'=' '{print $2}')
ethtool_magic=$(grep "ethtool_magic" $mgmt_config | awk -F'=' '{print $2}')
ethtool_offset=$(grep "ethtool_offset" $mgmt_config | awk -F'=' '{print $2}')
if [ -z "$ethtool_magic" ] || [ -z "$ethtool_offset" ]; then
log_migration "Unable to retrieve ethtool params ($ethtool_magic,$ethtool_offset)"
return
Expand Down Expand Up @@ -84,6 +84,69 @@ update_mgmt_interface_macaddr() {
ethtool -e eth0 offset $ethtool_offset length 6 >> /host/migration/migration.log
}

migrate_nos_configuration()
{
rm -rf /host/migration
mkdir -p /host/migration

# Extract the previous NOS's partition that contains the migration artifacts
set -- $(cat /proc/cmdline)
for x in "$@"; do
case "$x" in
nos-config-part=*)
nos_dev="${x#nos-config-part=}"
;;
SONIC_BOOT_TYPE=fast*)
sonic_fast_reboot=true
;;
esac
done

if [ -n "$nos_dev" ]; then
# remove nos-config-part from cmdline
sed -r -i.bak "s/nos-config-part=[^[:space:]]+//" /host/grub/grub.cfg

# Mount the previous NOS's partition
NOS_DIR=/mnt/nos_migration
MG_GZFILE=$NOS_DIR/minigraph.xml.gz.base64.txt
MG_FILE=$NOS_DIR/minigraph.xml
ACL_GZFILE=$NOS_DIR/acl.json.gz.base64.txt
ACL_FILE=$NOS_DIR/acl.json
SNMP_FILE=$NOS_DIR/snmp.yml
mkdir -p $NOS_DIR

mount $nos_dev $NOS_DIR
if [ $? != 0 ]; then
log_migration "ERROR: cannot mount $nos_dev"
else

# decode & unzip minigraph.xml.gz.base64.txt
[ -f $MG_GZFILE ] && /usr/bin/base64 -d $MG_GZFILE | /bin/gunzip > $MG_FILE
[ -f $ACL_GZFILE ] && /usr/bin/base64 -d $ACL_GZFILE | /bin/gunzip > $ACL_FILE

# Copy relevant files
nos_migration_import $NOS_DIR/mgmt_interface.cfg /host/migration
nos_migration_import $MG_FILE /host/migration
nos_migration_import $ACL_FILE /host/migration
nos_migration_import $SNMP_FILE /host/migration

if [ "$sonic_fast_reboot" == true ]; then
mkdir -p /host/fast-reboot
nos_migration_import $NOS_DIR/arp.json /host/fast-reboot
nos_migration_import $NOS_DIR/fdb.json /host/fast-reboot
nos_migration_import $NOS_DIR/default_routes.json /host/fast-reboot
fi

umount $NOS_DIR
rmdir $NOS_DIR
fi

[ -f /host/migration/mgmt_interface.cfg ] && update_mgmt_interface_macaddr /host/migration/mgmt_interface.cfg

migration="TRUE"
fi
}

firsttime_exit() {
rm -rf $FIRST_BOOT_FILE
exit 0
Expand Down Expand Up @@ -122,13 +185,11 @@ logger "SONiC version ${SONIC_VERSION} starting up..."
# 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
mkdir -p /host/migration

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
log_migration "$onie_grub_cfg not found"
else
Expand All @@ -139,60 +200,11 @@ if [ ! -e /host/machine.conf ]; then
done
fi

# Extract the previous NOS's partition that contains the migration artifacts
set -- $(cat /proc/cmdline)
for x in "$@"; do
case "$x" in
nos-config-part=*)
nos_val="${x#nos-config-part=}"
;;
esac
done

if [ -n "$nos_val" ]; then
nos_dev=$(findfs $nos_val)
if [ $? != 0 ]; then
log_migration "ERROR: nos_dev not found. Check grub parameters"
fi
else
log_migration "ERROR: nos_val not found. Check grub parameters"
fi

if [ -n "$nos_dev" ]; then
# Mount the previous NOS's partition
NOS_DIR=/mnt/nos_migration
MG_GZFILE=$NOS_DIR/minigraph.xml.gz.base64.txt
MG_FILE=$NOS_DIR/minigraph.xml
ACL_GZFILE=$NOS_DIR/acl.json.gz.base64.txt
ACL_FILE=$NOS_DIR/acl.json
SNMP_FILE=$NOS_DIR/snmp.yml
mkdir -p $NOS_DIR
mount $nos_dev $NOS_DIR
mkdir -p /host/fast-reboot

# decode & unzip minigraph.xml.gz.base64.txt
[ -f $MG_GZFILE ] && /usr/bin/base64 -d $MG_GZFILE | /bin/gunzip > $MG_FILE
[ -f $ACL_GZFILE ] && /usr/bin/base64 -d $ACL_GZFILE | /bin/gunzip > $ACL_FILE

# Copy relevant files
nos_migration_import $NOS_DIR/mgmt_interface.cfg /host/migration
nos_migration_import $MG_FILE /host/migration
nos_migration_import $ACL_FILE /host/migration
nos_migration_import $SNMP_FILE /host/migration
nos_migration_import $NOS_DIR/arp.json /host/fast-reboot
nos_migration_import $NOS_DIR/fdb.json /host/fast-reboot
nos_migration_import $NOS_DIR/default_routes.json /host/fast-reboot

umount $NOS_DIR
rmdir $NOS_DIR
fi

update_mgmt_interface_macaddr /host/migration/mgmt_interface.cfg

migration="TRUE"
umount /mnt/onie-boot
fi

migrate_nos_configuration

. /host/machine.conf

program_console_speed
Expand Down

0 comments on commit 64e04f8

Please sign in to comment.