i was reading this question How to rename machines after image install and I was wondering what you do for a linux machine. I am a windows guy and am clueless about linux. If i have a linux image or VM, is there a NewSid or SysPrep program that I have to run if I restore the image to a new machine?
I am asking more about a NewSid program rather than SysPrep, I want to make an image of an already installed machine, I don't need sysPrp to do the installing for me.
It depends on the Linux distribution but generally it means adjusting a few files in
/etc
for hostname and IP details. On RedHat-flavoured distros you would have to change:/etc/hosts
: hostname and IP addresses/etc/sysconfig/network
: hostname/etc/sysconfig/network-scripts/ifcfg-eth*
: network configurationgrep -r image_hostname /etc
andgrep -r image.ip.add.ress /etc
would find anything you need to edit. Changing the files won't make the changes take immediately -- you'd either have to reboot or manually apply them by updating the hostname (using thehostname
command) and restarting networking withservice network restart
.Modern Linux distributions will remember the MAC address of the card they were first installed to. Booting them on any other machine may well cause your eth0 to become eth1 when you least expect it.
The solution is to remove the file that maintains the persistent mapping between your MAC address and ethernet interface, which (on Debian/Ubuntu at least; this is one area that is very distro-specific) is /etc/udev/75-persistent-net-generator.rules.
This answer doesn't answer your question, but is more to add a different solution to the imaging problem.
The alternative to using a system image is to use something like preseeding for Debian/Ubuntu or kickstart for CentOS/Redhat/Fedora to install a base system and then use something like Puppet, CFEngine2 or Chef to configure the rest of the system. This gives you the flexibility to change your setup, and can be used to keep the configuration in sync after you've installed the initial system. This won't take significantly longer to install the system, and will reduce the time to produce your images.
i currently use the following script when i clone virtual machines. I've been using the same technique since the mid 90s when i was regularly cloning debian boxes to act as gateway/firewall machines for schools.
there are a few manual changes as well that i haven't got around to automating yet, mostly because i don't do it often enough that it's worth spending the time to figure out.
if the cloned machine has hard-coded IP address(es) rather than DHCP, i edit /etc/network/interfaces.
edit /etc/udev/rules.d/70-persistent-net.rules so that the interface names (eth0 & eth1) get assigned to the correct MAC addresses (otherwise they'll get eth2 & eth3 because eth0 & eth1 are already defined).
delete and regenerate the host's ssh key.