Recently, there was a little bit of confusion when following the article about activating network bonding without ifenslave – How to enable Linux bonding without ifenslave. At first, there were couple of errors:
livecd ~ # echo balance-alb > /sys/class/net/bond0/bonding/mode -bash: echo: write error: Device or resource busy livecd ~ # echo "+enp129s0f0" > /sys/class/net/bond0/bonding/slaves -bash: echo: write error: Operation not permitted
Or similar error when changing the bonding mode:
livecd ~ # echo 4 > /sys/class/net/bond0/bonding/mode -bash: echo: write error: Directory not empty livecd ~ # echo 802.3ad > /sys/class/net/bond0/bonding/mode -bash: echo: write error: Directory not empty
The server just booted in rescue live cd and there is no active network configuration:
SCREENSHOT 1) Apparently, the /sys/class/net/bond0/bonding/mode and /sys/class/net/bond0/bonding/slaves are in read only state.
No writes means no new configuration could be installed and the bonding cannot be configured (reconfigured).
Bonding mode could be changed only when the bonding device is in DOWN state.
Network interfaces could be added to the boding device only if they were in DOWN state, too.
In addition, changing bonding mode could only happen if there were no network interfaces added to the bonding interface.
So if you intend to configure the bonding network device using /sys file system make sure all network devices you are going to use are in DOWN state. Even the network devices do not have IP (or it may be an IP from 169.254.0.0/16 – a random IP from 169.254.0.0/16 after a DHCP failed configuration) they may be in UP state! You may use IP or/and ifconfig commands to set the state of the interface or the interface’s link into DOWN state.
Many Linux distributions and live CDs use DHCP by default for all discovered wired network interfaces and it is typical to boot into a live cd and the bonding interface or the network interfaces to be in UP state.
There are also errors in dmesg (always check dmesg when receiving errors from tools for system configuration!), which are much more informative (for the bond device):
bond0: option mode: unable to set because the bond device is UP bond0: enp129s0f0 is up - this may be due to an out of date ifenslave bond0: enp129s0f1 is up - this may be due to an out of date ifenslave
Set the DOWN state to the network devices using IP (from iproute2)
Replace the names (bond0, eth0, eth2) with those in your server accordingly.
ip link set bond0 down ip link set eth0 down ip link set eth0 down
Set the DOWN state to the network devices using ifconfig
Replace the names (bond0, eth0, eth2) with those in your server accrodingly.
ifconfig bond0 down ifconfig eth0 down ifconfig eth1 down
Here is the our example from a Gentoo Live CD.
SCREENSHOT 2) Despite there si no IP set for bond0 the device is in UP state.
The interfaces enp129s0f0 and enp129s0f1 are UP with IPs from the network 169.254.0.0/16, which is not a real one.
SCREENSHOT 3) No matter which tool we use the ip (iproute2) or the old school one ifconfig to set the network interface in DOWN state.
As soon as you set the DOWN you can use /sys file system to set modes and the slaves.
SCREENSHOT 4) Even we have set the bonding interface in DOWN state we still cannot change the mode, because we included two network interfaces in the bonding group above.
To change the bonding mode the bonding device must be in DOWN state and no slaves devices to exist in it. Set the boding state in DOWN. Because we added the two network interfaces before, now we must remove them from the group and then change the boding mode to LACP. Now you can add the IP and set the link to UP (mind the right syntax!).