LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-15-2004, 09:53 AM   #1
lfloridays
LQ Newbie
 
Registered: Jul 2004
Posts: 8

Rep: Reputation: 0
How to install in HD, and copy from old HD


I am a Linux Newbie (VERY NEW) and hope someone help me out. I have Linux OS on my server with a HD of 120 gig. I need to install a 250 Gig HD, copy all the files from the 120 GIG (OS and Data) and make the new HD the boot drive. Also - I need to eventually have the same name and partitions on the new drive.

Any help, info or a pointer to a document would be helpful. This server will be put back into production once I am done and don't want to make any mistakes!!! Thanks for your help!
 
Old 07-15-2004, 10:03 AM   #2
Quis
Member
 
Registered: May 2001
Location: Germany, Süd-Baden
Distribution: Gentoo
Posts: 139

Rep: Reputation: 15
you could try this with the dd (dsikdump) command:

eg. 120GB - /dev/hda, 250 GB - /dev/hdb

dd if=/dev/hda of=/dev/hdb.

this should copy the whole hdd to your new one.
 
Old 07-15-2004, 10:30 AM   #3
lfloridays
LQ Newbie
 
Registered: Jul 2004
Posts: 8

Original Poster
Rep: Reputation: 0
Thanks - I will use that command.

Do I need to mount that drive first and if so - is that just the mount command and drive name?

Once the copy is complete - how would I rename the

/dev/hdb drive to the /dev/hda drive and make that the boot drive?
 
Old 07-15-2004, 10:56 AM   #4
ppuru
Senior Member
 
Registered: Mar 2003
Location: Beautiful BC
Distribution: RedHat & clones, Slackware, SuSE, OpenBSD
Posts: 1,791

Rep: Reputation: 50
Quote:
dd if=/dev/hda of=/dev/hdb.
This will overwrite you second (new) disk with the contents of the first disk; including the partitions, partitiontable, MBR) - something like a replica of your first disk on your second. I am not sure whether you really want this.

If your new disk is your current primary disk, connect the old disk as a secondary (slave).

You can use the -p option with tar or cp to copy files while preserving the permissions.

Last edited by ppuru; 07-15-2004 at 11:08 AM.
 
Old 07-15-2004, 11:06 AM   #5
Quis
Member
 
Registered: May 2001
Location: Germany, Süd-Baden
Distribution: Gentoo
Posts: 139

Rep: Reputation: 15
Quote:
Originally posted by ppuru
This will overwrite you second (new) disk with the contents of the first disk; including the partitions, partitiontable, MBR) - something like a replica of your first disk on your second.
thats true. All data will be lost on the 240GB disk. The partitions will have exactly the same dimensions like the one of the smaller HDD, you might want to resize them with a tool like parted or Partition Magic.

You don't have to mount the devices for dd.
 
Old 07-15-2004, 11:33 AM   #6
lfloridays
LQ Newbie
 
Registered: Jul 2004
Posts: 8

Original Poster
Rep: Reputation: 0
Thank you for your responses....

I do want the 250GB drive to be overwritten with all of the 120GB contents. .... and I do want that 250GB drive to be the main drive. I may even take out the 120GB drive when I am done. I do want to make sure i don't lose data, partitions,......

I am a bit confused - would I use the dd or copy to move the data, keep persmissions, and keep the partitions?

And I think you said that if I install the drive - copy the data - then I do not have anything additional to mount the drive or make it the primary?
 
Old 07-15-2004, 11:35 AM   #7
ppuru
Senior Member
 
Registered: Mar 2003
Location: Beautiful BC
Distribution: RedHat & clones, Slackware, SuSE, OpenBSD
Posts: 1,791

Rep: Reputation: 50
dd would be quicker but the partition sizes will be the same as it was on your 120G disk. If I am not wrong, you would have 250G minus 120 G (130 G freespace) on your 250G disk. So if your purpose of moving to a 250G drive was to increase diskspace on your partitions, this solution may not be for you.

Last edited by ppuru; 07-15-2004 at 11:38 AM.
 
Old 07-15-2004, 12:11 PM   #8
lfloridays
LQ Newbie
 
Registered: Jul 2004
Posts: 8

