HOWTO Clone a Machine: Difference between revisions

From Research
Jump to navigation Jump to search
No edit summary
No edit summary
 
Line 23: Line 23:
  <font color=red>livecd</font> <font color=blue>#</font> '''mke2fs /dev/sda1'''
  <font color=red>livecd</font> <font color=blue>#</font> '''mke2fs /dev/sda1'''
  <font color=red>livecd</font> <font color=blue>#</font> '''mkswap /dev/sda2'''
  <font color=red>livecd</font> <font color=blue>#</font> '''mkswap /dev/sda2'''
  <font color=red>livecd</font> <font color=blue>#</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'''>''





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.