Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How To Completely Copy A Hard Drive In Linux

2 views
Skip to first unread message

David T. Ashley

unread,
Sep 1, 2002, 8:39:05 AM9/1/02
to
Hi,

I have a hard drive that, as one poster has described it, is probably
"circling the drain". It is a 6GB drive. I also have an 80GB drive in the
machine.

I'd like to get one of those new 150G drives and just copy everything over
(just one big partition, more or less).

How do I copy everything over? I was thinking about removing the old
drives, putting in the 150, then installing Linux minimally, then connecting
the old drives and starting in rescue mode and copying. I'm essentially
combining multiple partitions (from the 6 and the 80) onto one root
partition.

How to do this gracefully?

Thanks, Dave.


Andrew Williams

unread,
Sep 1, 2002, 10:41:20 AM9/1/02
to

Add the new disc as (example) /dev/hdc or /dev/hdd

I would tend to partition the new disc up. My personal preferences are
to make /usr and /opt read-only (unless I am upgrading/installing), and
to keep my boot sector below Cylinder 1023 (which some of my machines
with older BIOSes need). I also like to keep /home separate.
The / directory should be in the same place (i.e. /dev/hda1 or
/dev/hda2) as it was before. That makes things easier.

You can also decide to use reiserfs or ext3. I tend to use ext3 for the
root partition and reiserfs for the rest.

Whatever you go for.

How I would then go about this is:

init 1 (you MUST be in single-user mode for this)

cd /<directory I want to copy, if you want everything, do a 'cd /'>
mount the target partition as (for example) /mnt
tar cf - . | (cd /mnt; tar xf - )
or
tar cfl - . | (cd /mnt; tar xf - )
The 'l' option is (I think) necessary if you want to stop tar following
links outside of that filesystem. That may be wrong.

Anyway, do that for each filesystem you want to copy and you have the
new disc's partitions set up.
Update your *new* /etc/fstab to reflect any changed locations and
changed filesystems.
i.e.
/dev/hda1 / ext3 defaults 1 1
/dev/hda2 /usr reiserfs defaults,ro 1 1
and so on
if the new disc will later be running as /dev/hda

Now you need a boot-floppy, booting from a CD in recovery-mode is also a
possibility if your CD handles this well.
Take the old disc out, connect the new one up where the old one was
(/dev/hda ?)
Boot from floppy or CD and run lilo

If I got this right and you did as well, you can now reboot from the
disc. Best of luck, I have done this a few times and it worked for me.

best of luck

--
opinions personal, facts suspect.
http://home.arcor.de/36bit/samba.html

Jim Levie

unread,
Sep 1, 2002, 11:46:58 AM9/1/02
to

Connect the new drive, say as hdc or hdd. Then do:

1) Use fdisk to create partitions to your likeing on the new drive.
2) For each file system partition that you make run mke2fs to make a file
system. And use mkswap on the swap parition.
3) Copy the data from the existion drives to the new drive with dump,
something like:
# mount /dev/hdc2 /mnt
# cd /mnt
# dump 0af - / | restore rf -
# rm restoresymtable
4) Make a current boot floppy
5) Move the new drive to the hda position, boot from floppy, and install
a bootloader (lilo or grub-install)

NOTES:

It's better to have separate partitions for at least /, /var, & /home.
And with a big drive and large partitions you should have a separate
/boot, say 20-40Mb as the 1st partition. The reason to separate /var from
the root file system is that it is contantly being written to while the
system is running. Should there be a system crash or power fail that
causes damage to the contents of /var it is easier to recover the system.
If the same damage happens to / it can mean a re-install. Having a
separate /home means that it's contents can be preserved across an
install. If I were doing this I'd size the partitions something like:

hdc1 - /boot - 30Mb
hdc2 - / - 7000Mb
hdc3 - swap - 2x memory, up to 2047Mb
hdc6 - /var - 500Mb min, more if this is a mail server
hdc7 - /home - the rest of the drive

The / is big enough accept the existing OS, and should allow the next
couple of versions of the OS to be installed without re-partitioning.
This would certainly be true for RedHat.

The data transfer method of preference is dump, especially for those file
systems that contain special files (like /dev and /var). And to be really
safe you should do the copy while in single user mode. Tar is okay for
places that only hold ordinary files (/home, /boot).