Original Poster
Rep: Reputation: 0
Yes - the main reason I am putting in the newer harddrive is to increase space for my data - so I will need the extra space to be available.

Thanks again for all the replys!!!!
 
Old 07-15-2004, 01:39 PM   #9
ajmatson
LQ Newbie
 
Registered: Jun 2004
Location: AZ
Distribution: MEPIS 2003.10.2
Posts: 14

Rep: Reputation: 0
Partition Magic

DD everything like explained. Then use Partition Magic to resize the partitions to your desired amount or format the free space and use it as a separate storage partition.
 
Old 07-15-2004, 01:39 PM   #10
mjkmkk
LQ Newbie
 
Registered: Jun 2004
Posts: 3

Rep: Reputation: 0
Copy HD

Hey, I'm in a similar (not exact) boat to you. I have
a dual-boot system with two identical HD's. I NEVER
use the Win side, and the disk on the linux side is
starting to act flaky, so I want to move everything
from the linux disk (/dev/hdb) to the soon-to-be-empty
Win disk (/dev/hda). So the two questions I'm really
interested in are two you posed but haven't yet been
answered:

1. Does dd preserve dates/links/permissions, i.e. is
it an EXACT copy

2. Besides switching the master/slave cables, is there
a way to simply tell the system to boot off the new
disk (/dev/hda). I assume chaging lilo.conf is the simple
way. I'd just as soon not open the box and start
pulling/switching cables.
 
Old 07-15-2004, 03:49 PM   #11
lfloridays
LQ Newbie
 
Registered: Jul 2004
Posts: 8

Original Poster
Rep: Reputation: 0
Did you get an answer to your questions
1) Exact copy using dd
2)changing the lilo.conf instead of switching cables?

Thanks,
 
Old 07-15-2004, 06:11 PM   #12
mjkmkk
LQ Newbie
 
Registered: Jun 2004
Posts: 3

Rep: Reputation: 0
Nope, nothing yet..... since I posted my question on
your thread, I expect any response to show up on your
message list. I hope we get a response soon!
 
Old 07-16-2004, 12:15 AM   #13
ppuru
Senior Member
 
Registered: Mar 2003
Location: Beautiful BC
Distribution: RedHat & clones, Slackware, SuSE, OpenBSD
Posts: 1,791

Rep: Reputation: 50
2 threads intertwined

mjkmkk, dd simply copies whatever exists on the source to the destination. It wouldn't know about filesystems or permissions. Something like the ancient diskcopy command on DOS. So the perms will stay intact.

You will ned to boot into linux (perhaps on your hdb), make changes to lilo.conf, run lilo -t -v.
 
Old 07-16-2004, 04:35 AM   #14
osvaldomarques
Member
 
Registered: Jul 2004
Location: Rio de Janeiro - Brazil
Distribution: Conectiva 10 - Conectiva 8 - Slackware 9 - starting with LFS
Posts: 519

Rep: Reputation: 34
Hi gentlemen,
As you have your server working, I recommend a different approach. You don't need to stop your server until make sure you can jump to the new disk. I don't think dd is the correct tool for this.
I suggest we divide our process in three phases: preparation, copy and setup.
The tools you will need are "fdisk", "tar" and "rsync" and, of course, the proper filesystem tools for your file-systems and, last but not least lilo or grub.
In the first phase I recommend you install the new disk as "primary slave". In conditions I can't precisely specify, fdisk cannot recognize the "lba settings" of the disk, giving wrong partition sizes.
To specify what partitions you will need, enter
Code:
fdisk -l /dev/hda
. This will show you the partitions you have on the working disk. For example, this is my partition lay-out
Code:
Disk /dev/hda: 255 heads, 63 sectors, 9729 cylnders
Units = cylinders of 16065 * 512 bytes

