CRM Hosting


Add to Technorati Favorites

Software mirror in FreeBSD

If you want to make a low-cost server with a RAID capabilities and don’t want to invest in a hardware RAID solution, gmirror is a good choice. You can use it to add a disk and create a mirror even on your existing server running FreeBSD 6 or 7.

In my example I have at start an 8 GB hard disk where I installed FreeBSD 7 (/dev/ad0).

existing_disk.png

The first thing to do is to add another hard disk with the same size (or bigger than the existing one) and boot the OS.

Now you have to create the mirror. For this you can use:

gmirror label -v -b round-robin gm0 /dev/ad0

If /dev/ad0 is the disk where the OS is installed (like in our example) then you will get an error because you are not allowed to write the metadata on a disk mounted for write. To solve this you must use sysctl:

sysctl kern.geom.debugflags=16


Now re-run the gmirror command and you will have the mirror created.


metadata.png

Next thing to do is to tell FreeBSD to load automatically the gmirror module at startup. Open /boot/loader.conf with your favorite editor and add this line:

geom_mirror_load="YES"

Now you have to modify /etc/fstab so at the next reboot the file systems will be mounted from the mirror, not from /dev/ad0

fstab_old.pngfstab_new.png

Now you are ready to reboot the computer. Be sure you don’t have any typo in fstab or you computer will not boot.
If everything is OK, after the restart, you will have an operating system booted from the mirror. Now it’s time to add the second disk to the RAID array:

gmirror insert gm0 /dev/ad1

where /dev/ad1 is the second hard disk in the computer. At this moment the computer starts rebuilding the array. Depending an your disks size and speed it can take from half an hour to few hours.

disk2_added.png

You can check the status of the mirror using:

gmirror status

Until the synchronization is complete, the status of the mirror will be degraded. After this step is complete, the mirror status will be complete

gmirror_status.png

When the mirror status is COMPLETE you will have a fully functional mirror for your server.

If one of your disks will ever fail, all you have to do is to remove it from the mirror using

gmirror forget gm0 /dev/adX

where /dev/adX is the failing hard disk.
After that, power off the server, change the defective hard disk and after the system boots, just insert the new disk into the mirror:

gmirror insert gm0 /dev/adX

and the mirror will be resynchronized.


You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

AddThis Social Bookmark Button
Comments are DoFollow, so you may consider writing a small note :)

5 Responses to “Software mirror in FreeBSD”

  1. You made it look simple to do. I wanted to do this but I was affraid of losing data.

  2. Your blog is interesting!

    Keep up the good work!

  3. Hay,I like your posting friend and i would like to link exchange with your blog if you want.this is my blog Car Body Kit And also dont forget to come.i will happy if you come .Good bye friend

  4. How come you are moderating my comments?

  5. Hi. I go through a few of one’s other posts and wished to understand in the event you would be interested in exchanging blogroll links?

Leave a Reply



BRDTracker