Skip to content

Commit

Permalink
[initramfs]: SSD firmware upgrade in initramfs (#10748)
Browse files Browse the repository at this point in the history
Why I did it
To upgrade SSD firmware in initramfs while rebooting from SONiC to SONiC and during NOS to SONiC migration.

How I did it
New option 'ssd-upgrader-part’ is introduced in grub command line, to indicate the partition and its filesystem type in which the SSD firmware updater is present. ‘ssd-upgrader-part’ syntax is ssd-upgrader-part=<partition>,<filesystem type>. Example: ssd-upgrader-part=/dev/sda8,ext4

A new initramfs script ‘ssd-upgrade’ is included in init-premount and it invokes the SSD firmware updater (ssd-fw-upgrade) present in the partition indicated by the boot option 'ssd-upgrader-part'

How to verify it
In SONiC, the SSD firmware updater is copied to “/host/” directory.
Fast-reboot is to be initiated with the ‘-u’ option ([scripts/fast-reboot] Add option to include ssd-upgrader-part boot option with SONiC partition sonic-utilities#2150)
After reboot, while booting into SONiC the SSD firmware updater will be executed in initramfs.
  • Loading branch information
ArunSaravananBalachandran authored May 12, 2022
1 parent 992d233 commit f4b22f6
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
4 changes: 4 additions & 0 deletions build_debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/arista-
sudo cp files/initramfs-tools/resize-rootfs $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/resize-rootfs
sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/resize-rootfs

# Hook into initramfs: upgrade SSD from initramfs
sudo cp files/initramfs-tools/ssd-upgrade $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/ssd-upgrade
sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/ssd-upgrade

# Hook into initramfs: run fsck to repair a non-clean filesystem prior to be mounted
sudo cp files/initramfs-tools/fsck-rootfs $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/fsck-rootfs
sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/fsck-rootfs
Expand Down
3 changes: 3 additions & 0 deletions files/image_config/platform/rc.local
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ migrate_nos_configuration()
# remove nos-config-part from cmdline
sed -r -i.bak "s/nos-config-part=[^[:space:]]+//" /host/grub/grub.cfg

# remove ssd-upgrader-part from cmdline
sed -r -i.bak "s/ssd-upgrader-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
Expand Down
35 changes: 35 additions & 0 deletions files/initramfs-tools/ssd-upgrade
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/sh

case $1 in
prereqs)
exit 0
;;
esac

# Extract kernel parameters
set -- $(cat /proc/cmdline)
for x in "$@"; do
case "$x" in
ssd-upgrader-part=*)
ssd_upgrader_part="${x#ssd-upgrader-part=}"
;;
esac
done

if [ ! -z "$ssd_upgrader_part" ]; then
echo "ssd-upgrader-part found in /proc/cmdline" > /tmp/ssd-fw-upgrade.log
mkdir -p /mnt/ssd_upgrader_part
mount -t "${ssd_upgrader_part#*,}" "${ssd_upgrader_part%,*}" /mnt/ssd_upgrader_part
if [ -x /mnt/ssd_upgrader_part/ssd-fw-upgrade ]; then
cp /mnt/ssd_upgrader_part/ssd-fw-upgrade /tmp/
cd /tmp/
umount /mnt/ssd_upgrader_part
rm -r /mnt/ssd_upgrader_part
./ssd-fw-upgrade >> /tmp/ssd-fw-upgrade.log 2>&1
else
echo "ssd-fw-upgrade not found" >> /tmp/ssd-fw-upgrade.log
umount /mnt/ssd_upgrader_part
rm -r /mnt/ssd_upgrader_part
fi
gzip /tmp/ssd-fw-upgrade.log
fi
5 changes: 5 additions & 0 deletions files/initramfs-tools/union-mount.j2
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,8 @@ fi
if [ -f /tmp/fsck.log.gz ]; then
mv /tmp/fsck.log.gz ${rootmnt}/var/log
fi

## ssd-fw-upgrade log file: /tmp will be lost when overlayfs is mounted
if [ -f /tmp/ssd-fw-upgrade.log.gz ]; then
mv /tmp/ssd-fw-upgrade.log.gz ${rootmnt}/var/log
fi

0 comments on commit f4b22f6

Please sign in to comment.