Howto Run Script At Boot Time To Set Ethernet Speed on Raspberry Pi 4

I have a Raspbian (Debian Buster) 10 system on Raspberry Pi 4 hardware. When the system boots, I need to force the Ethernet eth0 to a speed of 100 mbps. (The equipment it connects to has a flaw in it’s ethernet controller that makes 1,000 mbps problematic.)

From my reading, it seems the proper way to do this is to create a script that sets the ethernet speed as I want it and then create a systemd service that will cause the script to be executed at boot time. I cannot get this to work.

From the command line, I can fix the speed at 100 mbps using the command:

ethtool -s eth0 speed 100 duplex full

This works fine. I can write a script with the above command in it and when executed, it works fine.

When I try to create a systemd unit file to run it at startup, it does not work. Looking at the systemd journal file it reads:

– Logs begin at Thu 2019-02-14 04:12:00 CST, end at Fri 2021-07-23 14:36:19 CDT. –
Jul 23 14:20:42 spilnx035 systemd[1]: Starting Fix Ethernet Speed at 100 mbps…
Jul 23 14:20:42 spilnx035 fix-ethernet-speed.sh[450]: Cannot get current device settings: Invalid argument
Jul 23 14:20:42 spilnx035 fix-ethernet-speed.sh[450]: not setting speed
Jul 23 14:20:42 spilnx035 fix-ethernet-speed.sh[450]: not setting duplex
Jul 23 14:20:43 spilnx035 systemd[1]: fix-ethernet-speed.service: Succeeded.
Jul 23 14:20:43 spilnx035 systemd[1]: Started Fix Ethernet Speed at 100 mbps.

(The second to last line above is not correct. The speed remains at 1,000 mbps)

My unit file for systemd looks like this:

[Unit]
Description=Fix Ethernet Speed at 100 mbps

[Service]
Type=oneshot
ExecStart=/usr/bin//fix-ethernet-speed.sh

[Install]
WantedBy=multi-user.target

Before rebooting I have run the command:

Note: I have no experience in creating these systemd service entries. I expect that is where my error is but do not know that for sure.

Thank you in advance for any help.

Tim

This kind of stuff done using special rc.local shell script on systemd while booting Linux system.

Step 1. Create or update /etc/rc.local

Use editor such as nano or vim

sudo vim /etc/rc.local

Append your commands. For example:

#!/bin/sh
# add your commands 
# call your scripts here
/sbin/ethtool -s eth0 speed 100 duplex full 

# last line must be exit 0 
exit 0

Step 2: Set up permissions

Run

sudo chmod -v +x /etc/rc.local

Step 3: Turing on rc-local.service on Linux when systemd is init

sudo systemctl enable rc-local.service

Step 4. Reboot Linux

Reboot the Linux box:

sudo reboot

Verify status after reboot:

sudo systemctl status rc-local.service

Check your eth0 speed:

sudo ethtool eth0
sudo ethtool eth0 | grep -i --color speed
1 Like

Did your script run? Is script executable?

ls -l /usr/bin/fix-ethernet-speed.sh
chmod +x /usr/bin//fix-ethernet-speed.sh

Also it is possible that your networking config changing your setting again in config file. Can you double check that in /etc/network/interfaces file?

Also see NetworkConfiguration - Debian Wiki as per this is how you set up your config in /etc/network/interfaces file:

 iface eth0 inet static
        address .../...
        gateway ...
        up sleep 5; /sbin/ethtool -s eth0 speed 100 duplex full 
1 Like

Linux sysadmin blog - Linux/Unix Howtos and Tutorials - Linux bash shell scripting wiki