# How to install FreeBSD 9.x using RAID 1 and BSD labels



## fugglefeet (Jan 8, 2014)

How to install FreeBSD 9.x using RAID 1 and BSD labels from scratch.

Hopefully the information presented here will be able to assist with the installing of FreeBSD using the above configuration. The beginning point requires a copy of the latest release version of FreeBSD (in this case 9.2). Start the installer as normal and follow the prompts until the partitioning screen appears. At this point, choose Shell (as seen on the screenshot below).



At the prompt screen, the existing partitions and metadata relating to previous disk mirroring needs to be deleted:


```
# gpart destroy -F ada0

# gpart destroy -F ada1
```

Now that the partitions on both disks are destroyed, confirm that any mirror metadata is also deleted:


```
# gmirror clear ada0

# gmirror clear ada1
```

The gmirror application may baulk at this point and display an error message. If this is the case, then there is no mirror metadata that needs to be deleted. Now the mirror with the two new disks needs to be created. Firstly, gmirror is loaded into memory to achieve the RAID 1 array:


```
# gmirror load
```

Once the gmirror application is fired up, it’s time to add the two drives to the mirror array:


```
# gmirror label -v gm0 /dev/ada0 /dev/ada1
```

Now the mirror is created and the mirror drive needs to be partitioned for it to boot and provide redundancy. MBR and BSD label partition tables can now be created on the mirror drive. This is achieved by issuing the following commands:


```
# gpart create -s MBR mirror/gm0

# gpart add -t freebsd -a 4k mirror/gm0
```

With the MBR partition table created, it’s now time to create the BSD label partition tables that will be used by the system. The sizes for the various partitions that will be created are based on the following guidelines:

/        4 to 8 times the installed system memory.
swap     2 to 4 times the installed system memory.
/var     4 to 8 times the installed system meomry.
/tmp     2 to 4 times the installed system memory.
/usr     the balance of the free hard disk space.

Remember that these are guidelines and NOT rules. Now comes the creation of the BSD label partition table and that is done by executing the following at the command prompt:


```
# gpart create -s BSD mirror/gm0s1
# gpart add -t freebsd-ufs  -a 4k -s 4g mirror/gm0s1
# gpart add -t freebsd-swap  -a 4k -s 2g mirror/gm0s1
# gpart add -t freebsd-ufs  -a 4k -s 4g mirror/gm0s1
# gpart add -t freebsd-ufs  -a 4k -s 2g mirror/gm0s1
# gpart add -t freebsd-ufs  -a 4k mirror/gm0s1
```

The partitions have been created on the mirror drive. The mirror drive is made bootable by installing the bootcode in the MBR, setting it as the active slice and installing the bootcode in the BSD label:


```
# gpart bootcode -b /boot/mbr mirror/gm0
# gpart set -a active -i 1 mirror/gm0
# gpart bootcode -b /boot/boot mirror/gm0s1
```

The filesystems on the mirror need to be formatted (with soft updates enabled):


```
# newfs -U /dev/mirror/gm0s1a
# newfs -U /dev/mirror/gm0s1d
# newfs -U /dev/mirror/gm0s1e
# newfs -U /dev/mirror/gm0s1f
```

Now that the various partitions have been formatted, the partitions need to be mounted prior to FreeBSD being installed on the mirror drive. But first the necessary directories need to be made in the /mnt directory, for the partitions to be mounted and finally the /etc/fstab file is created that the system will use to boot with:


```
# mount /dev/mirror/gm0s1a /mnt

# mkdir /mnt/var
# mkdir /mnt/tmp
# mkdir /mnt/usr

# mount /dev/mirror/gm0s1d /mnt/var
# mount /dev/mirror/gm0s1e /mnt/tmp
# mount /dev/mirror/gm0s1f /mnt/usr
```

Now the /etc/fstab file is created using the following information below:


```
# vi /tmp/bsdinstall_etc/fstab

#Device                        Mountpoint        FStype        Options        Dump        Pass#
/dev/mirror/gm0s1a             /                 ufs           rw             1           1
/dev/mirror/gm0s1b             none              swap          sw             0           0
/dev/mirror/gm0s1d             /var              ufs	        rw             2           2
/dev/mirror/gm0s1e             /tmp              ufs	        rw	          2           2
/dev/mirror/gm0s1f             /usr              ufs	        rw	          2           2
```

The necessary directories have been created and the relevant partitions have been mounted for FreeBSD to be installed on the mirror drive. With this done, now it’s time to install FreeBSD:-


```
# exit
```

Continue with the rest of the installer until the following screen appears:



At this point select Yes and the installer will drop into shell mode where the last tweaks are done to the system to boot from the mirror drive:


```
# echo 'geom_mirror_load="YES"' >> /boot/loader.conf
# echo 'daily_status_gmirror_enable="YES"' >> /etc/periodic.conf

# exit
```

That is the installation of FreeBSD on a mirror drive done and all that is left to do is to reboot the newly installed operating system.


----------



## ShelLuser (Jan 8, 2014)

Thanks for sharing this, this will come in _very_ handy within a few months or so for me, much appreciated!

I'm preparing to migrate my Windows 2k3 servers to FreeBSD (a project I'll be taking on within a month or so) and both servers also utilize software mirroring (it's not very high-end hardware). So this is a very welcome starting point for me to dive into this mirroring setup.

What I also consider very interesting is that FreeBSD, in contrary to both Windows and Linux, can utilize whole disks for its mirroring. Both other operating systems only use software mirroring on a per-partition basis (of course you can create a partition which consists of a whole disk, but on Unix-like environments this isn't always a desirable approach).


----------



## fugglefeet (Jan 9, 2014)

Hi ShelLuser,

Thanks for the feedback and hopefully I can provide more Howto's in the future. I have also done a variation using a per partition mirroring.

fugglefeet


----------

