2012
05.10

I’ve been doing some playing in the lab, trying to clone lots of Ubuntu VMs on Windows Server 2012 Hyper-V.  It’s just lab work so I want the VMs to have DHCP addresses.  I am a forum browsing noob to Penguin-eering so all I’m doing is copying the VHDX file and attaching to VMs.  The problem is that when the copied VM starts up, it indicates during boot up that acquiring an IP configuration is taking too long (thus delaying the boot up) and running ifconfig when I’m logged in shows no DHCP address was acquired.

Cause?  It’s Linux’s desire to have sticky MAC addresses (which also causes problems if you have the default dynamic MAC addresses and you move/Live Migrate a Linux VM).  I did some Penguin-eering and found that there’s a file called 70-persistent-net.rules which can be found at /etc/udev/rules.d.  If you run:

cat /etc/udev/rules.d/70-persistent-net.rules then you’ll see that it contains a rule that locks the network activity to your original VM’s MAC address.  Solution?  Delete that rule.

Ubuntu doesn’t have a default root (administrator) account enabled for direct login.  Instead you use a lesser account and elevate your privileges – it’s kind of like UAC but the concept has been in UNIX for a long time.  You’ll use sudo to accomplish this.  It’s relevant because 70-persistent-net.rules is a locked down system file.  On your reference VM you’ll need to do this before copying it.

sudo vi /etc/udev/rules.d/70-persistent-net.rules will edit the file using vi.  Navigate to the line in question.  Use dd (press dd twice) to delete the line.  Then press : and enter wq! to quit vi while writing the changes with no confirmation.  Did I mention that I started my career as a UNIX developer? Smile  Some old things are hard to forget.

Shutdown the VM (easiest way for us noobs is to use the shutdown command in Hyper-V Manager or POSH) which cleanly does this via the Hyper-V integration components that are built into the Linux kernel (featured in Ubuntu 12.04).

Now the VHDX can be copied and reused in new VMs.  Don’t worry if you’ve got already copied VMs.  Just do the above edit and reboot them and you’ll be sorted … or get their new MAC address from the VM properties, edit the rules file, and reboot.

EDIT: This will probably apply if using this cloning technique with any hypervisor.

2 comments so far

Add Your Comment
  1. This behavior also appears, when you change the network adapter after installing debian via netinstall…
    Cheers from Germany,
    Jan

  2. nice info here – haven’t run into this yet but am about to attempt the same thing on my network so thanks for the heads up. Exactly the sort of arcane stuff that leaves me scratching my head as I’m originally from the Windows world.

Get Adobe Flash player