Device     Boot    Start    End    Blocks   Id  System
/dev/hda1             1        33    265041   82  Linux swap
/dev/hda2   *        34        66    265072+  83  Linux
/dev/hda3            67       449   3076447+  83  Linux
/dev/hda4           450      9729  74541600    5  Estendida
/dev/hda5           450       832   3076416   83  Linux
/dev/hda6           833      1215   3076416   83  Linux
/dev/hda7          1216      1598   3076416   83  Linux
/dev/hda8          1599      2873  10241406   83  Linux
/dev/hda9          2874      4148  10241406   83  Linux
/dev/hda10         4149      5423  10241406   83  Linux
/dev/hda11         5424      6698  10241406   83  Linux
/dev/hda12         6699      7973  10241406   83  Linux
/dev/hda13         7974      8738   6144831   83  Linux
/dev/hda14         8739      9729   7960176   83  Linux
You must remember partitions 1 to 4 are primary partitions and the rest, 5 to 16 are secondary partitions. For you to have secondary partitions, one of the primaries has to be of "extended" type.
Based on this lay-out, you must enter
Code:
fdisk /dev/hdb
fdisk has a command help. All you have to enter is "m". The first command to use is "p" to see the partitions already defined. If there is any partition, delete it with "d". Now, use the command "n" to define the partitions you need. You have to follow the lay-out, but not the partition size. So, if a partition in the current disk has 1gB, you can put 2 or 5 or 20gB since it is the same partition. After specify the partition, if it is not a Linux type, use the commant "t" to specify the partition type.
You may create other partitions that you have not in the current system, but as an addition to the already existing ones. These will be set up after the disk change.
After the specifications I recommend you activate the boot partition with the command "a" because some bios refuse to boot if they doesn't find an active partition. The linux doesn't need it.
Now, write the partition layout to the disk with the command "w".
Now we need to format the partitions. If you have swap partition, you have to
Code:
mkswap /dev/hdbX
. /dev/hdbX is the partition you specified in fdisk for swap.
If your partitions are ext2 or ext3, all you need is mke2fs and if it is ext3 you may want to use tune2fs also. If you have other type of partitions, you will need to use the correct tools to initialize your filesystems. If you have other type of partitions, your system has the tools you need. Sorry I can't help with it, because I allways used just ext2 and ext3.
Ok, for the ext2 you have to enter
Code:
mke2fs /dev/hdbX
for each partition you specified, where X is the partition number, except for the swap and extended partition. For the ext3 partitions you have to enter
Code:
mke2fs -j /dev/hdbX
tune2fs -c0 -i0 /dev/hdbX
If you have another type of partition, use the proper initialize command instead of mke2fs for each partition you have.
Now that we finished the preparation phase. I suggest you to halt the machine and install the new disk as "secondary master". This will speed up the copies because the source and destination disk will be in differente ide controllers. If you have the cdrom on the secondary ide as master, then install the new disk as "secondary slave".
Now we need to mount the new disk. First we need to create a mount point to the new root.
Code:
mkdir /mnt/new
Now we need to see how the actual system is mounted. With the command "df -v" we can see it
Code:
Opiii:~# df -v
Filesystem           1k-blocks      Used Available Use% Mounted on
/dev/hda7              3028080   2454212    420048  86% /
/dev/hda2               256665     16254    227158   7% /boot
/dev/hda13             6048320   4069656   1671424  71% /d
/dev/hda11            10080488   8226272   1342148  86% /e
/dev/hda8             10080488   7161564   2406856  75% /f
/dev/hda9             10080488   9001784    566636  95% /a
/dev/hda10            10080488   8702052    866368  91% /b
/dev/hda12            10080488   9278916    289504  97% /s
We need to follow the mounting lay-out. For each filesystem (at the left) we have the mount point at the right, start with the "/" which is the root filesystem. Following my example, first we must mount the new root partition on "/mnt/new", then create the directories for the other mount points and then, mount the corresponding filesystems in this directories. So, for each /dev/hdaX, mounted in directory /Y, we will mount /dev/hdbX(or /dev/hdcX or /dev/hddX) in the directory /mnt/new/Y. Remember, /dev/hda corresponds to primary master ide, /dev/hdb to primary slave, /dev/hdc to secondary master and /dev/hdd to secondary slave. Lets follow this example, assuming that we install the new disk as secondary master (/dev/hdc):[code]
mount /dev/hdc7 /mnt/new
cd /mnt/new
mkdir boot d e f a b s
cd
mount /dev/hdc2 /mnt/new/boot
mount /dev/hdc13 /mnt/new/d
mount /dev/hdc11 /mnt/new/e
mount /dev/hdc8 /mnt/new/f
mount /dev/hdc9 /mnt/new/a
mount /dev/
hdc10 /mnt/new/b
mount /dev/hdc12 /mnt/new/s

