l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2004 Jun 21 11:59

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] Cloning a drive?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] Cloning a drive?

Tim Riley said:
> On Sat, 2004-06-19 at 12:08, Paul wrote:
>> I need to move my desktop from a (full) 10G drive to a (spare) 20G
>> drive.
> I would first try dd. After booting from a CD:
> # dd if=/dev/hda of=/dev/hdb
> This should make the first 10G of /dev/hdb the same as /dev/hda.
> So to recover the second 10G on /dev/hdb, run fdisk on /dev/hdb
> and create an additional partition.
> Disclaimer: I haven't done disk surgery in several years.
> <snip>

Gah! This can cause problems with the MBR information on where to find
partition boundaries and make it difficult to make changes later as the
geometry of the older smaller disk will be different fromm the new disk.

There is a howto on migrating your disk, and it pretty much comes down to
this assuming IDE/ATA, Only Linux on the system, you have an EBD (Emegency
Boot Disk) and one very large volume for Linux, and one swap partition:

Power down.

Connect the new drive to an empty slot/cable.

Make is slave if necessary.

Power up the machine and boot into Linux.

Use fdisk and look at the present partition information.
 Find which is swap and which is your "/"
  (let us assume /dev/hda1 is "/" and /dev/hd2 is swap)

Use fdisk to create partitions which are at least the same size as the
ones on the original disk, and make sure the numbering for the partition
is the same. If /dev/hda1 was "/boot" and /dev/hda2 was "/" and /dev/hda3
was swap, then make the first partition on the new disk "/boot", the
second "/" and the third "swap" and make sure the size of each is equal to
or greater than the size of the partition on the old disk)

Use fdisk to specify the "filesystem type" of partition. (Easiest to use
the same filesystem type as your present system's mounted volumes)

Format the "new" drive's partitions with mkfs (see man pages.)

# mkdir /new
Now, in the "/new" create the mount-points for the mounted volumes. If
/boot was /dev/hda1 then # mkdir /new/boot and then make the first
partition of the new disk mount to that mount point with "mount" (see man
page) The "/new" shoudl resemble the old disk's mounted volumes.

If you use procfs (have a mounted /proc) then:
# cd /new
# mkdir /proc

If you use "devfs (have a /dev which is mounted as tyep "devfs" then:
# cd /new
# mkdir /dev
Else, you have the older "dev":
# cd /new
# cp -aR /dev ./
(the -R is supposed to be a recursive copy, but unlike the -r, the "-R" is
supposed to handle the device specil files like c,b,f, etc and copy the
type instead of the contents.)

Now for the other directories in "/" you can do a cp -aR for each dir from
# cd /new
(Make sure that /proc, /dev, /tmp, /cdrom, /floppy, and /mnt are not in
this list below.)
# cp -aR /bin /etc /home /lib /sbin /var /boot /root /sys /usr ./

If you have mount points like /cdrom /floppy or other mount points in /mnt
then you will want to make sure each of these are dirs not copied with
contents, but instead are just made in new (you know how to mdkir)

If you have a symlink in / which points to your running kernel, then make
a relative symlink from /new to the kernel (relative meaning that the link
should not start with a "/" but should start with a directory name like:)
# cd /new
# ln -s boot/kernel/mykernel samelinknamein-new-as-wasinold

At this point, all of your data should be copied to the new disk.

Now sync and shutdown:
# sync
# shutdown -h now

Swap the drives so that the new is the primary master and the old is
either not connected or is a salve or on another free slot (secondary
master slave or primary slave)

Put in your EBD.

Boot your machine and boot from the EBD.

Do not boot from the "EBD" as-is. Pass it an arguement for a "root" which
matches the partition number on the new disk that was "/"
In this case, you have made the new disk the primary master and you have
retained the same partition numbering as the old drive. This will make the
new drive become /dev/hda and ensure the data in /etc/fstab on the new
drive is correct as well:
Assuming lilo for the EBD, press shift, and then "tab" to list the
kernels. In RedHat, the LILO screed tells you you can press control-x or
something to get "advanced options" Get to this command line:

list    of    kernels    available   for   booting
Select the appropriate kernel name and type it. I';ll assum your kernel is

mykernel root=/dev/hda2
(The above assumes that the 2nd partition on your new drive was "/")
(then press return)

At this point, your kernel should boot from the EBD, but have its "/"
actually be your new local HD.

Log in as root. Run lilo:
# lilo

Sync and reboot. (Do not forget to remove your EBD)
# sync
# reboot
(remove EBD)

Now the system should boot on its own and all should be well. If it does
not, you still have your Old drive around with all of its data.


vox-tech mailing list

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
O'Reilly and Associates
For numerous book donations.