3

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.

BLAKE
  • 706
  • 9
  • 25
  • 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 07 '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. http://blogs.technet.com/markrussinovich/archive/2009/11/03/3291024.aspx – ThatGraemeGuy Nov 03 '09 at 14:38

5 Answers5

3

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.

markdrayton
  • 2,429
  • 1
  • 20
  • 24
3

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.

crb
  • 7,928
  • 37
  • 53
2

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.

David Pashley
  • 23,151
  • 2
  • 41
  • 71
2
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
Tar
  • 21
  • 1
1

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.

cas
  • 6,653
  • 31
  • 34
  • and /etc/hosts has to be edited too so that the new hostname **AND** IP address are in there. – cas Sep 07 '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 07 '09 at 22:11
  • You can edit those comments directly into your answer, and probably should. – Phil Miller Sep 08 '09 at 15:57