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 arista-net initramfs hook #899

Merged
merged 1 commit into from
Aug 20, 2017
Merged
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
4 changes: 4 additions & 0 deletions build_debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/arista-
sudo cp files/initramfs-tools/mke2fs $FILESYSTEM_ROOT/etc/initramfs-tools/hooks/mke2fs
sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/hooks/mke2fs

# Hook into initramfs: rename the management interfaces on arista switches
sudo cp files/initramfs-tools/arista-net $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/arista-net
sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/arista-net

## Hook into initramfs: after partition mount and loop file mount
## 1. Prepare layered file system
## 2. Bind-mount docker working directory (docker aufs cannot work over aufs rootfs)
Expand Down
61 changes: 61 additions & 0 deletions files/initramfs-tools/arista-net
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/sh

Copy link
Collaborator

Choose a reason for hiding this comment

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

add comment for this file

rename the management interfaces on arista switches

case $1 in
prereqs)
exit 0
;;
esac

set -e

# Extract kernel parameters
set -- $(cat /proc/cmdline)
items=""
for x in "$@"; do
case "$x" in
Aboot=*)
aboot_flag="${x#Aboot=}"
;;
net_*)
item="${x#net_}"
items="$items $item"
;;
platform=*)
platform_flag="${x#platform=}"
;;
esac
done

arista_net_rename() {
local device_path="$1"
local new_name="$2"
local from_name="$3"
for path in $(ls -d /sys/class/net/$from_name* 2>/dev/null); do
local devid="$(realpath "$path/device")"
if echo "$devid" | grep -q "$device_path"; then
local cur_name="${path##*/}"
ip link set "$cur_name" name "$new_name"
return
fi
done
}

# Iterate over all the net_maX items found in the cmdline two times.
# First time renaming the interfaces to maX.
# The second time renaming them to their final name ethX.
if [ -n "$aboot_flag" -a "$platform_flag" == 'rook' ]; then
for item in $items; do
key="${item%=*}"
value="${item#*=}"
arista_net_rename "$value" "$key" eth
done
for item in $items; do
key="${item%=*}"
value="${item#*=}"
index="${key#ma}"
index="$(( $index - 1 ))"
newKey="eth$index"
arista_net_rename "$value" "$newKey" ma
done
fi