NIC after clone

In the spirit of blogging to remember what I did, I hope I have a solution by the end of this post.

On RHEL 6, using virt-clone, I cloned a paused QEMU/KVM VM , then cloned the clone and brought that up. The  MAC on the NIC was changed, but I couldn’t bring it up:

ifup eth0
Device eth0 does not seem to be present, delaying initialization.

Looking in ifcfg-eth0, everything looked generic:

DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
NM_MANAGED=no

Just for completeness, I went ahead and added:

HWADDR=52:54:00:72:a6:c0

Don’t think that should be necessary, anyway it made no difference.

My coworker helpfully pointed out that udev might need some changes after a clone. Looking at /etc/udev/rules.d/70-persistent-net.rules I could see some of the problem:

# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.
# PCI device 0x1af4:0x1000 (virtio-pci)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:ef:64:a4", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
# PCI device 0x1af4:0x1000 (virtio-pci)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:72:a6:c0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

Looks like rather than replace eth0’s MAC addr, the clone just added a new device, and the record of the old one is still there. But the obvious thing to do here doesn’t seem to help. I tried commenting out the first definition and changing the second one to eth0. No dice – same result. So, more poking around.

StackOverflow turned up something that mentioned /sys/class/net/ which on my clone contains:

# ls /sys/class/net/
eth1 lo

Huh… so as far as the system is concerned, there really is no eth0. I could probably get by just having eth1, but I’d really like to know how to fix this.

This page brought me to some more interesting low-level stuff.

# ip link show eth0
Device "eth0" does not exist.
# ip link show eth1
2: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
    link/ether 52:54:00:72:a6:c0 brd ff:ff:ff:ff:ff:ff

Good to know we’re all reading from the same script. So who determines what gets assigned to eth0 or eth1?

That’s when I started writing this.

And then I found this forum entry. So I deleted the udev rules file and rebooted. And that worked – the NIC came back as eth0 and got a connection without me changing anything.

I guess it makes some sense. The rules file refers to a device that doesn’t exist, so a rule is added for the new device, and just in case the old one comes back, the old rule remains.

But seriously, rebooting? There has to be something I can just run to set things right.

Advertisements