Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

i was reading this question http://serverfault.com/questions/62993/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.

share|improve this question
1  
SysPrep and NewSID are specific to Windows, plus NewSID is only required for machines which are to be joined to a domain. –  John Gardeniers Sep 7 '09 at 21:45
    
For what its worth, newsid has been retired. Turns out it wasn't nearly as big an issue as everyone thought it was. blogs.technet.com/markrussinovich/archive/2009/11/03/… –  ThatGraemeGuy Nov 3 '09 at 14:38
add comment

5 Answers

up vote 3 down vote accepted

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 configuration

grep -r image_hostname /etc and grep -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 the hostname command) and restarting networking with service network restart.

share|improve this answer
    
Even better: sed --in-place 's/image_hostname/hostname1/g' –  Cristian Ciupitu Sep 7 '09 at 20:59
    
the automated search and replace might be a little dangerous if your old or new hostname is similar to words found elsewhere in configuration files... –  Norky Jun 2 '11 at 13:10
add comment

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.

share|improve this answer
    
Yup, good point. –  markdrayton Sep 7 '09 at 19:26
add comment

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.

share|improve this answer
add comment
On Debian, modify:
/etc/hostname
/etc/hosts
/etc/mailname
/etc/resolv.conf
/etc/postfix/main.cf
/etc/exim4/update-exim4.conf.conf
/etc/udev/rules.d/z25_persistent-net.rules

And run:
/etc/init.d/hostname.sh
rm -f /etc/ssh/ssh_host*
dpkg-reconfigure openssh-server
share|improve this answer
add comment

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.

#! /bin/bash

# change hostname of virtual machine from "$1" to "$2"

error() {
  echo "Usage: $0 OldName NewName" >&2
  exit 1
}

OLD="$1"
NEW="$2"

[ -z "$OLD" -o -z "$NEW" ] && error

find /etc -type f -print0 | \
        xargs -0r grep -l "\b$OLD\b" | \
        egrep -v 'ssh|\.db' | \
        xargs -d "\n" -r sed -i -e "s/$OLD/$NEW/g"

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.

  1. if the cloned machine has hard-coded IP address(es) rather than DHCP, i edit /etc/network/interfaces.

  2. 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).

  3. delete and regenerate the host's ssh key.

share|improve this answer
    
and /etc/hosts has to be edited too so that the new hostname AND IP address are in there. –  cas Sep 7 '09 at 22:08
    
BTW, this little script is in /root/scripts on the source image (a minimal/base debian install) that i clone when i make new VMs, so that it's there to be run on the clone. i put it there rather than /usr/local/sbin because it's only ever used once when the VM is cloned. –  cas Sep 7 '09 at 22:11
    
You can edit those comments directly into your answer, and probably should. –  Novelocrat Sep 8 '09 at 15:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.