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

HOWTO Copy Linux to New Hard Disk

98 views
Skip to first unread message

Peter Schlosser

unread,
Apr 3, 2002, 3:26:20 AM4/3/02
to
There are many methods to copy one hard disk to another. I tried some
of them, and these are my notes. I am writing this AFTER finally
completing the whole project. What took me many nights to figure out,
ended up taking a couple of hours to complete, from start to finish,
once I knew what to do.

Many of my observations, frustrations and failures are not discussed.
I am writing this primarily as an aid to the next guy who is somewhere
in the vicinity of my experience level. I am not tenacious enough to
actually claim what level I am at. I guess the reader can decide.

RSYNC fails, apparently, when dealing with large lists of files.
DUMP/RESTORE takes a very long time, (when compressed) and creates
issues when trying to find places to store the dump files in between
the dump and restore cycle.
CPIO seems the best bet, and worked like a charm. tar and dd can also
be used, but I found my solution before getting around to trying them.

I wanted to copy a basic RedHat Linux 7.0 installation from a smaller
hard disk, to a newer larger disk. The server configuration was that
of a simple Internet Server, hosting about 90 domains, and providing
basic services to 100+ users, such as Apache, mod-perl, ssh, qmail,
wu-ftp, mysql, and so forth.

Down time needed to be minimized so the users (my clients) would not
complain. Furthermore, symbolic links are employed in the user home
directories for their html and cgi files. I wanted to be sure these
links were copied over properly.

The following sequence of commands copies the 5 file systems from an
old hard disk to a new. I chose to partition the new hard disk in the
SAME ORDER, such that, the device names were the same. Meaning, hda8
was root, hda1 was /boot, etc. This meant I did not have to edit or
modify any configuration files. (A discovery after my first few
attempts)

While running from the old hard disk, most of the setup and copying can
be performed. Only the last step, rewriting of the boot sector on the
new hard disk, was done from the Linux Rescue mode.

Old Hard Disk Layout: Master, Primary IDE.
/dev/hda1 /boot ext2 25 Mb
/dev/hda5 /usr ext2 4300 Mb
/dev/hda6 /home ext2 4300 Mb
/dev/hda7 /var ext2 256 Mb
/dev/hda8 / ext2 256 Mb
/dev/hda9 swap 256 Mb (256 DRAM installed)
unused ~356 Mb

My reasons for this hard disk upgrade was that /var was at 93% usage,
and /var/qmail and /var/httpd would fill it up. When this happened,
Apache and qmail stopped functioning. Further, a mysql upgrade would
not complete because of little /var space. /home was at 85% usage
(100+ users). Following this upgrade, /var/qmail and /var/httpd logs
will be moved so this can be minimized.

New Hard Disk: Master, Secondary IDE
partitioned using: cfdisk /dev/hdc
/dev/hdc1 /boot ext2 25 Mb
/dev/hdc5 /usr ext2 2000 Mb
/dev/hdc6 /home ext2 20000 Mb
/dev/hdc7 /var ext2 13000 Mb
/dev/hdc8 / ext2 4400 Mb
/dev/hdc9 swap 512 Mb (2x DRAM size)

Once partitioned, each partition must be "formatted" before mounting.
Don't forget disk label !!!
$ mke2fs -c -L /boot /dev/hdc1
$ mke2fs -c -L /usr /dev/hdc5
$ mke2fs -c -L /home /dev/hdc6
$ mke2fs -c -L /var /dev/hdc7
$ mke2fs -c -L / /dev/hdc8
$ mkswap -c /dev/hdc9

BE CAREFUL not to screw with any device from hdaX, since that's the old
hard disk we are copying from.

Now that each partition is formatted, each of these "file systems" may
be mounted under a mount point, and the content copied on to them. I
downed my server during this process, to minimize various daemons
changing the content of the old disk, during the copy.

$ shutdown now
$ mkdir /mnt/new
$ mount /dev/hdc8 /mnt/new

Copying the old root from hda8 to hdc8 creates the other mount points
for: boot, usr, home and var.

$ cd /
$ find / -xdev | cpio -admpv /mnt/new

Repeat the process for the remaining file systems

$ mount /dev/hdc1 /mnt/new/boot
$ cd /boot
$ find /boot -xdev | cpio -admpv /mnt/new/boot

$ mount /dev/hdc5 /mnt/new/usr
$ cd /usr
$ find /usr -xdev | cpio -admpv /mnt/new/usr

$ mount /dev/hdc6 /mnt/new/home
$ cd /home
$ find /home -xdev | cpio -admpv /mnt/new/home

$ mount /dev/hdc7 /mnt/new/var
$ cd /var
$ find /var -xdev | cpio -admpv /mnt/new/var

Savvy Linux people may spot that changing into a directory before
issuing the find is unnecessary. This may be true, but I am relaying
the ACTUAL commands I used, with success, in this endeavor.

