Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

19.4 RAID1 - Mirroring

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

Note: This command should have created the gm0, device node under the /dev/mirror directory.

Install a generic fdisk label and boot code to new gm0 device:

# fdisk -vBI /dev/mirror/gm0

Now install generic bsdlabel information:

# bsdlabel -wB /dev/mirror/gm0s1

Note: 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 construct a default UFS 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 as shown in the following example:

# Device                Mountpoint      FStype  Options         Dump    Pass#
#/dev/da0s2b             none            swap    sw              0       0
/dev/mirror/gm0s1a       /               ufs     rw              1       1

Ensure the geom_mirror.ko module will load on boot by running the following command:

# echo 'geom_mirror_load="YES"' >> /mnt/boot/loader.conf
# echo 'geom_mirror_load="YES"' >> /boot/loader.conf

Reboot the system:

# shutdown -r now

At the boot screen, select option four (4) to gain access to single user mode. At the console, ensure that the system booted from the gm0s1a. This can be done by viewing the output from df(1).

If all has gone well, the system should have booted from the gm0s1a device. From here, the primary disk may be cleared and inserted into the mirror using the following commands:

# dd if=/dev/zero of=/dev/da0 bs=512 count=79
# 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.

As the mirror is built the status may be checked using the following command:

# gmirror status

19.4.1 Troubleshooting

19.4.1.1 System refuses to boot

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

Notes

[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 Section 11.14 for more information.


 
 
  Published under the terms of the FreeBSD Document Project