Now, you may enter "df -v" again to see the mounted filesystems. You can check if there are no mistakes. If any filesystem is mounted in an incorrect mount point, you can use umount to unmount it and mount again in the proper directory.
Now it's time to copy the filesystems. There are many ways to do it, but I prefer "tar" to copy huge amounts of data. In reality, we will use two instances of tar, one to archive the source filesystem and the other to extract the data on the fly to the new file system.
Code:
(cd <source-file-system>; tar c --one-file-system .)|(cd <destination-file-system>; tar xv)
for each file system we want/need to copy. We start 2 sub-shells (the parenthesis means "start a sub-shell). In the first, we enter cd to the mount point of the old disk and after (the ";" means enter) we start a tar archival creation for just the file system we gave "cd" and tell it to archive this directory ("."); We pipe the resulting archive to a second sub-shell, where, first we "cd" to the new filesystem mount point and after we start a tar to extract the archive. The files will bring all the permissions, timestamp and ownership of the original.
We cannot forget that during this time, the system is being used and modified by your clients. All we want for now is to copy the bulk data. Depending on your data, this will take a long while. We have to repeat this command for each filesystem to be copied, starting with the "root".
We can semi-automate this copy this way;
Code:
for FS in / /boot /d /e /f /a /b /s
do
  (cd $FS;tar c --one-file-system .)|(cd /mnt/new/$FS;tar xv)
done
This ends the part of this phase which your users can share the system. Now you have to enter single user mode to update the changes the system has during the time the copy lasted.
You have to alert your users to close their sessions and block access from users. If you have databases, shut it down, if you have Xwindow, enter "init 3" to shut it down and if you have terminal login users enter "touch /etc/nologin" to block new logins. After assure no one user is working, we will use rsync to update the filesystems. now we will enter
Code:
for FS in / /boot /d /e /f /a /b /s
do
  (cd $FS;rsync -av --one-file-system . /mnt/new/$FS)
done
rsync will copy only the files which were changed after the tar copy.

Now the copy phase is finished. We need to know if your system boot loader is lilo or grub. We need different procedures for each boot loader. If your distribution use grub, we need to install grub now, before reboot. You will enter "grub"
You will receive the "grub prompt"
Code:
grub> root hd(1,X)
grub> find /boot/grub/stage1
    (hd0,6)
    (hd1,6)
grub> setup (hd1)
     ....
     ....
grub> quit
It's done.
If you have lilo, I don't know a way to set up boot without other boot disk, (cd or floppy). To do this, you need to keep on hand the device of the root partition, in our example, /dev/hda7.
Now, you turn your computer off, install the new disk as "primary master" if you have lilo, get the distribution cd or the "boot disk" to boot from it. When the system boots, at the lilo: prompt, you will enter "linux ro root=/dev/hdaX", in our example "linux ro root=/dev/hda7". When the login prompt appears, login as root and enter "lilo". This will install lilo in the new disk.
If you have grub, you will boot direct, with no more intervention.

In both cases, if you entered "touch /etc/nologin", now you have to remove it, entering "rm /etc/nologin".
The exception to this procedure is if you have dos/windows partitions on your disk. I recommend you use another machine which has dos/windows to create and format the dos/windows partitions before enter in the preparation phase, always reproducing the lay-out given by the current disk.

Hope it does help!
 
Old 07-16-2004, 08:51 AM   #15
lfloridays
LQ Newbie
 
Registered: Jul 2004
Posts: 8

Original Poster
Rep: Reputation: 0
Thanks - this does help - I will go through to see if I have questions
but thanks for such a detailed reply
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy an entire install to second harddisk seriesx4 Linux - General 7 10-13-2005 12:44 PM
Copy install disc's to hard-drive peter64 Mandriva 6 09-01-2004 04:15 PM
RPM Question : Copy but not install : how to shankariyer Linux - General 7 02-16-2004 02:02 PM
copy files of cd post-install? tuppe Red Hat 2 12-05-2003 12:27 PM
Install doesn't copy the files fdiskgreg Slackware 5 03-04-2003 12:58 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration