Software RAID1 on FreeBSD
Introduction:
This article describes how to setup a software RAID1 (Mirrored) array of two disks (not partitions)
using gmirror on FreeBSD. It can be used with identical or dissimilar disks and can be used for the
root partition (that's exactly what this example shows) to create a bootable software RAID1 array.
It is written specifically for the operating system version shown below but will probably work on
later versions with little deviation.
Software:
Operating System: | FreeBSD 6.1 for i386 | Download |
Before you begin:
-
You should already have the operating installed and working on your "first" disk.
Booting into the "Fixit" Repair Mode shell:
-
Reboot your computer from the FreeBSD 6.1 CD 1 and wait for the sysinstall main menu.
-
Select the Fixit option from the main menu.
-
Select the CDROM/DVD option. You will then be in the Fixit shell.
-
Change the root of the file system to /dist by entering the command:
-
Mount the device file system on /dev by entering the command:
-
Load gmirror by entering the command:
Creating the mirrored array
-
Setup the array by labelling the disk that currently contains the data you want to protect (your master, if you like) by entering the command:
gmirror label -v -b round-robin gm0 /dev/ad0
|
In the command above you have setup a mirror with round-robin load balancing called gm0 from the hard disk /dev/ad0 (In this case this is the primary
master IDE device. If you have Serial ATA or SCSI disks your device names are almost certainly different. If you are not sure of your disk's device
name You can see a list of disks on your system by typing the following command for IDE & Serial ATA devices:
And this command for SCSI disks:
If those names don't jog your memory you can remind yourself by rebooting your computer back into the operating system on the disk and open the file
/etc/fstab with a text editor. Search for a line with the mountpoint / the device name will be displayed on the same line as per the example below:
# Device Mountpoint FStype Options Dump Pass#
/dev/ad0s1b none swap sw 0 0
/dev/ad0s1a / ufs rw 1 1
/dev/acd0 /cdrom cd9660 ro,noauto 0 0
|
As you can see here the disk with the root (/) file system is /dev/ad0.
Once the data has been written to the first disk you will get a response similar to the one below:
Metadata value stored on /dev/ad0
Done.
|
-
Now add the second disk to the array by entering the command:
gmirror insert gm0 /dev/ad1
|
Again, in this example I have used /dev/ad1, the primary slave IDE device. You should substitute your own device name if your second disk is on a
different channel or interface type.
The mirror will begin to synchronise immediatley but you can use it right away and even reboot without having to wait for it to complete.
Configuration changes for normal use
-
Mount the root partition on your mirror on /mnt by entering the command:
mount /dev/mirror/gm0s1a /mnt
|
-
Change the root of the file system to /mnt by entering the command:
-
Ensure gmirror is loaded at boot by entering the command:
echo 'geom_mirror_load="YES"' >> /boot/loader.conf
|
-
Make sure your mirrored array is mounted at boot instead of your original first disk by editing /etc/fstab with your favourite text editor.
Replace all occurences of your "first" disk device name with gm0. For example, my original fstab looked like this:
# Device Mountpoint FStype Options Dump Pass#
/dev/ad0s1b none swap sw 0 0
/dev/ad0s1a / ufs rw 1 1
/dev/acd0 /cdrom cd9660 ro,noauto 0 0
|
I changed all the occurences of ad0 to mirror/gm0 so the table now reads:
# Device Mountpoint FStype Options Dump Pass#
/dev/mirror/gm0s1b none swap sw 0 0
/dev/mirror/gm0s1a / ufs rw 1 1
/dev/acd0 /cdrom cd9660 ro,noauto 0 0
|
And you're done! You can now reboot your computer by typing:
at the command line and allowing the operating system to load from your mirror. Remember to take the FreeBSD CD out!
Monitoring the array
-
You can keep an eye on the status of the array by typing the command:
You will get a response similar to:
Name Status Components
mirror/gm0 COMPLETE ad0
ad1
|
You can also get more in depth information by typing:
and you will get a response like this:
Geom name: gm0
State: COMPLETE
Components: 2
Balance: round-robin
Slice: 4096
Flags: NONE
GenID: 0
SyncID: 1
ID: 2044043084
Providers:
1. Name: mirror/gm0
Mediasize: 81964301824 (76G)
Sectorsize: 512
Mode: r2w2e2
Consumers:
1. Name: ad0
Mediasize: 81964302336 (76G)
Sectorsize: 512
Mode: r1w1e1
State: ACTIVE
Priority: 0
Flags: NONE
GenID: 0
SyncID: 1
ID: 3387661378
2. Name: ad1
Mediasize: 122942324736 (114G)
Sectorsize: 512
Mode: r1w1e1
State: ACTIVE
Priority: 0
Flags: NONE
GenID: 0
SyncID: 1
ID: 2251528811
|
Addendum
-
Document Version: 1.2.0
-
Changes:
-
References:
- dannyman.toldme.com - this guide was based
on the original instructions found at dannyman.toldme.com
|