The OpenNET Project / Index page

[ новости /+++ | форум | wiki | теги | ]

Поиск:  Каталог документации

7. Copy the files from the old disk to the new disk

You might want to go to single-user mode before starting to copy the disk, in order to shut down the system daemons and preserve the state of the logs, and to prevent users from logging in:
/sbin/telinit 1

When copying the hard disk, you want to copy all directories and files, including links.

However, you don't want to copy the directory /new-disk, since this would copy the new disk to itself!

Furthermore, you want to create the /proc directory on the new disk, but you don't want to copy its contents: /proc is a virtual file system and doesn't have any actual files, but rather contains information on the processes running on the system.

Here are three different ways to copy the old disk to the new one. This may take quite a while, especially if you have a large disk or little memory. You can expect to be able to copy 10 Mb per minute, and possibly much more.

You can follow the copy's progress by using the command df from another terminal. Try watch df or watch ls -l /new-disk to see a report updated every two seconds; press Ctrl-C to end the display. Be aware that running the watch program itself will slow down the copying.

cp -ax / /new-disk

This is the simplest method, but will only work if your original Linux system is on a single disk partition.

The -a option preserves the original system as much as possible. The -x option limits cp to a single file system; this is necessary to avoid copying the /new-disk and /proc directories.

SuSE only. With this method only, you must also create the directory /dev/pts on the new disk. Use the command mkdir /new-disk/dev/pts".

Note: When using the -x option, recent versions of cp will create the directories /new-disk/new-disk and /new-disk/proc, although the directories will be empty. If these directories are created, you should delete /new-disk/new-disk, and keep /new-disk/proc.

cd / && echo cp -a `/bin/ls -1Ab | egrep -v "^new-disk$|^proc$"` /new-disk | sh

(write this all on one line)

This goes to the root directory and then copies all files and directories except /new-disk and /proc to /new-disk. Note that the first option after ls is the number 1, not the letter L!

This command should work in all circumstances.

cp -a /bin /boot /dev /etc /home /lib /lost+found /mnt /root /sbin /tmp /usr /var /new-disk

(write this all on one line)

The last directory, /new-disk, is the destination for the cp command. All the other directories are the sources. Therefore, we're copying all the directories we're listing to /new-disk.

With this method, you simply list yourself the directories you want to copy. Here we listed all the directories except /new-disk and /proc. If you can't use the other methods for any reason, you can always use this command to manually specify the directories you want to copy.

With this method only, if there are any files in the root directory itself, you need another command to copy them. In particular, this is required with Debian and Slackware, since these distributions put files in the root directory:
cp -dp /* /.* /new-disk

Previous versions of the Mini How-To stated that you could also use tar to copy the disk, but this method was found to have a bug. There are of course many other ways to copy the disks, but these three are the simplest, quickest, and most reliable.

After using any of these three methods, you must also create the /proc directory on the new disk, if it doesn't already exist:
mkdir /new-disk/proc

At this point, you may verify the file structure on the new disk, if you wish:
umount /new-disk
fsck.ext2 -f /dev/hdb1
mount -t ext2 /dev/hdb1 /new-disk

If the new disk has more than one partition, you must unmount them from the bottom up before running fsck.ext2: in the example mentioned above, you'd first unmount the 3rd level partitions, then the 2nd level partitions, and then the 1st level partition.

You may also compare the two disks, to ensure that the files were copied properly:
find / -path /proc -prune -o -path /new-disk -prune -o -xtype f -exec cmp {} /new-disk{} \;

(write this all on one line)

Slackware only. A basic Slackware installation ("A" series only) doesn't include the cmp command, so you won't be able to run this command if you have only installed the basic files. The cmp command is in the "AP1" series.)

This will only compare regular files, not character or block special files (in the /dev directory), sockets, etc., since the cmp command doesn't work properly with these. We would welcome suggestions on how to verify these "special" files.

Inferno Solutions
Hosting by

Закладки на сайте
Проследить за страницей
Created 1996-2022 by Maxim Chirkov
Добавить, Поддержать, Вебмастеру