🌐 🇵🇱 Polski · 🇬🇧 EN
If you use VirtualBox or any other virtualization software, you may encounter issues with network interfaces when cloning a Linux virtual machine. During network startup, you might receive strange error messages about uninitialized devices, etc. While you could remove the network interfaces from the source machine before cloning, that is not the best approach. There are other solutions. As you might have guessed, this concerns virtual network interfaces and their representation in the Linux system. During the cloning process, the files containing network interface configurations are cloned as well, but the new machine will have entirely different hardware. The solution is simple.
This situation typically occurs when cloning virtual machines.
For example, let's say we need to clone a virtual machine with CentOS installed. After the cloning operation, we check the network status and try to start it. We will see something like this:
Device eth0 does not seem to be present, delaying initialization.
The message above informs us that the device is likely not present in the system, which is correct. The device from the source machine is not the same as the one in the cloned machine. Something needs to be done about this.
Step 1 - Checking the network interface configuration
# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=08:00:27:8A:A0:19
TYPE=Ethernet
UUID=ef598847-7f31-449b-9076-f2521c1ab8ba
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp
As you can see, the "HWADDR" and "UUID" entries refer to the device from the original machine.
Step 2 - Editing the network interface file.
In VirtualBox, go to "Settings" and then "Network"
Now you can see the correct MAC address for the cloned machine's interfaces. The entry in the ifcfg-eth0 file should look like this:
DEVICE=eth0
HWADDR=08:00:27:75:5E:A4
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp
Update the MAC address and remove the UUID line.
Step 3 - Editing /udev, i.e., dynamic device files
The /etc/udev/ directory contains files for devices that are physically (or via virtual representation) present in the system. Consequently, the file containing network card data is already there. Unfortunately, the system does not refresh this automatically. It simply tries to find the devices contained in the files, and if they are not present, it displays the corresponding message:
Device eth0 does not seem to be present, delaying initialization.
Fortunately, devices like network cards are added to the system automatically. As you might have guessed, it is enough to remove the existing file so that a new one with the correct values is created after a reboot.
So, we remove the file:
# rm /etc/udev/rules.d/70-persistent-net.rules
Then we reboot the machine:
# reboot
Step 4 - Verifying network functionality after the changes.
# service network restart
Shutting down interface eth0: [ OK ]
Shutting down interface eth2: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0:
Determining IP information for eth0... done. [ OK ]
Bringing up interface eth2:
Determining IP information for eth2... done. [ OK ]
# ifconfig
eth0 Link encap:Ethernet HWaddr 08:00:27:75:5E:A4
inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe75:5ea4/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:13 errors:0 dropped:0 overruns:0 frame:0
TX packets:37 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3190 (3.1 KiB) TX bytes:3400 (3.3 KiB)
eth2 Link encap:Ethernet HWaddr 08:00:27:80:CF:EA
inet addr:192.168.56.101 Bcast:192.168.56.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe80:cfea/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:290 errors:0 dropped:0 overruns:0 frame:0
TX packets:239 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:28494 (27.8 KiB) TX bytes:29447 (28.7 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
As you can see above, the network is working as expected. Problem solved.




Comments