Files
warewulf/overlays/wwinit/rootfs/warewulf/init.d/50-ipmi
Jonathon Anderson 987eeb019b Fixed IPMI VLAN configuration
- Closed: #1892

Signed-off-by: Jonathon Anderson <janderson@ciq.com>
2025-07-02 13:53:11 +02:00

111 lines
3.4 KiB
Bash
Executable File

#!/bin/sh
. /warewulf/config
export PATH=/usr/bin:/bin:/usr/sbin:/sbin
echo "Warewulf prescript: IPMI"
echo
if [ "$WWIPMI_WRITE" != "true" ]; then
echo "IPMI write not configured: skipping"
exit
fi
echo "Loading IPMI kernel modules..."
modprobe ipmi_si ipmi_ssif ipmi_devintf ipmi_msghandler || (
echo "Unable to load IPMI kernel modules: skipping IPMI configuration"
exit
)
if [ ! -e /dev/ipmi0 ]; then
echo "/dev/ipmi0 does not exist; creating..."
sleep 1
ipmi_dev=$(grep ipmidev /proc/devices | awk '{ print $1 }')
mknod -m 0666 /dev/ipmi0 c "$ipmi_dev" 0
fi
command -v ipmitool >/dev/null 2>&1 || (
echo "ipmitool is not available: skipping IPMI configuration"
exit
)
lan_info="$(ipmitool lan print 1)"
if [ -n "$WWIPMI_VLAN" ]; then
prev_vlan=$(echo "$lan_info" | grep "^802.1q VLAN ID *:" | awk -F': ' '{print $2 }')
if [ "$prev_vlan" == "$WWIPMI_VLAN" ] || [ "$prev_vlan" = "Disabled" -a "$WWIPMI_VLAN" = off ]; then
echo "IPMI VLAN: $WWIPMI_VLAN"
else
echo "IPMI VLAN: $prev_vlan -> $WWIPMI_VLAN"
ipmitool lan set 1 vlan id "$WWIPMI_VLAN"
fi
fi
if [ -n "$WWIPMI_IPADDR" ]; then
prev_ip=$(echo "$lan_info" | grep "^IP Address *:" | awk -F': ' '{ print $2 }')
if [ "$prev_ip" != "$WWIPMI_IPADDR" ]; then
echo "IPMI IP address: $prev_ip -> $WWIPMI_IPADDR"
ipmitool lan set 1 ipsrc static
ipmitool lan set 1 ipaddr "$WWIPMI_IPADDR"
ipmitool lan set 1 access on
else
echo "IPMI IP address: $WWIPMI_IPADDR"
fi
fi
if [ -n "$WWIPMI_NETMASK" ]; then
prev_netmask=$(echo "$lan_info" | grep "^Subnet Mask *:" | awk -F': ' '{ print $2 }')
if [ "$prev_netmask" != "$WWIPMI_NETMASK" ]; then
echo "IPMI netmask: $prev_netmask -> $WWIPMI_NETMASK"
ipmitool lan set 1 netmask $WWIPMI_NETMASK
else
echo "IPMI netmask: $WWIPMI_NETMASK"
fi
fi
if [ -n "$WWIPMI_GATEWAY" ]; then
prev_gateway=$(echo "$lan_info" | grep "^Default Gateway IP *:" | awk -F': ' '{ print $2 }')
if [ "$prev_gateway" != "$WWIPMI_GATEWAY" ]; then
echo "IPMI gateway: $prev_gateway -> $WWIPMI_GATEWAY"
ipmitool lan set 1 defgw ipaddr "$WWIPMI_GATEWAY"
else
echo "IPMI gateway: $WWIPMI_GATEWAY"
fi
fi
if [ -n "$WWIPMI_USER" ]; then
prev_user=$(ipmitool -c user list 1 | awk -F, '{ if ($1 == 2) { print $2; exit } }')
if [ "$prev_user" != "$WWIPMI_USER" ]; then
ipmitool user set name 2 "$WWIPMI_USER"
ipmitool user priv 2 4 1
ipmitool user enable 2
echo "IPMI username: $prev_user -> $WWIPMI_USER"
else
echo "IPMI username: $WWIPMI_USER"
fi
fi
if [ -n "$WWIPMI_PASSWORD" ]; then
ipmitool user test 2 20 "$WWIPMI_PASSWORD" >/dev/null || ipmitool user test 2 16 "$WWIPMI_PASSWORD" >/dev/null
if [ $? -ne 0 ]; then
ipmitool user set password 2 "$WWIPMI_PASSWORD"
ipmitool user priv 2 4 1
ipmitool user enable 2
echo "IPMI password: [updated]"
else
echo "IPMI password: [unchanged]"
fi
fi
echo "Configuring Serial over LAN..."
ipmitool channel setaccess 1 2 link=on ipmi=on callin=on privilege=4
ipmitool sol set force-encryption true 1
ipmitool sol set force-authentication true 1
ipmitool sol set privilege-level admin 1
ipmitool sol payload enable 1 2
ipmitool sol set enabled true 1 1
speed=38.4 # 19.2 38.4 115.2
ipmitool sol set non-volatile-bit-rate $speed 1
ipmitool sol set volatile-bit-rate $speed 1