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
. 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
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
. /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
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.
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!