At this point, the files are all copied. I used the reboot command to
make sure everything was flushed to disk. Then, when I saw the machine
had reset, and was about to boot again, I shut the power down. I
disconnected my Old Hard Disk and set it aside. I moved my New Hard
Disk from the Secondary IDE (master) to the Primary (master). I stuck
in my RedHat Linux Boot CD (I'm sure a boot floppy would work) and
booted into "Linux rescue" mode.

I recreated the mount point, and ran LILO to write the new boot sector.
Mounting /usr, /home and /var may not be required. I did it just to be
thorough.

$ mkdir /mnt/new
$ mount /dev/hdc8 /mnt/new
$ mount /dev/hdc1 /mnt/new/boot
$ mount /dev/hdc5 /mnt/new/usr
$ mount /dev/hdc6 /mnt/new/home
$ mount /dev/hdc7 /mnt/new/var
$ cd /mnt/new
$ sbin/lilo -v -v -r /mnt/new
$ exit

Entering exit causes a reboot. I removed the RedHat Linux Boot CD, and
allowed it to boot from the New Hard Disk. Everything checked out.

Things that did NOT work well:

using rsync to copy from one file system to another. I began running
rsync thinking it was a blessing to limit down time. While the server
was in multi-user mode (Apache, qmail, sshd, wu-ftpd, mysqld, etc) I
would run synch to copy most of the files:
$ rsync -avxz --timeout=300 --delete /home /mnt/new/home
I though I could then down the server, and run it again, and it would
only update a few more files that had changed since the last rsync.
This should have been really fast (I thought)

When my /tmp dir would fill up, and rsync would crash, I would borrow
/home, but I could not use this when rsynching home, so I'd use /usr.
This was kind of a pain.
$ rsync -avxz --timeout=300 --delete -T /home /usr /mnt/new/usr

At one point, I discovered there were files that were clearly not
"okay" such that, I would go through the whole copy process, reboot in
Linux rescue mode, and when attempting to run lilo, I would get an
"cannot run binary file" error. It turned out, /mnt/new/sbin/lilo was
corrupted. But the original at /sbin/lilo was fine. Why didn't rsync
catch this? I was afraid other files my not be right, particularly
user files in /home. So I began using the -I switch, which forces a
copy of everything, every time rsync is run (or so it seemed). So much
for rsync saving me down-time.

rsync from my RedHat Linux 7.0.16 single user mode would blow up on
large lists of files. Particularly, /home. This was using FORCE mode:
$ rsync -awxz -I --timeout=300 --delete -T /usr /home /mnt/new/home

so I switched to dump/restore. Because I was running out of room on my
disks, I guessed compressing the dump data was a good idea. It worked
pretty well, except it took a long time. It took hours to compress the
biggest partition, /home. BTW, this is an Internet server, hosting
nearly 90 domains. I wanted to complete this whole project between 1AM
and 6AM. After several late nights of attempts, I looked for another
way. For the record, the commands I used were:

$ dump -0 -f/home/root.dump -j2 -u /
$ mkdir /mnt/new
$ mke2fs -L / /dev/hdc8
$ mount /dev/hdc8 /mnt/new
$ cd /mnt/new
$ restore -rf /home/BACKUP/root.dump

Another gotcha, one of those nights, was running mke2fs without using
-L to set the disk label. I'd spend hours going through this process,
only to see Linux crash during bootup. I got the whole idea of running
mke2fs from the man page for restore. It failed to mention the disk
label thing. I'm no Linux export, each step and problem along the way
was researched using man pages, finding HOWTOs using search engines,
and reading the newsgroups. I gotta say, the Internet is pretty slick
for finding information. Just keep on trying, and one can usually find
what they need.

I've been a C++/MFC Windows Programmer for 8 or so years, since the
Windows 95 days. Nothing has been more frustrating to me, than trying
to figure out how somebody programmed something from a Windows program,
that Micro$oft has either poorly documented, or not documented at all.
oh sure, if you want to CALL THEM, pay $500 for an incident, they will
give you the answer. Open Source OS's, like Linux, are a welcome
relief to a junior hacker, such as myself.

Anyway, I hope this outline of my experience helps those who need to
"clone" a Linux installation, or upgrade their hard disk in an existing
server.

Richard Pitt

unread,
Apr 6, 2002, 2:58:50 PM4/6/02
to
Thanks for posting this - It is great when somebody takes the time to
report back on what did and didn't work - we all learn.

richard

On Wed, 03 Apr 2002 00:26:20 -0800, Peter Schlosser wrote:

> There are many methods to copy one hard disk to another. I tried some
> of them, and these are my notes. I am writing this AFTER finally
> completing the whole project. What took me many nights to figure out,
> ended up taking a couple of hours to complete, from start to finish,
> once I knew what to do.

snip...

richard

--
Richard C. Pitt C.E.O. Belcarra Messaging Corp.
ric...@belcarra.com 604-644-9265 www.belcarra.com
Embedded Linux Systems: Design, Creation, Integration
Specializing in USB, Flash, and all things TCP/IP

Richard Harmonson

unread,
Apr 6, 2002, 3:43:59 PM4/6/02
to
On Sat, 06 Apr 2002 11:58:50 -0800, Richard Pitt wrote:

> Thanks for posting this - It is great when somebody takes the time to
> report back on what did and didn't work - we all learn.
>
> richard
>

> On Wed, 03 Apr 2002 00:26:20 -0800, Peter Schlosser wrote: snip...
>
> richard
>
>
I have not had an opportunity to closely look at your results (later), but
agree with Richard Pitt. Thank you for taking the time to document and
share you experience.

--
Richard Harmonson
A+/CCNA/CNA/iNet+/Lin+/MCSA/Net+/RHCE/Serv+
http://www.kinetotech.com

Thanh

unread,
Apr 8, 2002, 11:04:50 PM4/8/02
to
goo...@quietbay.net (Peter Schlosser) wrote in message news:<7d788fbc.02040...@posting.google.com>...


Thanks for the great summary. I certainly can use it when the time comes.
There is a utility called, mirrordir (search on freshmeat.net), that I found
quite helpful.

Thanh

0 new messages