FreeBSD Data Transfer Method


1. Shut down, install the new hard disk and restart it.

2. Check if the system has identified a new hard disk after booting: hpserver dmesg grep ad2 will display ad2: 9765MB if it succeeds[19841/16/63] at ata1-master UDMA33 and other information, otherwise you need to check whether there is a wrong connection or hardware compatibility.

The new hard disk has been installed successfully. Here are two methods of data migration.

1. Adding a hard disk to transfer the original hard disk/var data to the new hard disk

After the system has been established, FreeBSD can not adjust partition space freely like PQMagic without destroying partition data, so if / var space is not enough, it needs to add a hard disk to increase space, and the original data must be migrated.

2. Partitioning the new hard disk

You can use sysinstall or the command line to partition. Although fdisk has more flexibility, I recommend sysinstall. After partitioning, we use Label in sysinstall to build file system-related file system.

3. There are two ways to mount the file system to / MNT hpserver mount / dev / ad1s1e / MNT 4 and migrate the data. One is to use tar, the other is to use dump.

(1) Use tar to backup and restore data.

hpserver# cd /var
hpserver# tar cf – * | (cd /mnt; tar xf -)

(2) Use dump backup and restore data. Personally, I recommend this method because I tried to use tar to backup var directory, when there was an error and stopped automatically. I analyzed the reasons why some files or temporary files in use might not be backed up, but dump is not a file unit, but a block unit, there should be no such situation, so this is my recommendation. Reasons for using dump and restore.

hpserver# cd /mnt
hpserver# dump -f- /var | restore -f- -r

During and at the end of the process, information similar to the following will appear:

DUMP: Date of this level 0 dump: Wed Jan 14 23:44:35 2004
DUMP: Date of last level 0 dump: the epoch
DUMP: Dumping /dev/ad0s1e (/var) to standard output
DUMP: mapping (Pass I) [regular files]
DUMP: mapping (Pass II) [directories]
DUMP: estimated 305 tape blocks.
DUMP: dumping (Pass III) [directories]
DUMP: dumping (Pass IV) [regular files]
DUMP: DUMP: 361 tape blocks
DUMP: finished in less than a second

5. One caveat is that you need to make sure that no data is written to the original / var after backup, otherwise, the data is not backed up to the new partition. After that, don’t forget to check the results and uninstall / mnt.

hpserver# ls /mnt
hpserver# umount /mnt

6. Edit the / etc / fstab file and change the original file system pointing to / VAR to / dev / ad1s1e. Restart will take effect.

2. Hard Disk Replication

If there is something wrong with the old system disk, or the capacity is not enough, you want to replace a new hard disk, then you can copy the old hard disk data to the new hard disk, and then remove the old hard disk. Following the steps above, we assume that the hard disk has been installed.

Here’s a small tips, which is to first record the mount point corresponding to the old hard disk file system. The new hard disk partition order is the same as the old one, so that we can avoid the confusing steps below. Let’s look at the / etc / fstab comparison. Otherwise, I forgot that ad2s1e is used to mount that directory after all.

1. Use sysinstall to partition the new hard disk, set up the MBR, and create the file system one by one according to the original order. Assuming that the original file system / dev / ad0s1g corresponds to / usr, then your new hard disk / dev / ad2s1g corresponds to / usr, and the original file system / dev / ad0s1e corresponds to / var, then your new hard disk / dev / ad2s1e corresponds to / var. Clear the mount points of all file systems by M, because we have not yet established a temporary mount directory, and it is not clear that the mount conflicts with the original mount of the system.

2. Create temporary directories to serve as temporary mount points and mount these file systems.

hpserver# cd /mnt
hpserver# mkdir root
hpserver# mkdir usr
hpserver# mkdir var

Using cat/etc/fstab to see the corresponding relationship of the original file system, we just need to look at the last letter, so as to avoid us forgetting what corresponds to what, which is why I just made the name of the new hard disk file system correspond to the previous reason.

hpserver# mount /dev/ad2s1a /mnt/root
hpserver# mount /dev/ad2s1g /mnt/usr
hpserver# mount /dev/ad2s1e /mnt/var

3. Dump is the best way to duplicate hard disk, and tar is not used as much as possible, because when you backup the root partition, if you do not exclude some directories with parameters, it will backup everything to your new partition, which is certainly not what we want to see.

hpserver# cd /mnt/root
hpserver# dump -f- / | restore -f- -r
hpserver# cd /mnt/var
hpserver# dump -f- /var | restore -f- -r
hpserver# cd /mnt/usr
hpserver# dump -f- /usr | restore -f- -r

4. Up to now, the data backup and restore have been completed. Check if there are any errors and omissions, and then separately umount these partitions.

hpserver# umount /mnt/root
hpserver# umount /mnt/usr
hpserver# umount /mnt/var

5. Finally, shut down the computer, remove the original hard disk, and hang the new hard disk to the original position of the old hard disk. This step should not be omitted. If you do not change the location, the system still thinks the new hard disk is ad2. Because your / etc / fstab contains the corresponding ad0, the file systems such as / usr and / var will not be found in startup. Start and see if there are no exceptions. Congratulations. Data migration has been successful. Otherwise, please see what errors have been made or what steps have been forgotten. Anyway, don’t be so anxious to empty the contents of the old hard disk. It’s better to let the new system run for a few days to observe any anomalies before you start.

Keep in mind that data migration is a relatively dangerous thing, there should be no errors in the operation process, otherwise it may lead to the loss of your original data, so you must be very cautious.