HOWTO Clone a Machine: Difference between revisions

From Research
Jump to navigation Jump to search
Mdeepwel (talk | contribs)
No edit summary
Line 1: Line 1:
Using standard Linux tools, this guide explains how to copy a working Linux machine onto a brand new machine, in less than an hour.
Using standard Linux tools, this guide explains how to copy a working Linux machine onto a brand new machine, in less than an hour.  It is also very useful to re-create a machine which is undergoing a disk-(subsystem) upgrade, such as migrating to RAID or a different level of RAID.


== Server/Golden Machine ==
== Server/Golden Machine ==


First, create an image of a good working system or use an existing image, if you have one. At Research we have images stored at musashi:/export/mirror/image/fresh-deployable-gentoo-images
First, create an image of a good working system or use an existing image, if you have one. At Research we have images stored at musashi:/export/mirror/image/fresh-deployable-gentoo-images
* Do this as root.
* Follow these steps, as root:


  # cd /
  <font color=red>livecd</font> <font color=blue>root #</font> '''cd /'''
  # tar cpzf hostname.tgz / --exclude=/hostname.tgz --exclude=/proc --exclude=/lost+found --exclude=/mnt --exclude=/sys --exclude=/tmp
<font color=red>livecd</font> <font color=blue>root #</font> '''mount /boot'''
  <font color=red>livecd</font> <font color=blue>root #</font> '''tar cpzf hostname.tgz / --exclude=/hostname.tgz --exclude=/proc --exclude=/lost+found --exclude=/mnt --exclude=/sys --exclude=/tmp'''


* This will create a host image of about 700 MB.
* This will create a host image of about 700 MB for a minimal server; as much as 22GB for a loaded workstation.  Forgetting to mount /boot will mean your target machine won't have any kernel, nor grub.conf!  You'll need a rescue-CD to create grub.conf, and you'll have to compile a fresh kernel.


== Client/To Be Imaged Machine ==
== Client/To Be Imaged Machine ==
Boot the machine you want the image deployed on with a minimal Gentoo CD. Mount that hard drive and partition it appropriately.
Boot the machine you want the image deployed on with a minimal Gentoo CD. Mount that hard drive and partition it appropriately.
  # fdisk /dev/hda
  <font color=red>livecd</font> <font color=blue>root #</font> '''fdisk /dev/sda'''


/dev/hda1 /boot 500M
/dev/sda1 /boot 500M     ''<make this partition bootable>''
/dev/hda2 swap 2000M
/dev/sda2 swap 8000M
/dev/hda3 /tmp 4000M
/dev/sda3 / 30000M    ''<or, the entire remainder of the disk>''
/dev/hda4 /


Add filesystems
Add filesystems
  # mke2fs /dev/hda1
  <font color=red>livecd</font> <font color=blue>root #</font> '''mke2fs /dev/sda1'''
  # mkswap /dev/hda2
  <font color=red>livecd</font> <font color=blue>root #</font> '''mkswap /dev/sda2'''
  # mke2fs -j /dev/hda3
  <font color=red>livecd</font> <font color=blue>root #</font> '''mke2fs -j /dev/sda3'''
# mke2fs -j /dev/hda4
 


Mount drives:
Mount drives:
  # mount /dev/hda4 /mnt/gentoo
  <font color=red>livecd</font> <font color=blue>root #</font> '''mount /dev/sda3 /mnt/gentoo'''
  # mkdir /mnt/gentoo/tmp
  <font color=red>livecd</font> <font color=blue>root #</font> '''mkdir /mnt/gentoo/tmp'''
  # mkdir /mnt/gentoo/boot
  <font color=red>livecd</font> <font color=blue>root #</font> '''mkdir /mnt/gentoo/boot'''
  # mkdir /mnt/gentoo/proc
  <font color=red>livecd</font> <font color=blue>root #</font> '''mkdir /mnt/gentoo/proc'''
  # mount /dev/hda3 /mnt/gentoo/tmp
  <font color=red>livecd</font> <font color=blue>root #</font> '''mount /dev/sda1 /mnt/gentoo/boot'''
# mount /dev/hda1 /mnt/gentoo/boot
  <font color=red>livecd</font> <font color=blue>root #</font> '''swapon /dev/sda2'''
  # swapon /dev/hda2
  <font color=red>livecd</font> <font color=blue>root #</font> '''mount -t proc none /mnt/gentoo/proc'''
  # mount -t proc proc /mnt/gentoo/proc


Copy over the hostname.tgz file onto this machine.
Copy over the hostname.tgz file onto this machine.
  # scp root@hostname:/hostname.tgz /mnt/gentoo
  <font color=red>livecd</font> <font color=blue>root #</font> '''scp root@hostname:/hostname.tgz /mnt/gentoo'''


