Add initramfs hook for Arista devices (#2595)
We are going to use initramfs hook for firmware upgrades To install Arista hook: - create folder /mnt/flash/<image dir>/platform/hooks/boot1/ from Aboot or /host/<image dir>/platform/hooks/boot1/ from Sonic - add executable script to created folder
This commit is contained in:
parent
3800508b39
commit
d632569a6a
@ -130,6 +130,8 @@ cat files/initramfs-tools/modules | sudo tee -a $FILESYSTEM_ROOT/etc/initramfs-t
|
||||
sudo mkdir -p $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/
|
||||
sudo cp files/initramfs-tools/arista-convertfs $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/arista-convertfs
|
||||
sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/arista-convertfs
|
||||
sudo cp files/initramfs-tools/arista-hook $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/arista-hook
|
||||
sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/arista-hook
|
||||
sudo cp files/initramfs-tools/mke2fs $FILESYSTEM_ROOT/etc/initramfs-tools/hooks/mke2fs
|
||||
sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/hooks/mke2fs
|
||||
sudo cp files/initramfs-tools/setfacl $FILESYSTEM_ROOT/etc/initramfs-tools/hooks/setfacl
|
||||
|
74
files/initramfs-tools/arista-hook
Normal file
74
files/initramfs-tools/arista-hook
Normal file
@ -0,0 +1,74 @@
|
||||
#!/bin/sh
|
||||
|
||||
PREREQS="arista-convertfs"
|
||||
|
||||
prereqs() { echo "$PREREQS"; }
|
||||
|
||||
case $1 in
|
||||
prereqs)
|
||||
prereqs
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
info() { printf "%04.2f: $@\n" "$(cut -f1 -d' ' /proc/uptime)"; }
|
||||
err() { info "Error: $@"; }
|
||||
warn() { info "Warning: $@"; }
|
||||
|
||||
set -e
|
||||
|
||||
root_mnt='/mnt/arista-firmware'
|
||||
root_dev=''
|
||||
aboot_flag=''
|
||||
|
||||
# Alway run cleanup before exit
|
||||
cleanup() {
|
||||
if grep -q "$root_mnt" /proc/mounts; then
|
||||
umount "$root_mnt"
|
||||
fi
|
||||
[ -e "$root_mnt" ] && rmdir "$root_mnt"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
# Extract kernel parameters
|
||||
set -- $(cat /proc/cmdline)
|
||||
for x in "$@"; do
|
||||
case "$x" in
|
||||
Aboot=*)
|
||||
aboot_flag="${x#Aboot=}"
|
||||
;;
|
||||
loop=*)
|
||||
x1="${x#loop=}"
|
||||
image_dir="${x1%/*}"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
[ -z "$aboot_flag" ] && exit 0
|
||||
|
||||
root_dev="$ROOT"
|
||||
if [ -z "$root_dev" ]; then
|
||||
err "Error: root device name is not provided"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "$root_mnt"
|
||||
mount -t ext4 "$root_dev" "$root_mnt"
|
||||
|
||||
get_sorted_hooks() {
|
||||
echo $(find "$1" -name '[0-9][0-9]-*' -type f | sort)
|
||||
}
|
||||
|
||||
if [ -d "$root_mnt/$image_dir/platform/hooks/boot1" ]; then
|
||||
for hook in $(get_sorted_hooks "$root_mnt/$image_dir/platform/hooks/boot1"); do
|
||||
if [ ! -z "$hook" ]; then
|
||||
cp "$hook" /tmp/
|
||||
hook="/tmp/`basename $hook`"
|
||||
info "Running hook $(basename $hook)"
|
||||
. "$hook"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
umount "$root_mnt"
|
||||
rmdir "$root_mnt"
|
Loading…
Reference in New Issue
Block a user