Thursday 24 November 2016

Solve "device eth0 does not seem to be present, delaying initialization"

device eth0 does not seem to be present, delaying initialization:

This error is mostly observed due to changes in MAC address of the NIC card used in the Linux machine.

For me it occurred when I cloned one of my Linux virtual machine. So the cloned machine was not able to detect the NIC and every time I tried to restart the network it was throwing this error.

Solution:
Now when you clone a machine all the setting and default properties gets cloned from the original one including the hostname, IP address and MAC address which should be different for each machine as they are the one which helps you recognize machines on the network.

Now changing hostname and IP Address is quiet easy task but changing a MAC address is a bit tricky as you should know the MAC id of the new NIC installed.

The MAC id details for the NIC card is stored in the below mentioned file which is automatically created every time the machine boots.
/etc/udev/rules.d/70-persistent-net.rules
If you open this file the contents would be like this
# less /etc/udev/rules.d/70-persistent-net.rules # PCI device 0x1022:0x2000 (pcnet32) SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", 
ATTR{address}=="00:50::56:8a:1f:32", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
Delete this file
# rm -f /etc/udev/rules.d/70-persistent-net.rules
Reboot your machine as after reboot a new file will be created with the details of your new NIC card
# less /etc/udev/rules.d/70-persistent-net.rules # PCI device 0x1022:0x2000 (pcnet32)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", 
ATTR{address}=="00:50:56:bb:72:20", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
As you can see the difference in MAC id and NIC card name

It is time for you to copy the new MAC id and NIC card name to your ifcfg-eth0 file
# vi /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth1 HWADDR=00:50:56:8a:50:9f
Restart your network and everything should work fine

In case you want to use the same NIC name eth0 then replace the NIC card name from 70-persistent-net.rules file and reboot your machine for the changes to take affect



Note: If you're creating VM images (ami etc.) These five lines should fix everything for you.

sed -i '/HWADDR/d' /etc/sysconfig/network-scripts/ifcfg-eth0 
sed -i '/HOSTNAME/d' /etc/sysconfig/network-scripts/ifcfg-eth0 
sed -i '/UUID/d' /etc/sysconfig/network-scripts/ifcfg-eth0 
rm -f /etc/udev/rules.d/*-persistent-* 
touch /etc/udev/rules.d/75-persistent-net-generator.rules 

The first three sed lines remove the mac address, hostname and uuid lines from the interface. And the final two will simply block the persistent interface file from being created.
If you're running a VM on a hosting provider such as DigitalOcean, this error may also appear if you've got a mismatching kernel installed on your instance and the one provided by the hypervisor. This is due to the incorrect modules being loaded.




No comments:

Post a Comment