Extract it into the root of the new machine /mnt/gentoo
Extract it into the root of the new machine /mnt/gentoo
  # cd /mnt/gentoo
  <font color=red>livecd</font> <font color=blue>root #</font> '''cd /mnt/gentoo'''
  # tar -xzf hostname.tgz
  <font color=red>livecd</font> <font color=blue>root #</font> '''tar -xzf hostname.tgz'''


Chroot into the new environment.
Chroot into the new environment.
  # chroot /mnt/gentoo /bin/bash
  <font color=red>livecd</font> <font color=blue>root #</font> '''chroot /mnt/gentoo /bin/bash'''
  # env-update && source /etc/profile
  <font color=red>livecd</font> <font color=blue>root #</font> '''env-update && source /etc/profile'''


Verify /boot/grub/grub.conf and /etc/fstab
Verify /boot/grub/grub.conf and /etc/fstab


Setup grub on the hard drive:
Setup grub on the hard drive:
  # grep -v rootfs /proc/mounts > /etc/mtab
  <font color=red>livecd</font> <font color=blue>root #</font> '''grep -v rootfs /proc/mounts > /etc/mtab'''
  # grub-install /dev/hda
  <font color=red>livecd</font> <font color=blue>root #</font> '''grub-install /dev/hda'''


Finish Configuring the machine:
Finish Configuring the machine:
Line 60: Line 59:
* Check /etc/make.conf
* Check /etc/make.conf


Make system dirs
Make system dirs:
  # mkdir -p /mnt/gentoo-distfiles
  <font color=red>livecd</font> <font color=blue>root #</font> '''mkdir -p /mnt/gentoo-distfiles'''
  # mkdir -p /sys
  <font color=red>livecd</font> <font color=blue>root #</font> '''mkdir -p /sys'''


Exit and umount drives, remove Gentoo CD, reboot the machine.
Exit and umount drives, remove Gentoo CD, reboot the machine.

Revision as of 17:24, 17 November 2009

Using standard Linux tools, this guide explains how to copy a working Linux machine onto a brand new machine, in less than an hour. It is also very useful to re-create a machine which is undergoing a disk-(subsystem) upgrade, such as migrating to RAID or a different level of RAID.

Server/Golden Machine

First, create an image of a good working system or use an existing image, if you have one. At Research we have images stored at musashi:/export/mirror/image/fresh-deployable-gentoo-images

  • Follow these steps, as root:
livecd root # cd /
livecd root # mount /boot
livecd root # tar cpzf hostname.tgz / --exclude=/hostname.tgz --exclude=/proc --exclude=/lost+found --exclude=/mnt --exclude=/sys --exclude=/tmp
  • This will create a host image of about 700 MB for a minimal server; as much as 22GB for a loaded workstation. Forgetting to mount /boot will mean your target machine won't have any kernel, nor grub.conf! You'll need a rescue-CD to create grub.conf, and you'll have to compile a fresh kernel.

Client/To Be Imaged Machine

Boot the machine you want the image deployed on with a minimal Gentoo CD. Mount that hard drive and partition it appropriately.

livecd root # fdisk /dev/sda
/dev/sda1	/boot	500M     <make this partition bootable>
/dev/sda2	swap	8000M
/dev/sda3	/	30000M     <or, the entire remainder of the disk>

Add filesystems

livecd root # mke2fs /dev/sda1
livecd root # mkswap /dev/sda2
livecd root # mke2fs -j /dev/sda3


Mount drives:

livecd root # mount /dev/sda3 /mnt/gentoo
livecd root # mkdir /mnt/gentoo/tmp
livecd root # mkdir /mnt/gentoo/boot
livecd root # mkdir /mnt/gentoo/proc
livecd root # mount /dev/sda1 /mnt/gentoo/boot
livecd root # swapon /dev/sda2
livecd root # mount -t proc none /mnt/gentoo/proc

Copy over the hostname.tgz file onto this machine.

livecd root # scp root@hostname:/hostname.tgz /mnt/gentoo

Extract it into the root of the new machine /mnt/gentoo

livecd root # cd /mnt/gentoo
livecd root # tar -xzf hostname.tgz

Chroot into the new environment.

livecd root # chroot /mnt/gentoo /bin/bash
livecd root # env-update && source /etc/profile

Verify /boot/grub/grub.conf and /etc/fstab

Setup grub on the hard drive:

livecd root # grep -v rootfs /proc/mounts > /etc/mtab
livecd root # grub-install /dev/hda

Finish Configuring the machine:

  • Set a root password.
  • Set the hostname.
  • Static ip address.
  • Reset log files.
  • Check /etc/make.conf

Make system dirs:

livecd root # mkdir -p /mnt/gentoo-distfiles
livecd root # mkdir -p /sys

Exit and umount drives, remove Gentoo CD, reboot the machine.