Avenging Angel

Software RAID1 on FreeBSD

  1. Introduction:

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

  3. Software:

  4. Operating System:FreeBSD 6.1 for i386Download

  5. Before you begin:

    1. You should already have the operating installed and working on your "first" disk.
  6. Booting into the "Fixit" Repair Mode shell:

    1. Reboot your computer from the FreeBSD 6.1 CD 1 and wait for the sysinstall main menu.
    2. Select the Fixit option from the main menu.
    3. Select the CDROM/DVD option. You will then be in the Fixit shell.
    4. Change the root of the file system to /dist by entering the command:
      chroot /dist
      
    5. Mount the device file system on /dev by entering the command:
      mount_devfs devfs /dev
      
    6. Load gmirror by entering the command:
      gmirror load
      
  7. Creating the mirrored array

    1. 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:
      ls /dev/ad*
      
      And this command for SCSI disks:
      ls /dev/da*
      
      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.
      
    2. 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.
  8. Configuration changes for normal use

    1. Mount the root partition on your mirror on /mnt by entering the command:
      mount /dev/mirror/gm0s1a /mnt
      
    2. Change the root of the file system to /mnt by entering the command:
      chroot /mnt
      
    3. Ensure gmirror is loaded at boot by entering the command:
      echo 'geom_mirror_load="YES"' >> /boot/loader.conf
      
    4. 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:
      reboot
      
      at the command line and allowing the operating system to load from your mirror. Remember to take the FreeBSD CD out!
  9. Monitoring the array

    1. You can keep an eye on the status of the array by typing the command:
      gmirror status
      
      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:
      gmirror list
      
      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
      
  10. Addendum

    1. Document Version: 1.2.0
    2. Changes:
      • 1.2.0
        • Updated for FreeBSD 6.1
      • 1.1.0
        • Updated for FreeBSD 6.0
    3. References:
      • dannyman.toldme.com - this guide was based on the original instructions found at dannyman.toldme.com