This is one thing that I am doing quite often: create a "gold image" system, export it as a Virtual Application, and then create a number of clones from that. Unfortunately, VirtualBox doesn't change the MAC address of the network interfaces, so if you clone N systems, they will end all with the same MAC… Ouch!!! And what about host names?
So, let's see how to properly rename the system (both hostname and MAC). Note that there may be other stuff you need to change (like, for example, server SSH keys). We'll make a concrete example here:
- the "golden image" isn't a running system (we can safely start a clone of it without screwing the network or anything else)
- the "golden image" is a Debian system (Lenny, in my specific case)
- the "golden image" hostname is golden, the name of the clone will be newname
First thing: start the system and log in as root. Then:
vi /etc/hosts /etc/hostname
In vi, do:
:%s/golden/newname/g :w :n :s :wq
These instructions will:
- change all occurences of golden to newname
- write out the file
- switch to the next file
- repeat the substitution
- save and exit
Then move away some annoying udev rules:
Now shut down the system:
shutdown -h now
Once the system is down, run the VirtualBox gui and select the settings for the new system; get to the advanced network settings and push the "recycle" button to generate a new MAC. Do this for each interface the machine has. Then save the settings and boot again.
…and you are done 😉 Have fun with your new clone!
Update: if your golden image can't be switched off, you can use the following procedure.
Before booting the new machine, set both interfaces as they had the cable unplugged, and generate a new MAC address for each interface straight away. Then boot it, and do all the file changes as described above, including moving away the 70-persistent-net-rules file. Now plug the virtual interfaces by right clicking on the network icon at the bottom of the console, selecting the Network Interface item and ticking the corresponding checkbox.
You are done, and once you reboot you'll see your system come up with its new name and with the network interfaces properly configured.