0

I need to ensure the following is run when my Raspberry Pi 4 is rebooted.

/sbin/ethtool --change eth0 advertise 0x008

Following various bits of advice, I added a last line to if-pre-up.d/ethtool as follows:

root@raspberrypipurple:/home/pi# more /etc/network/if-pre-up.d/ethtool
#!/bin/sh

ETHTOOL=/sbin/ethtool

test -x $ETHTOOL || exit 0

[ "$IFACE" != "lo" ] || exit 0

# Gather together the mixed bag of settings applied with -s/--change
SETTINGS="\
${IF_ETHERNET_PORT:+ port $IF_ETHERNET_PORT}\
${IF_DRIVER_MESSAGE_LEVEL:+ msglvl $IF_DRIVER_MESSAGE_LEVEL}\
"
[ -z "$SETTINGS" ] || $ETHTOOL --change "$IFACE" $SETTINGS

# - force interface to negotiate 100MB and not 1000MB 
#   to allow POE etc to hog some of the Cat5 pairs
$ETHTOOL --change eth0 advertise 0x008

Running the script at the CLI worked and changed the "Advertised link modes" as reported by ethtool

root@raspberrypipurple:/home/pi# /sbin/ifup -a -v
/bin/run-parts --exit-on-error --verbose /etc/network/if-pre-up.d
run-parts: executing /etc/network/if-pre-up.d/ethtool
run-parts: executing /etc/network/if-pre-up.d/wireless-tools
run-parts: executing /etc/network/if-pre-up.d/wpasupplicant
/bin/run-parts --exit-on-error --verbose /etc/network/if-up.d
run-parts: executing /etc/network/if-up.d/000resolvconf
run-parts: executing /etc/network/if-up.d/ethtool
run-parts: executing /etc/network/if-up.d/wpasupplicant

However, after the reboot my interface speed was wrong and the same if-pre-up.d/ethtool script appeared to have failed...

root@raspberrypipurple:/etc#  systemctl status networking
● networking.service - Raise network interfaces
     Loaded: loaded (/lib/systemd/system/networking.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Thu 2023-05-11 13:05:25 BST; 9h ago
       Docs: man:interfaces(5)
    Process: 354 ExecStart=/sbin/ifup -a --read-environment (code=exited, status=1/FAILURE)
   Main PID: 354 (code=exited, status=1/FAILURE)
        CPU: 31ms

May 11 13:05:25 raspberrypipurple systemd[1]: Starting Raise network interfaces...
May 11 13:05:25 raspberrypipurple ifup[364]: netlink error: failed to retrieve link settings
May 11 13:05:25 raspberrypipurple ifup[364]: netlink error: Invalid argument
May 11 13:05:25 raspberrypipurple ifup[359]: run-parts: /etc/network/if-pre-up.d/ethtool exited with return code 1
May 11 13:05:25 raspberrypipurple ifup[354]: ifup: pre-up script failed
May 11 13:05:25 raspberrypipurple systemd[1]: networking.service: Main process exited, code=exited, status=1/FAILURE
May 11 13:05:25 raspberrypipurple systemd[1]: networking.service: Failed with result 'exit-code'.
May 11 13:05:25 raspberrypipurple systemd[1]: Failed to start Raise network interfaces.

Anybody able to point out where I am going wrong?

1
  • In a standard Raspberry Pi OS installation networking is not enabled as shown by systemctl is-active 'networking' which replies inactive. You might have more success if you enable networking, but I would just use a simpler service e.g. crontab to run on startup.
    – Milliways
    May 13 at 0:33

1 Answer 1

0

After hours of messing around I discovered that adding the following to the end of /etc/network/if-pre-up.d/ethtool solved the problem.

sleep 10
/usr/sbin/ethtool --change eth0 advertise 0x008

Adding the same two lines to /etc/rc.local also worked.

The key element in this solution is the sleep. Without the sleep, ethtool appears to do its thing too soon and has no effect. I am not sure what is causing ethtool to fail without the sleeps. I suspect the half-wired cabling is causing something to retry and take longer to initialise. Even with sleeps I suspect your mileage may vary depending on boot media speed, remote hub and DHCP server response, etc. However, initially setting sleep to 60secs should cater for the worst case. Once working you can reduce the sleep time in steps till you are happy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.