[K12OSN] copy system to another computer

Les Mikesell les at futuresource.com
Sun Jul 17 20:33:00 UTC 2005


On Sat, 2005-07-16 at 11:56, mike webb wrote:
> the command lvm vgdisplay returns "no volume groups found" thanks for 
> the primer on how the hard drives are named.
> 
> 1. piggy back the new hard disk into the computer as a "slave" or use cable select
> the new disk will need to be in the secondary positon and the old disk needs to have its jumper set for
> cable select and be in the primary position.
> 2. insert install cd and type "linux rescue" at the boot prompt (without quotes).
> 3. my old hard disk is hda, my new harddisk will be hdb, so type "dd if=/dev/hda of=/dev/hdb" (without quotes).
> 
> 4. after dd is finshed shutdown and remove the new hard disk from the 
> computer and place it in your new computer do not connect to the network 
> yet.
> 5. turn on computer and run system-config-network from a terminal to 
> change name and ip address.
> 6. shutdown computer, insert network cable and reboot.
> 
> i'm ready for the rest of the story. fyi i'm using k12ltsp 4.1  i think 
> i'm going to want to end up with 2 partions on my new drive, the primary 
> and the swap, thats all i have on my old drive.

OK, the general idea here is to fdisk matching or larger partitions on
the new disk, make file systems, mount them in a temporary spot, copy
the existing files over and install a boot loader.  There are a lot of
ways this can be done, so don't be afraid to try something different.
As I mentioned, I've never had trouble copying live systems this way
so you can add the disk and reboot as usual.

Start with an 'fdisk -l' to get your existing partition layout.  Then
fdisk /dev/hdb to create partitions on the new drive.  When doing it
by hand I usually start with a 100M (or so) ext3 partition for /boot,
then about 2 gigs for swap, then the rest in an ext3 for /.  If other
drives are involved, I'll mount them as /home and /var.   Since you
only need 3 partitions, they can all be primary.  Start with 'n' to
make a new partiton and answer the prompts.  You can use +100M for the
size of the boot partition, +2000M for swap - the rest is pretty obvious
and you can always delete them and start over.  The default partition
type is OK except for the swap partition.  For that you need to use 't'
at the fdisk prompt, give the partition number that will be used for
swap, and 82 for the type.  When you are done, use the 'w' command to
save it.

The partitions will become /dev/hdbn where n is the partition number
you created with fdisk.  Make filesystems with:
mke2fs -j /dev/hdbn (for each one)
If you make a separate /boot as the first partition that's
mke2fs -j /dev/hdb1
then mkswap /dev/hdb2   for the swap partition
and
mke2fs -j /dev/hdb3   for /  (note that the -j makes it an ext3
journaled filesystem).

Now make a mount point for your new root partiton:
mkdir /tmp/new
mount it:
mount /dev/hdb3 /tmp/new
Repeat for /boot
mkdir /tmp/new/boot
mount /dev/hdb1 /tmp/new/boot

Now copy the existing system:
cd /boot
cp -av . /tmp/new/boot
cd /
cp -av --one-file-system . /tmp/new

(You could use tar|tar, or cpio -p or dump|restore if you prefer, but
GNU cp gets it right with the -a option.  The -v slows it down quite a
bit but lets you see what it is doing).

Now you need to fix what will be your new /etc/fstab, so:
vi /tmp/new/etc/fstab
Change each LABEL=/something on the left side to the device
name noting that it will be /dev/hdan not the current /dev/hdbn
after you move to the new system.  Be sure the swap partition is
correct also.

Make the same adjustment to /new/boot/grub/grub.conf (the one in /etc
is a symlink - be sure to edit the real one at this point).  Fix all
instances of root=LABEL=/ to be root=/dev/hda3.  The 'root' line in
each grub entry should say 'root (hd0,0)' meaning that the boot
partition is the first partition on the first drive in grub's odd
notation.  If, for some reason, it currently says something else, fix
that too.  If you know more about grub than I do, you can install the
loader now with some quirky commands.  I leave it for another step.

If you want, you can edit these files under /tmp/new/etc/sysconfig/:
network, network-scripts/ifcfg-eth0, and if it exists,
networking/profiles/default/ifcfg-eth0 to change the hostname and
ip address.  Or you can wait till the machine is running.  If you
edit now, remove any HWADDR lines you see because they will be
wrong after the disk move and they aren't really necessary.

Then, shut the machine down and swap the drive into the new machine
(don't forget to change jumpers if you aren't using cable select.  Boot
the new machine with the install CD with 'linux rescue' at the boot
prompt. If your edit was correct on /etc/fstab, it will detect your hard
drive, mount it for you under /mnt/sysinstall and suggest a chroot
command to do repairs.  If it doesn't, don't panic, you can still
fix it.  If it does, execute the chroot command, then type:
grub-install /dev/hda
which was the last step to making the drive bootable.  Then type exit
twice to unmount things cleanly and reboot, removing the CD.

If the install CD didn't detect the system, you probably have something
wrong in the fstab file.  You can repeat the commands to mount the
partitions yourself, remembering that they are now in the hda position.
You might need to review the output of 'dmesg' to see how the system
is detecting your partitions and adjust fstab accordingly, then
reboot with 'linux rescue' again to make sure.

Once it boots on its own, you can run system-config-network to fix
the name and network settings if you didn't modify the copied files
earlier.

You can use approximately the same procedure to restore backups made
with tar or other file-based methods onto bare iron - you just have
to do a little more of the work from the rescue CD or knoppix.

-- 
  Les Mikesell
   les at futuresource.com





More information about the K12OSN mailing list