--- scripts/boot-network.sh 2012-02-06 09:41:26.000000000 +0000 +++ scripts/boot-network.sh 2012-02-06 09:48:58.000000000 +0000 @@ -1,6 +1,6 @@ #!/bin/bash #%stage: device -#%depends: ibft +#%depends: ibft setmac #%programs: /sbin/dhcpcd /sbin/ip # dhcpcd reqires the af_packet module #%modules: af_packet $bonding_module --- /dev/null 2012-01-24 00:00:13.882812501 +0000 +++ scripts/boot-setmac.sh 2012-02-06 09:39:52.000000000 +0000 @@ -0,0 +1,92 @@ +#!/bin/bash +#%stage: device +#%depends: usb +# +#%programs: /sbin/ip /bin/readlink /bin/cat /bin/sleep +# +## Script to set a mac address to a ethernet device. +## The device takes the following parameter from /proc/cmdline: +## - setmac.set_mac_addr=xx:xx:xx:xx:xx -> the MAC address to set +## - setmac.set_iface= -> the interface name to which the MAC should get set +## - setmac.set_module= -> module driver name +## +## The setmac.set_mac_addr= parameter is mandatory! while +## either setmac.set_iface or setmac.set_module need to be set. +## +## If setmac.set_iface is given the MAC is set to the device, +## but only if the device has a random MAC address in sysfs. +## +## If setmac.set_module is set the first device/interface with a +## random MAC address gets the given MAC assigned (marked in sysfs). +## +###### + +SETMAC_PARAM_MAC="setmac.set_mac_addr=" +SETMAC_PARAM_IFACE="setmac.set_iface=" +SETMAC_PARAM_MODULE="setmac.set_module=" +SET_MAC=0 +SET_MAC_ADDR="" +SET_MAC_TO_IFACE="" +SET_MAC_MODULE="" +SYSFS_NET_PATH="/sys/class/net" + +if [ -x /sbin/ip ] && [ -e /proc/cmdline ]; then + #for i in [kexec_jump_back_entry=0xf6ac9000 splash=silent setmac.set_mac_addr=44:1e:a1:cc:ba:f7 setmac.set_iface=eth0 quiet vga=794] + #for i in [kexec_jump_back_entry=0xf6ac9000 splash=silent setmac.set_mac_addr=44:1e:a1:cc:ba:f7 setmac.set_module=e1000e quiet vga=794] + for i in `cat /proc/cmdline` + do + if [[ "$i" =~ $SETMAC_PARAM_MAC* ]]; then + #SET_MAC_ADDR=`echo $i | sed -n "s/$SETMAC_PARAM_MAC\(.*\)/\1/p"` + SET_MAC_ADDR=${i#*${SETMAC_PARAM_MAC}*} + elif [[ "$i" =~ $SETMAC_PARAM_IFACE* ]]; then + SET_MAC_TO_IFACE=${i#*${SETMAC_PARAM_IFACE}*} + elif [[ "$i" =~ $SETMAC_PARAM_MODULE* ]]; then + SET_MAC_MODULE=${i#*${SETMAC_PARAM_MODULE}*} + fi + done + + if [ ! -z $SET_MAC_ADDR ]; then + if [ ! -z $SET_MAC_TO_IFACE ]; then + if [ -d "$SYSFS_NET_PATH/$SET_MAC_TO_IFACE" ]; then + read value < $SYSFS_NET_PATH/$SET_MAC_TO_IFACE/addr_assign_type + #if [ $value -eq 1 ] ; then + if [ $value -eq 1 ] ; then + SET_MAC=1 + fi + fi + elif [ ! -z $SET_MAC_MODULE ]; then + for dev in /sys/class/net/* ; do + # skip files that are no directories + if ! [ -d $dev ] ; then + continue + fi + read value < $dev/addr_assign_type + if [ $value -eq 1 ] ; then + iface=$(basename $dev) + if [[ "$iface" =~ eth* ]]; then + module=$(readlink $SYSFS_NET_PATH/$iface/device/driver/module ) + module=${module##*/} + if [ "$SET_MAC_MODULE" = "$module" ]; then + SET_MAC_TO_IFACE=$iface + SET_MAC=1 + break + else + echo "should we do something here?" >&2 + fi + fi + fi + done + fi + fi + + if [ $SET_MAC -eq 1 ]; then + if [ -n $SET_MAC_ADDR ] && [ -n $SET_MAC_TO_IFACE ]; then + /sbin/ip link set dev $SET_MAC_TO_IFACE address $SET_MAC_ADDR + #echo "/sbin/ip link set dev $SET_MAC_TO_IFACE address $SET_MAC_ADDR" >&2 + ret=$? + if [ "$ret" != "0" ]; then + echo "/sbin/ip couldn't set MAC-address='$SET_MAC_ADDR' to $SET_MAC_TO_IFACE" >&2 + fi + fi + fi +fi --- man/mkinitrd.8.txt 2012-02-06 09:55:20.000000000 +0000 +++ man/mkinitrd.8.txt 2012-02-06 10:03:13.000000000 +0000 @@ -207,6 +207,13 @@ *udev_timeout=*_secs_:: Set the timeout for root device detection to _secs_ seconds. Default is 10. +setmac.set_mac_addr=_MAC_ADDRESS_ & [setmac.set_iface=_iface_ | setmac.set_module=_module_]:: +Use _MAC_ADDRESS_ to specify the MAC address which should be assigned. The +format is 01:23:45:67:89:ab. Either specify _iface_ as the interface name (e.g. eth0) +of the device or specify _module_ as the kernel module/driver name. In case the kernel +module name is used, the first interface/device with a random MAC get the +given MAC address set. + Features -------- Normally *mkinitrd* detects all required features automatically, based upon @@ -274,6 +281,10 @@ *resume.userspace*:: Include resume support using the userspace program +*setmac*:: +Include support to set a MAC address to ethernet devices which +got a random MAC address assigned by the kernel + *usb*:: Include USB-support (keyboard and storage)