HOWTO Clone a Machine: Difference between revisions
No edit summary |
No edit summary |
||
(9 intermediate revisions by 3 users not shown) | |||
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 | ||
* | * Follow these steps, as root: | ||
# cd / | <font color=red>hostname</font> <font color=blue>#</font> '''cd /''' | ||
# tar cpzf hostname.tgz / --exclude=/hostname.tgz --exclude=/proc --exclude=/lost+found --exclude=/mnt --exclude=/sys | <font color=red>hostname</font> <font color=blue>#</font> '''mount /boot''' | ||
<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 | * 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/ | <font color=red>livecd</font> <font color=blue>#</font> '''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 | Add filesystems | ||
# mke2fs /dev/ | <font color=red>livecd</font> <font color=blue>#</font> '''mke2fs /dev/sda1''' | ||
# mkswap /dev/ | <font color=red>livecd</font> <font color=blue>#</font> '''mkswap /dev/sda2''' | ||
# mke2fs -j /dev/ | <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: | ||
# mount /dev/ | <font color=red>livecd</font> <font color=blue>#</font> '''mount /dev/sda3 /mnt/gentoo''' | ||
# mount /dev/ | <font color=red>livecd</font> <font color=blue>#</font> '''mkdir /mnt/gentoo/tmp''' | ||
# swapon /dev/ | <font color=red>livecd</font> <font color=blue>#</font> '''mkdir /mnt/gentoo/boot''' | ||
# mount -t proc | <font color=red>livecd</font> <font color=blue>#</font> '''mkdir /mnt/gentoo/proc''' | ||
<font color=red>livecd</font> <font color=blue>#</font> '''mount /dev/sda1 /mnt/gentoo/boot''' | |||
<font color=red>livecd</font> <font color=blue>#</font> '''swapon /dev/sda2''' | |||
<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. | ||
# 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 | ||
# cd /mnt/gentoo | <font color=red>livecd</font> <font color=blue>#</font> '''cd /mnt/gentoo''' | ||
# 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. | ||
# chroot /mnt/gentoo /bin/bash | <font color=red>livecd</font> <font color=blue>#</font> '''chroot /mnt/gentoo /bin/bash''' | ||
# 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: | ||
# grep -v rootfs /proc/mounts > /etc/mtab | <font color=red>livecd</font> <font color=blue>#</font> '''grep -v rootfs /proc/mounts > /etc/mtab''' | ||
# grub-install /dev/ | <font color=red>livecd</font> <font color=blue>#</font> '''grub-install /dev/sda''' | ||
Finish Configuring the machine: | Finish Configuring the machine: | ||
Line 46: | Line 56: | ||
* Set the hostname. | * Set the hostname. | ||
* Static ip address. | * Static ip address. | ||
* Reset log files. | |||
* Check /etc/make.conf | |||
Make system dirs: | |||
<font color=red>livecd</font> <font color=blue>#</font> '''mkdir -p /mnt/gentoo-distfiles''' | |||
<font color=red>livecd</font> <font color=blue>#</font> '''mkdir -p /sys''' | |||
Exit and umount drives, 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.