--
The instructions said to use Windows 98 or better, so I installed RedHat.

mjt

unread,
Sep 1, 2002, 3:25:51 PM9/1/02
to
David T. Ashley wrote:

> How do I copy everything over? I was thinking about removing the old

check out: http://www.partimage.org/


--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Michael J. Tobler: motorcyclist, surfer, # Black holes result
skydiver, and author: "Inside Linux", # when God divides the
"C++ HowTo", "C++ Unleashed" # universe by zero

Max Blackmer

unread,
Sep 2, 2002, 2:16:57 AM9/2/02
to

I think you need a special controller for the 150G dives.. but you are on
the right path to copying it over. However I do not recommend making one big
partition this can cause some serious pain if your root fs fills up. lots of
programs cease to work when there is no space to write temp or logfiles.
Here are my recommended minimal partitions:

/ 80MB to 250MB The root file system about
/usr 1GB to 3GB This is where all the user and utility programs go
how much you allocate is up to how many programs.
/usr/local O to 2GB This depends if you want to isolate the local
programs from os included programs usefule for
reinstallations and leaving local programs alone.
/tmp 250MB to 1GB This depends alot on the programs you run but
should be seperate from the root filesystem
/var 250MB to ? This has a lot to do with log files and a varable
data on some distrobutions this is where web pages
and databasess are stored as well as the log
files. depending on what you have going on here
determines the size.
/home big as possable this is the user work area you want to have as much
free space as you can get for the users as this is
were most of the useage occurs.

SWAP You want this about 2 times your memory you have with a maximum of

500MB if you are swaping more that this you need
to consider more ram as you will have serious
delays.

to show your current usage of these you can su to root and run the following
command to find the current useage:

[root@blah /]# cd /
[root@blah /]# du -hs /usr /usr/local /tmp /var /home
2.5G /usr
230M /usr/local
0 /tmp
431M /var
1.3G /home
[root@blah /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/hdb5 235M 48M 175M 22% /
none 93M 0 93M 0% /dev/shm
/dev/hda6 4.2G 1.3G 2.9G 31% /home
/dev/hda1 8.0G 4.6G 3.4G 58% /mnt/win_c
/dev/hdb1 8.0G 6.1G 1.9G 76% /mnt/win_c2
/mnt/zip 239M 125M 114M 53% /mnt/zip
/dev/hdb6 3.9G 2.3G 1.4G 61% /usr
/dev/hdb7 6.4G 262M 5.7G 5% /usr/local
/dev/hdc1 18G 463M 16G 3% /var

remember to subtract the /usr/local amount from the /usr for the actual user
if you are using a partition for /usr/local

now I deally you would have the hard drive connected to your system to
copy the files over but you must remember not to copy /dev /proc

mount the other drive in lets say /mnt/oldsysroot first you must create the
mount point in the temp dir:

mkdir /mnt/oldsysroot

next you will mount the root filesystem there (I am using my drive as an
example)

mount -t ext3 /dev/hdb5 /mnt/oldsysroot

your file system type will be found in you old /etc/fstab mine is ext3

next you will mount all the other partitions with lowest directory level
being first.

mount -t ext3 /dev/hda1 /mnt/oldsysroot/home
...
until you have them all mounted. the device will change depending on where
you positioned you drive /dev/hda /dev/hdb /dev/hdc /dev/hdd or whatever the
drive type.

once all are mounted you can use the cp command to copy the nessary
directories. for example

cp -Rpf --backup=numbered /mnt/oldsysroot/etc/* /etc

this will make backups in the target dir while copying the file to /etc
just as a a precaution makes for easy recovery.
you should do this in single user mode for speed and to eliminate
contention for resources of running apps.. but do make sure that all your fs
are mounted first before doing any of these steps.

another option is to use tar to pack everything up in a tgz file.. then
unpack them in the new drive.


>
> How to do this gracefully?
>
> Thanks, Dave.
>
>


--

Max W. Blackmer, Jr a.k.a. Daemon Watcher
The only sovereign I can allow to rule me is reason.
- Quote from Faith of the Fallen by Terry Goodkind

0 new messages