HOWTO Clone a Machine: Difference between revisions

From Research
Jump to navigation Jump to search
No edit summary
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 6: Line 6:
* Follow these steps, as root:
* Follow these steps, as root:


  <font color=red>hostname</font> <font color=blue>root #</font> '''cd /'''
  <font color=red>hostname</font> <font color=blue>#</font> '''cd /'''
  <font color=red>hostname</font> <font color=blue>root #</font> '''mount /boot'''
  <font color=red>hostname</font> <font color=blue>#</font> '''mount /boot'''
  <font color=red>hostname</font> <font color=blue>root #</font> '''tar cpzf hostname.tgz / --exclude=/hostname.tgz --exclude=/proc --exclude=/lost+found --exclude=/mnt --exclude=/sys --exclude=/tmp'''
  <font color=red>hostname</font> <font color=blue>#</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 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.
* 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.
Line 14: Line 14:
== 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.
  <font color=red>livecd</font> <font color=blue>root #</font> '''fdisk /dev/sda'''
  <font color=red>livecd</font> <font color=blue>#</font> '''fdisk /dev/sda'''


  /dev/sda1 /boot 500M    ''<make this partition bootable>''
  /dev/sda1 /boot 500M    ''<make this partition bootable>''
Line 21: Line 21:


Add filesystems
Add filesystems
  <font color=red>livecd</font> <font color=blue>root #</font> '''mke2fs /dev/sda1'''
  <font color=red>livecd</font> <font color=blue>#</font> '''mke2fs /dev/sda1'''
  <font color=red>livecd</font> <font color=blue>root #</font> '''mkswap /dev/sda2'''
  <font color=red>livecd</font> <font color=blue>#</font> '''mkswap /dev/sda2'''
  <font color=red>livecd</font> <font color=blue>root #</font> '''mke2fs -j /dev/sda3'''
  <font color=red>livecd</font> <font color=blue>#</font> '''mke2fs -j /dev/sda3'''    ''<note:  my personal preference is for XFS...'''mkfs.xfs /dev/sda3'''>''




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


Copy over the hostname.tgz file onto this machine.
Copy over the hostname.tgz file onto this machine.
  <font color=red>livecd</font> <font color=blue>root #</font> '''scp root@hostname:/hostname.tgz /mnt/gentoo'''
  <font color=red>livecd</font> <font color=blue>#</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
  <font color=red>livecd</font> <font color=blue>root #</font> '''cd /mnt/gentoo'''
  <font color=red>livecd</font> <font color=blue>#</font> '''cd /mnt/gentoo'''
  <font color=red>livecd</font> <font color=blue>root #</font> '''tar -xzf hostname.tgz'''
  <font color=red>livecd</font> <font color=blue>#</font> '''tar -xzf hostname.tgz'''


Chroot into the new environment.
Chroot into the new environment.
  <font color=red>livecd</font> <font color=blue>root #</font> '''chroot /mnt/gentoo /bin/bash'''
  <font color=red>livecd</font> <font color=blue>#</font> '''chroot /mnt/gentoo /bin/bash'''
  <font color=red>livecd</font> <font color=blue>root #</font> '''env-update && source /etc/profile'''
  <font color=red>livecd</font> <font color=blue>#</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:
  <font color=red>livecd</font> <font color=blue>root #</font> '''grep -v rootfs /proc/mounts > /etc/mtab'''
  <font color=red>livecd</font> <font color=blue>#</font> '''grep -v rootfs /proc/mounts > /etc/mtab'''
  <font color=red>livecd</font> <font color=blue>root #</font> '''grub-install /dev/hda'''
  <font color=red>livecd</font> <font color=blue>#</font> '''grub-install /dev/sda'''


Finish Configuring the machine:
Finish Configuring the machine:
Line 60: Line 60:


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


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

Latest revision as of 17:18, 24 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:
hostname # cd /
hostname # mount /boot
hostname # 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 # 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 # mke2fs /dev/sda1
livecd # mkswap /dev/sda2
livecd # mke2fs -j /dev/sda3     <note:  my personal preference is for XFS...mkfs.xfs /dev/sda3>


Mount drives:

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

Copy over the hostname.tgz file onto this machine.

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

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

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

Chroot into the new environment.

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

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

Setup grub on the hard drive:

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

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 # mkdir -p /mnt/gentoo-distfiles
livecd # mkdir -p /sys

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