Mirroring is a technology used by many corporations and home users to back up data without interruption. When a mirror exists, it simply means that diskB replicates diskA. Or, perhaps diskC+D replicates diskA+B. Regardless of the disk configuration, the important aspect is that information on one disk or partition is being replicated. Later, that information could be more easily restored, backed up without causing service or access interruption, and even be physically stored in a data safe.
To begin, ensure the system has two disk drives of equal size, this exercise assumes they are direct access (da(4)) SCSI disks.
Begin by installing FreeBSD on the first disk with only two partitions. One should be a swap partition, double the RAM size and all remaining space devoted to the root (/) file system. It is possible to have separate partitions for other mount points; however, this will increase the difficulty level ten fold due to manual alteration of the bsdlabel(8) and fdisk(8) settings.
Reboot and wait for the system to fully initialize. Once this process has completed, log in as the root user.
Create the /dev/mirror/gm device and link it with /dev/da1:
# gmirror label -vnb round-robin gm0 /dev/da1
The system should respond with:
Metadata value stored on /dev/da1. Done.
Initialize GEOM, this will load the /boot/kernel/geom_mirror.ko kernel module:
# gmirror load
Notatka: This command should have created the gm0, device node under the /dev/mirror directory.
Install a generic fdisk label and boot code to newly created gm0 device:
# fdisk -vBI /dev/mirror/gm0
Now install generic bsdlabel information:
# bsdlabel -wB /dev/mirror/gm0s1
Notatka: If multiple slices and partitions exist, the flags for the previous two commands will require alteration. They must match the slice and partition size of the other disk.
Use the newfs(8) utility to create a default file system on the gm0s1a device node:
# newfs -U /dev/mirror/gm0s1a
This should have caused the system to spit out some information and a bunch of numbers. This is good. Examine the screen for any error messages and mount the device to the /mnt mount point:
# mount /dev/mirror/gm0s1a /mnt
Now move all data from the boot disk over to this new file system. This example uses the dump(8) and restore(8) commands; however, dd(1) would also work with this scenario.
# dump -L -0 -f- / |(cd /mnt && restore -r -v -f-)
This must be done for each file system. Simply place the appropriate file system in the correct location when running the aforementioned command.
Now edit the replicated /mnt/etc/fstab file and remove or comment out the swap file [1]. Change the other file system information to use the new disk. See the following example:
# Device Mountpoint FStype Options Dump Pass# #/dev/da0s2b none swap sw 0 0 /dev/mirror/gm0s1a / ufs rw 1 1
Now create a boot.conf file on both the current and new root partitions. This file will “help” the system BIOS boot the correct drive:
# echo "1:da(1,a)/boot/loader" > /boot.config
# echo "1:da(1,a)/boot/loader" > /mnt/boot.config
Notatka: We have placed it on both root partitions to ensure proper boot up. If for some reason the system cannot read from the new root partition, a failsafe is available.
Now add the following line to the new /boot/loader.conf:
# echo 'geom_mirror_load="YES"' >> /mnt/boot/loader.conf
This will instruct loader(8) utility to load the geom_mirror.ko module during system initialization.
Reboot the system:
# shutdown -r now
If all has gone well, the system should have booted from the gm0s1a device and a login prompt should be waiting. If something went wrong, see review the forthcoming troubleshooting section. Now add the da0 disk to gm0 device:
# gmirror configure -a gm0 # gmirror insert gm0 /dev/da0
The -a
flag tells gmirror(8) to use
automatic synchronization; i.e., mirror the disk writes automatically. The manual page
explains how to rebuild and replace disks, although it uses data in place of gm0.
If the system boots up to a prompt similar to:
ffs_mountroot: can't find rootvp Root mount failed: 6 mountroot>
Reboot the machine using the power or reset button. At the boot menu, select option six (6). This will drop the system to a loader(8) prompt. Load the kernel module manually:
OK? load geom_mirror.ko OK? boot
If this works then for whatever reason the module was not being loaded properly. Place:
options GEOM_MIRROR
in the kernel configuration file, rebuild and reinstall. That should remedy this issue.
[1] |
It should be noted that commenting out the swap file entry in fstab will most likely require you to re-establish a different way of enabling swap space. Please refer to Sekcja 11.14 for more information. |
Poprzedni | Spis treści | Następny |
RAID0 - Striping | Początek rozdziału | GEOM Gate Network Devices |
Ten i inne dokumenty można pobrać z ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/.
W przypadku pytań o FreeBSD prosimy przeczytać dostępną dokumentację przed kontaktem z <questions@FreeBSD.org>.
W sprawie zapytań o tę dokumentację prosimy o kontakt z <doc@FreeBSD.org>.