Back
RED HAT LINUX HARD DRIVE COPYINGPREFACEThis document will help explain how to copying one Red Hat Linux System (RHLS) to another system or new hard drive. Resulting in a retained system, not having to reinstall one single application or lose any important data that you might have already accumlated. When I first went to the net in search for a document that would explain how to do this, I found many that explained it using different methods and as with many other support docs, it was too general in explaining the process! I don't know about you folks, but I like detail! I'm going to attempt in this document to explain how I done this and hope to find that it works completely for you too! By the name of this support document you notice I say "Red Hat". I'm not excluding other distrubutions, but as far as I know, this does work for Red Hat 7.1, 7.2 8.0, 9.0 and the now new Fedora Core distrubutions. You might can use this as a guide-line for other distrubutions. I really don't know why it wouldn't work, but you might have to bend a little on your own to come up with any work around that would help you in other distrubutions. DISCLAIMER Just to let you know, you should always exercise your backup plan when you begin to mess around with your data! Also, when using this document or any other document that I have written, you use it at your OWN RISK!!! Be wise and determine your ability to be able to preform this task. If ever in doubt, seek professional help! Thank you. OUR TEST MODEL I've performed this task on both x86 systems, that being AMD and Intel. CPU speeds ranging from 166MHz to 1.7GHz. But for the example model, I was using a PIII (Intel) 1GHz CPU with 512MB of PC133 SDRAM. The original hard drive had a capacity of 20GB and was very quickly runnuing out of hard drive space. To remedy this, I bought a 60GB for the upgrade. This new hard disk should give a little more breathing room for extra data. THE CHECKLIST Now we need to get our "ducks in a row"! Below is the checklist of items we need to have:
Let's move on! MAKING THE CONNECTIONS Before we begin any copying, we must make our physical connections with our two hard drive. I do recommend that you know that the PC you are working with is functioning correctly and has no known issues with the hardware. Practicuraly, the IDE controllers on the motherboard. These controllers (Primary and Secondary IDE 40-Pin ports) are the bridges in completing this task! With this assured, we begin by continuing in making the physical connections. Of course, one of our drives will be possibly already connected. If not, we should have the working and booting RHLS connected as our PRIMARY-MASTER. Also, recommended, you should hook the drive "to be copied to" as your SECONDARY-MASTER. If at this point your scratching your head, this maybe be your que to seek a good friend or professional help. Not meaning to discredit anyone, but the knowledge of knowing how IDE drives are configured on a PC is something you should be familiar with. Knowing about IDE configuration will also come to play when editing for the booting kernel and reinstalling the boot loader. TAKING INVENTORY This is where the fun begins! At this point, we should be sitting in front of our system and with all items needed at hand. I recommend you to be logged in as root and also not in the X Windows Desktop enviroment. You should be here: [root@yoursystem]#
Now lets look at we have mounted. This can be done by running the command mount. You'll probably see some output like this:
/dev/hda2 on / type ext3 (rw)As you can see I have several mounted objects. In this output, there is only two items that we are really concerned with. That would be the actual mounted drives. These drives are /dev/hda1 &
/dev/hda2. Everything else here is "virtual" and contains no
actual data to be backed up. Pen and paper comes in handy here. I would certainly
write down your mounted drive configuration. If your drive configuration
is /dev/hda1 & /dev/hda2, write this down to
refer to later. Also you should write down the on part also.
For example in the output above, you see where my drive configurations
says /dev/hda2 on / . This is important information also.
Remember: hda is the Primary Master IDE Drive hdb is the Primary Slave IDE Drive hdc is the Secondary Master IDE Drive hdd is the Secondary Slave IDE Drive 1, 2, 3, and on is the Partition number. Example, if you see hda1, this is indicating that your on the Primary Master
Drive, Partition number 1.GETTING YOUR NEW DRIVE READY With your new drive hooked up and ready for the transfer, we must get the drive in a state to accept data. The first step is to use a partitioning program called fdisk. This is usually located under the
/sbin directory in the top level of the file-system. A important note about
the program fdisk!!! When this program is running this is about the close
you can get in destroying your current data. PLEASE follow these
instructions very closely.
Actually, we are not going to run fdisk on the working RHLS, but if the new drive your copying to contains data or another operating system (e.g- Windows), then this data is in jeporady. I'm assuming that your new hard drive is hooked up on the Secondary-Master which under Linux will be /dev/hdc. Now
let's run the fdisk program by simply typing fdisk plus the
drive we are partitioning, which should be at /dev/hdc. Type
this at the command line:./fdisk /dev/hdcOnce opened, you'll probably get some output similar to the below:
The number of cylinders for this disk is set to 4864.You should now type the letter p to "print" the current
partition tabel. This will let us know how we should partition for our new
RHLS. Below is some possible ouput of your "print" command:
Disk /dev/hdc: 255 heads, 63 sectors/tracks, 7476 cylindersThis ouput would indicate that we currently have no partitions defined on the new drive. We are going to be setting up 3 new Primary Partitions. The first partition will be the partition that will contain our booting kernel. You will now need to type the letter n to begin the
partitioning. When enterning the n command you will get an
output similar below:
Command action
Now we need to select p for "primary". After this well be
asked to enter what partition, and of course we'll want to enter
1. Next enter the cylinder you want to start with. Since this
is a new drive we'll start with cylinder number 1. This next part will now have to be thought upon!
View the output below:Last cylinder or +size or +sizeM or +sizeK (1-7476, default
7476):We will need to determine the new size we want to give our new partition. Since this will be the partition that will hold the kernel and possible upgraded kernels in the future, I recommend giving this partition atleast 1 gigabytes(GB). Some might disagree, but I know I have the hard drive space now to do this. You will now need to enter the size in megabytes(MB). Enter this: +1024MRemember, it takes 1024MB to make 1GB. Now we can view the updated partition table by typing the letter p to "print"
the new table. You should recieve the output below:
Command (m for help): p
You can now see our newly created partition on /dev/hdc1.
Let's now do our second partition. The next partition will be the main partition. This
partition holds alot of data, so we will dedicate a great portition of the drive for
this partition. To do this will will need to press the key
n again. Just like last time, you'll be asked to enter if this partition
will be a Primary or Extended, and of course, you'll want to enter
P for Primary. Next, enter the partition number, which will be
2. Now you'll need to enter the beginning cylinder, just press "enter" for
the default and next let's define the partition size again.
If you remember, we defined the last partition by size of "Mega-bytes". By using the table print-out, we notice that 1-125 cylinders equals roughly 1GB. By using this formula and a trusty old table caculator, we can determine the next partition by the amount of cylinders. Let me remind you, this is an example on a 60GB drive. Your numbers will probably be totally different. Please make note of this! To begin to detemine this next size, we look at the remaining cylinders we have. 1 + 125 = 126. Take the 126 and subtract this from the total cylinders, which is 7476. This will give you the difference of 7350. In our example system, we have a system that has a total system memory of 512MB. The reason I'm pointing this out now is because, going ahead and subtracting for the swap partition size will give us the size to define for our main partition. Most swap partitions are usually double what the system memory is. Thus, 512MB X 2 = 1024MB. Meaning we will want to subtract 126 cylinders from 7350 (remaining) cylinders, giving a total of 7224. This 7224 is what we will want to type in for our next partition, which is number 2 at this point. Enter this: 7224Let's use the p command to print the updated partition table.
You will now see this new output:
Command (m for help): p
We now can see the newly added partition /dev/hdc2. This leads us to the
last partition, which will be the swap partition. If your not familiar with what swap
is, it's like your system's virtual memory. When your system runs out of physical RAM
(Random Access Memory), then this part of the hard drive is used for any other data that
needs to be retained. Very important system component. Bascially like before, we use the
n command to create the partition. Then p for "Primary".
Select
the number 3 for the partition number. This will be so easy! You will only need to press
enter for the default beginning cylinder. Then the default for the ending cylinder.
Remember, we reserved for the swap partition! There is no need for any math on this last
partition.
Next, we will need to change the Partition ID of /dev/hdc3.
To do this, you will need to enter the command t.You'll be
asked what Partition number you'll want to change. Here we will enter the
number 3. After entering the number 3, you should now enter the number 82.
This will set /dev/hdc3 System ID to "Linux Swap". To verfiy
this run your "print" command again. By pressing the letter
p, you get the updated partition table.
Device   Boot Start End   Blocks Id System
As you can see we made the change to /dev/hdc3 to a Linux
Swap Partition. To save these changes, we must now press the
w key to "write" the changes. Once the partition table is
updated, we are now ready to format! FORMATTING Still as root, and also in the /sbin
directory, we will be using mkfs.ext3 file-system formatting utility.
Most newer file-systems are ext3. Simply run this for your two partitions
/dev/hdc1 & /dev/hdc2. ./mkfs.ext3 /dev/hdc1When completed, you should now run it for /dev/hdc2. ./mkfs.ext3 /dev/hdc2Now let's format our swap partition. This is a special command. Still located in the /sbin directory, run this:./mkswap /dev/hdc3We are going to now label our partitions. THIS IS VERY IMPORTANT! Remember when I asked you to write down your "mounted" information? This is where this is important. If your RHLS is a default installation, then you recieve the labeling of /boot & /.
/boot would be assigned to your /dev/hdc1
partition, which holds the kernel of the system. Also, / would be your
main partition, where all your /home directories and pretty
much your whole system would live. This was assigned to your
/dev/hdc2 partition.
What we need to do is give the proper labeling and lucky enough, that
utility is in the /sbin directory where you should be located
now. At the command line, we should type out the following:
./e2label /dev/hdc1 /boot
Proceeding to the last label. Type this at the command line: ./e2label /dev/hdc2 /
This gets us to the most important part of this whole process. The copying of our data. Let's proceed! COPYING Now we are ready for the fun part. It's pretty much down hill from here! The first thing we want to do is get into SINGLE USER MODE. One main reason to do this is to shutdown any background running daemons and to get the system in a higher resource state. To do this, type this at the command line: /sbin/shutdown now
After in single user mode, you'll be brought to a "not so familiar" command prompt. You should be at something like: Sh-2.056#
Now let's start umounting the unnecessary mounted objects. By running our mount command, we'll be seeing our current mounted items.
View below possible ouput that you might see:
/dev/hda2 on / type ext3 (rw)
What we want to accomplish here is to only have /dev/hda1 &
/dev/hda2 the only two mounted objects. To begin unmounting,
you'll want to start with the bottom item and umount everything with the
exception of /dev/hda1 & /dev/hda2. To give an
example:
umount /proc/sys/fs/binfmt_misc
After umounting our first not needed object, we can run the mount
command and get this new output:
/dev/hda2 on / type ext3 (rw)
As you can see, we lost the /proc/sys/fs/binfmt_misc object
and now we should move up till the only two items we have mounted are
/dev/hda1 & /dev/hda2. Now we are set to mount
our new drive to the filesystem by first creating mount points. What we
need to do is do a:
cd /
This will get us to the "top level" of the filesystem. By doing a ls at the command prompt, we will see:
bin dev home lib misc  opt root tmp varWhat we are looking at is the directories that will need to be copied over to our new drive. But again, we need to create our mount points and mount our new partitions. Type this at the command line:
mkdir d1 && mkdir d2 && mount -t ext3 /dev/hdc1 /d1 && mount -t ext3
/dev/hdc2 /d2
All in one typing you created and mounted your new partitons. Your ready to copy! At this point we should run our mount command again
to verify our mounts. You should view similiar output:
/dev/hda2 on / type ext3 (rw)Note! This is all you should see! The command we will use to do the copying is simple in form, but effective in use. It is the cp command. There are other methods, but as far as I can tell,
there is nothing broken by using this command. In other words, this seems to work quite
nicely for a default RHLS. If up to this point you've followed with no problems, then
you should have further success! What I recommend is running the "clear"
command to get a clean screen and and do a simple "ls" command to get a
listing of your filesystem. Again, you should only see the top level of the filesystem,
something similar to this:
bin d1 dev home lib misc opt root tmp var
Now we copy! To begin, run these commands in the order they follow. After you type the command, I will indicate when to wait and to type again!
cp -a /boot/* /d1
Wait to finish copying. When at prompt, type:
cp -a /bin /d2
Wait to finish copying. When at prompt, type:
cp -a /dev /d2
Wait to finish copying. When at prompt, type:
cp -a /home /d2
Wait to finish copying. When at prompt, type:
cp -a /lib /d2
Wait to finish copying. When at prompt, type:
cp -a /misc /d2
Wait to finish copying. When at prompt, type:
cp -a /opt /d2
Wait to finish copying. When at prompt, type:
cp -a /root /d2
Wait to finish copying. When at prompt, type:
cp -a /tmp /d2
Wait to finish copying. When at prompt, type:
cp -a /var /d2
Wait to finish copying. When at prompt, type:
cp -a /etc /d2
Wait to finish copying. When at prompt, type:
cp -a /initrd /d2
Wait to finish copying. When at prompt, type:
cp -a /lost+found /d2
Wait to finish copying. When at prompt, type:
cp -a /mnt /d2
Wait to finish copying. When at prompt, type:
cp -a /proc /d2
Wait to finish copying. When at prompt, type:
cp -a /sbin /d2
Wait to finish copying. When at prompt, type:
cp -a /usr /d2
Wait to finish copying. When at prompt, type:
mkdir boot /d2
Now your done! If you noticed, we did not copy d1 &
d2. Because we were mounted to these points, and we would had
been only copying to ourselves. Good job if you have made it this far!
Now wrapping up!
THE BOOT LOADER With the latest greatest Red Hat distros, your probably got the GRUB boot loader to load your RHLS and or Windows. The next step is to get that boot loader installed back to your new drive. To do this, you will need to move to the /sbin directory. We will be using the
grub utility. When you start grub (by running
./grub), you'll see a possible message that it is checking
with the BIOS for drives...this may take a long time. Usually around 3-5
minutes or earlier, you'll be brought to this:
GRUB version 0.92 (640k lower/3072k upper
memory)hd0 (that is a zero) is the first hard drive. When you add a
number in front of the hd, then that would be the next hard
drive. In other words, hd0 is the Primary Master (first
drive). hd1 would be the Primary Slave. The reasons why I
have went to great length in explaining this, is because we are about to
have to tell GRUB where root is. In my working example, I
have a drive that is currently connected to the Secondary Master
(/dev/hdc). We will have to tell GRUB to install
the boot loader to the Master Boot Record and to make our current kernel
the booting operating system. You will need to issue this first command at
the grub command prompt:
root (hd2,0)
What we just done was tell GRUB that our booting RHLS is at
hard drive #3 plus the kernel is on the first partition. That is what the
zero was about. Please dont be confused here! This could be totally
different on your system, but if you should issue this command on the
wrong drive or partition and it is not a ext2fs type, then
you'll get a "filesystem type not recognized" message. If you
have been following this document to a "T", then you should be issuing the
same commands anyway. If you have successfully told GRUB
where your kernel is, you'll get this meassage:
Filesystem type is ext2fs, partition type 0x83
After completing this, we will now need to run the actual install of GRUB by issuing this command:setup (hd2)
After entering this you should and hopefully recieve this output:
Checking if "/boot/grub/stage1" exists... noWhen seeing this, you have come to the end of this task. Basically, what is left now is the testing to see if the system will boot. You'll have to remake your physical connections so that the drive you were copying to is the first drive. It is important to know that if you should leave both drives hooked together, you could experience some errors (non-destructive) about duplicate items. I suggest leaving the old drive out of the mix till you can know that the clone is error-free. Hopefully you'll be seeing the clone of what already exists. If you should have a problem, be sure that your labeling is correct. Again, this is very important! INFO I hope this document has helped you and if you should have questions or would like to share your success story with me, please drop me an email at nitrolinux@yahoo.com. Document created on 2-11-2003, by Jason L. Woodurff Some items corrected and updated on 8-4-2004 Back |
2004© jlwoodruff