FreeBSD:Install: Difference between revisions

From Wiki³
(Created page with "<div id="tocalign">__TOC__</div> The following is how to install FreeBSD using GEOM+UFS. This will offer redundancy and scaling of performance (with additional drives) for you...")
 
 
(129 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{DISPLAYTITLE:FreeBSD Installation}}
<div id="tocalign">__TOC__</div>
<div id="tocalign">__TOC__</div>
The following is how to install FreeBSD using GEOM+UFS. This will offer redundancy and scaling of performance (with additional drives) for you to base your system off of while maintaining efficiency of disk usage. This guide is mainly suited for use with workstations. It is setup for use with FreeBSD 9+ and was directly tested with the 10.0-CURRENT version of FreeBSD which includes the new BSDInstall<ref>{{cite web ||url=http://svn.freebsd.org/viewvc/base?view=revision&revision=218799 |title=FreeBSD Base r218799, Fri Feb 18 2011}}</ref>.
The following is how to install FreeBSD using GEOM+UFS. This will offer a base system of which is redundant, scalable, efficient usage of disk space. This guide is mainly suited for use with workstations, it is setup for use with FreeBSD 9.0 or newer.


==Introduction to FreeBSD==
GEOM permits access and control to classes (Master Boot Records, BSD labels, etc.) through the use of providers, or the special files in {{Mono|/dev}}. Supporting various software RAID configurations, GEOM will transparently provide access to the operating system and operating system utilities.<ref>{{cite web ||url=http://www.freebsd.org/doc/handbook/geom.html|title=FreeBSD Handbook|publisher=Chapter 20 - GEOM: Modular Disk Transformation Framework}}</ref>
I am going to make the assumption that you have at least a basic knowledge of the command line in FreeBSD. If you are new to FreeBSD all hope is not lost. The [http://www.freebsd.org/doc/handbook/ FreeBSD Handbook] is the primary source of documentation produced by the FreeBSD Documentation Project. Aside from this recently there has also been another great article written by Paul Venezia at InfoWorld entitled [http://www.infoworld.com/d/data-center/why-arent-you-using-freebsd-178119 Why aren't you using FreeBSD?]. If you are familiar with linux but new to FreeBSD there is the [http://www.freebsd.org/doc/en/articles/linux-users/index.html FreeBSD Quickstart Guide for Linux Users]. Last but not least if you are coming over from Windows you can take a look at [http://vtbsd.net/notwindows.html FreeBSD is NOT Windows].


GEOM permits access and control to classes (Master Boot Records, BSD labels, etc.) through the use of providers, or the special files in {{Mono|/dev}. Supporting various software RAID configurations, GEOM will transparently provide access to the operating system and operating system utilities.<ref>{{cite web ||url=http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/geom.html |title=FreeBSD Handbook |publisher=Chapter 20 - GEOM: Modular Disk Transformation Framework}}</ref>
==Booting the Installation Media==


Being newer features that have been recently added into FreeBSD they are not available through the generic {{ManPage|man=sysinstall|section=8}} or the new BSDInstall that is included on all of the default installation media. To remedy this, I am going to show you how to install FreeBSD manually from the shell on the install media.
Boot from your chosen installation media, for use in creation of this article the following test environment was used:
{{Note|icon=false|1={{Icon|computer}} VirtualBox 4.0.14_OSE r74382<br/>{{Icon|disc-blue}} FreeBSD-10.0-HEAD-20120130-JPSNAP-amd64-amd64-release.iso<br/><span class="plainlinks">[http://kyau.org/VMs/20120128__FreeBSD-VirtualBox_4.0.14_OSE.tar.bz2 {{Icon|drive-download}}] [http://kyau.org/VMs/20120202-freebsd__vbox4_0_14_ose.tar.bz2 Download VM]</span>}}


===Obtaining FreeBSD===
Upon first boot you will see the standard FreeBSD boot loader menu, feel free to wait out the allotted time or press enter to continue more rapidly. After the system has completed its boot up, you will be presented with the 'Welcome' window inside the new {{ManPage|man=bsdinstall|section=8}}. Select {{Mono|&lt; Shell &gt;}} from the options and press enter.


The first thing you are going to need is a copy of the most current {{mono|*-dvd1.iso}} or {{mono|*-memstick.img}} FreeBSD image (the other images do not contain the livefs that is needed). FreeBSD may be obtained from [http://torrents.freebsd.org:8080/ torrent], an [http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/mirrors-ftp.html FTP mirror] near you, or from [http://pub.allbsd.org/FreeBSD-snapshots/ FreeBSD Daily Snapshots].
==Remote Installation Setup (Optional)==


===Booting the Installation Media===
This section takes two things for granted; (a) that you have a personal set of SSH keys, and (b) that they are located on another server on the network, one that is already running an SCP capable SSH server. If you do not have one of these requirements feel free to skip this section or pause to set this up on your own. I feel it is easier to install via SSH due to the large amount of actual typing you are required to do, whereas with SSH you can merely copy/paste into the SSH window.
 
At this point you should boot from your installation media. For use in creation of this article the following test environment was used.
{{Note|1=
{{Icon|computer}} VirtualBox 4.0.14_OSE r74382
{{Icon|disc-blue}} FreeBSD-10.0-HEAD-20120120-JPSNAP-amd64-amd64-release.iso
}}
 
When you first boot up your chosen media you will see the normal boot menu, feel free to wait out the allotted time or press enter. After the system is done booting up you will be presented with the 'Welcome' window inside the new BSDInstaller.


==Configuring the Installation Environment==
Change {{Mono|/tmp}} from read-only to writable (used to store the SSH keys) and then remount it. Ignore any errors you may or may not see from executing this command, the {{Mono|/tmp}} directory will still be unmounted.
Select {{Mono|&lt; Shell &gt;}} from the options and press enter. You should now be presented with the shell. First thing we need to do is switch {{Mono|/tmp}} from read-only to writable (used later to store the zpool.cache file) and then load the required kernel modules via {{ManPage|man=kldload|section=8}}.


{{Code|umount /dev/md1}}
{{Code|umount /dev/md1}}
Ignore any errors you may or may not see from executing this command, the {{Mono|/tmp}} directory will still be unmounted. Remount the tmp directory and load the needed kernel modules.


{{Code|mdmfs -s 512M md1 /tmp}}
{{Code|mdmfs -s 512M md1 /tmp}}


{{Code|kldload geom_mirror}}
Connect to the network via DHCP with {{ManPage|man=dhclient|section=8}}, for network interface name use {{ManPage|man=ifconfig|section=8}} (common interface names are em0, nfe0, etc; look for the one that mentions the media being Ethernet). Then create our SSH host keys via {{ManPage|man=ssh-keygen|section=1}}.


{{Code|kldload opensolaris}}
{{Code|dhclient ''&lt;network interface&gt;''}}
 
{{Code|kldload zfs}}
 
===Remote Installation Setup (Optional)===
 
This section takes two things for granted; (a) that you have a personal set of SSH keys, and (b) that they are located on another server on the network, one that is already running an SCP capable SSH server. If you do not have one of these requirements feel free to skip this section or pause to set this up on your own. I feel it is easier to install via SSH due to the large amount of actual typing you are required to do, whereas with SSH you can merely copy/paste into the SSH window.
 
Connect to the network via DHCP with {{ManPage|man=dhclient|section=8}} (for network interface name use {{ManPage|man=ifconfig|section=8}}), then create our SSH host keys via {{ManPage|man=ssh-keygen|section=1}}.
 
{{Code|dhclient em0}}


{{Code|cd /tmp}}
{{Code|cd /tmp}}
Line 54: Line 34:
Next we will need to download your personal SSH keys from the network. Replace the username, IP address, and folder/file with the required information. After that is done go ahead and start up the SSH daemon with {{ManPage|man=sshd|section=8}}.
Next we will need to download your personal SSH keys from the network. Replace the username, IP address, and folder/file with the required information. After that is done go ahead and start up the SSH daemon with {{ManPage|man=sshd|section=8}}.


{{Code|scp user@192.168.''x''.''x'':~/.ssh/authorized_keys .}}
{{Code|scp ''&lt;user&gt;''@''&lt;0.0.0.0&gt;'':~/.ssh/authorized_keys .}}


{{Code|<nowiki>/usr/sbin/sshd -o PermitRootLogin=yes -o HostKey=/tmp/hostkey -o HostDSAKey=/tmp/hostkey_dsa -o AuthorizedKeysFile=/tmp/authorized_keys</nowiki>}}
{{Code|<nowiki>/usr/sbin/sshd -o PermitRootLogin=yes -o HostKey=/tmp/hostkey -o HostDSAKey=/tmp/hostkey_dsa -o AuthorizedKeysFile=/tmp/authorized_keys</nowiki>}}
Line 60: Line 40:
Connect to the IP address that was assigned to the installation computer using {{ManPage|man=ssh|section=1}} with your personal SSH keys.<ref>{{Cite web ||url=http://www.chiark.greenend.org.uk/~sgtatham/putty/ |title=PuTTY |publisher=If you are not using a Linux or BSD derived operating system you can alternatively use PuTTY}}</ref>
Connect to the IP address that was assigned to the installation computer using {{ManPage|man=ssh|section=1}} with your personal SSH keys.<ref>{{Cite web ||url=http://www.chiark.greenend.org.uk/~sgtatham/putty/ |title=PuTTY |publisher=If you are not using a Linux or BSD derived operating system you can alternatively use PuTTY}}</ref>


{{Code|ssh -l root 192.168.''x''.''x''}}
{{Code|ssh -l root ''&lt;0.0.0.0&gt;''}}


==Disk Partition Setup==
==Disk Partition Setup==
Moving on to the disk setup, first locate all of your disks, we can use {{ManPage|man=dmesg|section=8}} and {{ManPage|man=grep|section=1}} for this. The system I am using for this guide has two disks, your results may vary.
First thing we need to do is switch into an {{ManPage|man=sh|section=1}} shell, then load the required kernel modules via {{ManPage|man=kldload|section=8}}.


{{Code|dmesg {{!}} grep -e "^ad" -e "^da" -e "^hd"}}
{{Code|sh}}
{{Output|<nowiki>ada0 at ahcich0 bus 0 scbus0 target 0 lun 0
 
{{Code|kldload geom_journal}}
 
{{Code|kldload geom_mirror}}
 
{{Code|kldload geom_stripe}}
 
Moving on to the disk setup, first locate all of your disks, we can use {{ManPage|man=dmesg|section=8}} and {{ManPage|man=egrep|section=1}} for this. The system I am using for this guide has three disks, two disks will be utilized for the system and one will be dedicated for use by the {{Mono|/home}} partition. (There are many reasons for this, one being that you can then seamlessly switch between operating systems and still retain your {{Mono|/home}} folder.)
 
{{Code|dmesg {{!}} egrep "^ad{{!}}^da{{!}}^hd"}}
{{Output|<nowiki>ada0 at ahcich1 bus 0 scbus1 target 0 lun 0
ada0: <VBOX HARDDISK 1.0> ATA-6 SATA 2.x device
ada0: <VBOX HARDDISK 1.0> ATA-6 SATA 2.x device
ada0: 300.000MB/s transfers (SATA 2.x, UDMA6, PIO 8192bytes)
ada0: 300.000MB/s transfers (SATA 2.x, UDMA6, PIO 8192bytes)
ada0: Command Queueing enabled
ada0: Command Queueing enabled
ada0: 512000MB (1048576000 512 byte sectors: 16H 63S/T 16383C)
ada0: 512000MB (1048576000 512 byte sectors: 16H 63S/T 16383C)
ada1 at ahcich1 bus 0 scbus1 target 0 lun 0
ada0: Previously was known as ad6
ada1 at ahcich2 bus 0 scbus2 target 0 lun 0
ada1: <VBOX HARDDISK 1.0> ATA-6 SATA 2.x device
ada1: <VBOX HARDDISK 1.0> ATA-6 SATA 2.x device
ada1: 300.000MB/s transfers (SATA 2.x, UDMA6, PIO 8192bytes)
ada1: 300.000MB/s transfers (SATA 2.x, UDMA6, PIO 8192bytes)
ada1: Command Queueing enabled
ada1: Command Queueing enabled
ada1: 512000MB (1048576000 512 byte sectors: 16H 63S/T 163</nowiki>}}
ada1: 512000MB (1048576000 512 byte sectors: 16H 63S/T 16383C)
ada1: Previously was known as ad8
ada2 at ahcich3 bus 0 scbus3 target 0 lun 0
ada2: <VBOX HARDDISK 1.0> ATA-6 SATA 2.x device
ada2: 300.000MB/s transfers (SATA 2.x, UDMA6, PIO 8192bytes)
ada2: Command Queueing enabled
ada2: 256000MB (524288000 512 byte sectors: 16H 63S/T 16383C)
ada2: Previously was known as ad10</nowiki>}}


For partition table setup we will be using GUID Partition Table (GPT) via {{ManPage|man=gpart|section=8}}. Let's first pull up a list of the current partitions.
For partition table setup we will be using GUID Partition Table (GPT) via {{ManPage|man=gpart|section=8}}. Let's first pull up a list of the current partitions.
Line 81: Line 79:
{{Code|gpart show}}
{{Code|gpart show}}


If there are existing partitions on any disk remove them with the delete command, then destroy the disks partitioning scheme.
If there are existing partitions on any disk remove them with the delete option, then destroy the disk partitioning scheme. You will need to fill in appropriate values according to your setup, the disk is the device node you pulled from {{ManPage|man=dmesg|section=8}}, and the partition number is the one listed in the column underneath the device node name when using 'gpart show'. Replicate this for all disks as necessary.


{{Code|gpart delete -i 1 ada0}}
{{Code|gpart delete -i ''&lt;partition#&gt;'' ''&lt;disk&gt;''}}


{{Code|gpart destroy ada0}}
{{Code|gpart destroy ''&lt;disk&gt;''}}


Create a new partitioning scheme on each disk.
===GUID Partition Table===
{| class="wikitable"
|-
! align="center"| Filesystem
! align="right"| Mountpoint
! disk#0
! disk#1
! disk#2
! align="left"| Description
|-
| align="center"| freebsd-boot
| align="right"|
| align="center"| 64K
| align="center"| 64K
| align="center"|
| bootstrap / GTP bootcode
|-
| align="center"| freebsd-ufs
| align="right"| /
| align="center"| 5G
| align="center"| 5G
| align="center"|
| mirrored between disks, mounted read-only
|-
| align="center"| freebsd-swap
| align="right"| SWAP
| align="center"| 8G
| align="center"| 8G
| align="center"|
| mirrored between disks, using {{ManPage|man=geli|section=8}}
|-
| align="center"| freebsd-ufs
| align="right"| /var
| align="center"| 10G
| align="center"| 10G
| align="center"|
| striped between disks
|-
| align="center"| freebsd-ufs
| align="right"| /var/log
| align="center"| 5G
| align="center"| 5G
| align="center"|
| striped between disks
|-
| align="center"| freebsd-ufs
| align="right"| /usr
| align="center"| '''*'''
| align="center"| '''*'''
| align="center"|
| striped between disks
|-
| align="center"| freebsd-ufs
| align="right"| /home
| align="center"|
| align="center"|
| align="center"| '''*'''
| separate disk dedicated to /home
|-
| align="center"|
| align="right"| /tmp
| align="center"|
| align="center"|
| align="center"|
| 1gb mounted on encrypted SWAP with tmpmfs
|}
Create a new partition scheme on each disk to prep each disk for its partition table. The disk setup I happened to be using mapped my drives out to be {{Mono|ada0}}, {{Mono|ada1}}, and {{Mono|ada2}}; your drives maybe be different, if so replace them in the following three commands.


{{Code|gpart create -s gpt ada0}}
{{Code|disk0{{=}}ada0}}


{{Code|gpart create -s gpt ada1}}
{{Code|disk1{{=}}ada1}}


Now we need to create all of the disk partitions, we will be creating four partitions on each disk. The first partitions will contain the boot loader, the second partitions are the swap partitions and finally the third partitions are for the zpool (ZFS Pool). Adjust the size of the zpool partition to fit your disk size needs.
{{Code|disk2{{=}}ada2}}


{{Code|gpart add -s 64K -t freebsd-boot ada0}}
{{Code|gpart create -s gpt $disk0}}


{{Code|gpart add -s 4G -t freebsd-swap -l swap0 ada0}}
{{Code|gpart create -s gpt $disk1}}


{{Code|gpart add -s 495G -t freebsd-zfs -l zroot0 ada0}}
{{Code|gpart create -s gpt $disk2}}


Now that we have the base partition setup, replicate this onto the other disk.
Now we need to create all of the disk partitions, the following table indicates how we will be laying out the partition table of all the disks. Each disk will contain a {{Mono|boot}}, {{Mono|root}} and {{Mono|swap}} partitions (mirrored across ''$disk0'' and ''$disk1''), {{Mono|/var}}, {{Mono|/var/log}}, and {{Mono|/usr}} partitions (striped across ''$disk0'' and ''$disk1''), and finally a {{Mono|/home}} partition filling the entirety of ''$disk2''. Adjust the size of your filesystem partitions to fit your disk size needs (starting trimming down with the {{Mono|/usr}} partition).


{{Code|gpart add -s 64K -t freebsd-boot ada1}}
Create the boot partition and embed GPT bootstrap into protective MBR, then install GPT bootstrap onto the boot partition.


{{Code|gpart add -s 4G -t freebsd-swap -l swap1 ada1}}
{{Code|gpart add -s 64K -t freebsd-boot $disk0}}


{{Code|gpart add -s 495G -t freebsd-zfs -l zroot1 ada1}}
{{Code|gpart bootcode -b /boot/pmbr -i1 -p /boot/gptboot $disk0}}


Install the protected MBR boot code and gptzfsboot loader onto each of the disks. The gptzfsboot loader will give you the ability to load zfsloader from a zpool.
Then create swap and filesystem partitions, and replicate the partition table you created for ''$disk0'' onto ''$disk1''.


{{Code|gpart bootcode -b /boot/pmbr -i 1 -p /boot/gptzfsboot ada0}}
{{Code|gpart add -s 5G -t freebsd-ufs $disk0}}


{{Code|gpart bootcode -b /boot/pmbr -i 1 -p /boot/gptzfsboot ada1}}
{{Code|gpart add -s 8G -t freebsd-swap $disk0}}


Verify the partition table to make sure all of the disks match.
{{Code|gpart add -s 10G -t freebsd-ufs $disk0}}


{{Code|gpart show}}
{{Code|gpart add -s 5G -t freebsd-ufs $disk0}}
{{Output|<nowiki>=>        34  1048575933  ada0  GPT  (500G)
 
          34        128    1  freebsd-boot  (64K)
{{Code|gpart add -t freebsd-ufs $disk0}}
        162    8388608    2  freebsd-swap  (4.0G)
 
    8388770  1038090240    3  freebsd-zfs  (495G)
{{Code|gpart backup $disk0 {{!}} gpart restore -F $disk1}}
  1046479010    2096957        - free -  (1.0G)
 
Finally create the boot and {{Mono|/home}} partitions on ''$disk2''.


=>        34  1048575933  ada1  GPT  (500G)
{{Code|gpart add -s 64K -t freebsd-boot $disk2}}
          34        128    1  freebsd-boot  (64K)
        162    8388608    2  freebsd-swap  (4.0G)
    8388770  1038090240    3  freebsd-zfs  (495G)
  1046479010    2096957        - free -  (1.0G)</nowiki>}}


Take note that I did not use the entire disk, the reason behind this is that when using RAID and replacing problematic disks more than likely your new disk will have a slightly different disk geometry and as such might limit your ability to use it as a replacement disk if you cannot fit all the necessary partitions on the disk.
{{Code|gpart bootcode -b /boot/pmbr -i1 -p /boot/gptboot $disk2}}


==ZFS File System==
{{Code|gpart add -t freebsd-ufs $disk2}}
Moving onto the ZFS volume setup, create the main {{ManPage|man=zpool|section=8}} and the root volume, then mount the root volume on to {{Mono|/mnt}}.


{{Code|<nowiki>zpool create -O atime=off -O canmount=off -O checksum=fletcher4 -O mountpoint=/mnt -O setuid=off zroot raidz gpt/zroot0 gpt/zroot1</nowiki>}}
Verify the partition table to make sure all of the disks are setup correctly.


{{Code|<nowiki>zfs create -o mountpoint=legacy -o setuid=on zroot/root</nowiki>}}
{{Code|gpart show -p}}
{{Output|<nowiki>=>        34  1048575933    ada0  GPT  (500G)
          34        128  ada0p1  freebsd-boot  (64k)
        162    10485760  ada0p2  freebsd-ufs  (5.0G)
    10485922    16777216  ada0p3  freebsd-swap  (8.0G)
    27263138    20971520  ada0p4  freebsd-ufs  (10G)
    48234658    10485760  ada0p5  freebsd-ufs  (5.0G)
    58720418  989855549  ada0p6  freebsd-ufs  (472G)


{{Code|mount -t zfs zroot/root /mnt}}
=>        34  1048575933    ada1  GPT  (500G)
          34        128  ada1p1  freebsd-boot  (64k)
        162    10485760  ada1p2  freebsd-ufs  (5.0G)
    10485922    16777216  ada1p3  freebsd-swap  (8.0G)
    27263138    20971520  ada1p4  freebsd-ufs  (10G)
    48234658    10485760  ada1p5  freebsd-ufs  (5.0G)
    58720418  989855549  ada1p6  freebsd-ufs  (472G)


Create the {{Mono|/usr}} container volume and then all the sub-volumes.
=>      34  524287933    ada2  GPT  (250G)
        34        128  ada2p1  freebsd-boot  (64k)
        162  524287805  ada2p2  freebsd-ufs  (250G)</nowiki>}}


{{Code|<nowiki>zfs create -o canmount=off zroot/usr</nowiki>}}
===RAID0 & RAID1===
Now that the partition table is laid out we can move on to setting up the RAID configuration and filesystem labels. We will be using {{ManPage|man=gmirror|section=8}} to put the {{Mono|root}} and {{Mono|swap}} partitions into RAID1 systems. Then using {{ManPage|man=gstripe|section=8}} put the {{Mono|/var}}, {{Mono|/var/log}}, and {{Mono|/usr}} partitions into RAID0 systems.


{{Code|zfs create zroot/usr/home}}
{{Code|gmirror label -v -b load root ${disk0}p2 ${disk1}p2}}


{{Code|<nowiki>zfs create -o compress=lzjb -o exec=on zroot/usr/obj</nowiki>}}
{{Code|gmirror label -v -b prefer swap ${disk0}p3 ${disk1}p3}}


{{Code|<nowiki>zfs create -o compress=gzip zroot/usr/ports</nowiki>}}
{{Code|gstripe label -v var ${disk0}p4 ${disk1}p4}}


{{Code|<nowiki>zfs create -o compress=off -o exec=off zroot/usr/ports/distfiles</nowiki>}}
{{Code|gstripe label -v log ${disk0}p5 ${disk1}p5}}


{{Code|<nowiki>zfs create -o compress=off -o exec=off zroot/usr/ports/packages</nowiki>}}
{{Code|gstripe label -v usr ${disk0}p6 ${disk1}p6}}


{{Code|<nowiki>zfs create -o compress=gzip -o exec=off zroot/usr/src</nowiki>}}
===UFS Journaling===
Journaling capability stores a log of file system transactions, i.e.: changes that make up a complete disk write operation, before meta-data and file writes are committed to the disk proper. This transaction log can later be replayed to redo file system transactions, preventing file system inconsistencies. This method is yet another mechanism to protect against data loss and inconsistencies of the file system.<ref>{{cite web||url=http://www.freebsd.org/doc/handbook/geom-gjournal.html|title=FreeBSD Handbook|publisher=Chapter 20.7 - UFS Journaling Through GEOM}}</ref> Begin by creating all the journals for the filesystems with {{ManPage|man=gjournal|section=8}}.


{{Code|cd /mnt ; ln -s /usr/home home}}
{{Code|gjournal label mirror/root}}


Then create the {{Mono|/var}} container and subsequent sub-volumes.
{{Code|gjournal label stripe/var}}


{{Code|<nowiki>zfs create -o exec=off -o canmount=off zroot/var</nowiki>}}
{{Code|gjournal label stripe/log}}


{{Code|<nowiki>zfs create -o compress=lzjb zroot/var/audit</nowiki>}}
{{Code|gjournal label stripe/usr}}


{{Code|<nowiki>zfs create -o compress=lzjb zroot/var/crash</nowiki>}}
{{Code|glabel label home ${disk2}p2}}


{{Code|zfs create zroot/var/db}}
{{Code|gjournal label label/home}}


{{Code|<nowiki>zfs create -o compress=lzjb -o exec=on zroot/var/db/pkg</nowiki>}}
===Clear/Mount Filesystems===
The next natural step is to construct all of the UFSv2 file systems with {{ManPage|man=newfs|section=8}}. We will be setting the minimum free space threshold to 5% in addition to enabling journaling and setting UFS to UFSv2.


{{Code|zfs create zroot/var/empty}}
{{Code|newfs -m 5 -O 2 -J mirror/root.journal}}


{{Code|<nowiki>zfs create -o compress=gzip zroot/var/log</nowiki>}}
{{Code|newfs -m 5 -O 2 -J stripe/var.journal}}


{{Code|<nowiki>zfs create -o compress=gzip zroot/var/mail</nowiki>}}
{{Code|newfs -m 5 -O 2 -J stripe/log.journal}}


{{Code|zfs create zroot/var/run}}
{{Code|newfs -m 5 -O 2 -J stripe/usr.journal}}


==FreeBSD Installation==
{{Code|newfs -m 5 -O 2 -J label/home.journal}}
Now that the ZFS file system hierarchy is setup we can remount the ZFS pool, install the FreeBSD base system, and then copy the zpool.cache. When you import the zpool back into the system you might get errors about not being able to create mountpoints, this is rectified two commands later.


{{Code|cd}}
After this {{ManPage|man=mount|section=8}} the {{Mono|root}} partition and create all the base folders for the other mounts and then mount them as well.


{{Code|zpool export zroot}}
{{Code|mount -t ufs -o async /dev/mirror/root.journal /mnt}}


{{Code|zpool import -o cachefile{{=}}/tmp/zpool.cache zroot}}
{{Code|mkdir -p /mnt/home /mnt/usr /mnt/var}}


{{Code|mount -t zfs zroot/root /mnt}}
{{Code|mount -t ufs -o async /dev/label/home.journal /mnt/home}}


{{Code|zfs mount -a}}
{{Code|mount -t ufs -o async /dev/stripe/usr.journal /mnt/usr}}


{{Code|mount -t ufs -o async /dev/stripe/var.journal /mnt/var}}


{{Code|sh}}
{{Code|mkdir -p /mnt/var/log}}


{{Code|cd /usr/freebsd-dist}}
{{Code|mount -t ufs -o async /dev/stripe/log.journal /mnt/var/log}}


{{Code|export DESTDIR{{=}}/mnt}}
At this point you mounts should look like the following.


{{Code|for file in base.txz lib32.txz kernel.txz doc.txz;}}
{{Code|df -HTt ufs {{!}} egrep "Filesystem{{!}}journal"}}
{{Output|Filesystem                Type    Size    Used  Avail Capacity  Mounted on<br />/dev/mirror/root.journal  ufs    4.2G    20k    3.9G    0%    /mnt<br />/dev/label/home.journal  ufs    259G    8.2k    246G    0%    /mnt/home<br />/dev/stripe/usr.journal  ufs    980G    8.2k    931G    0%    /mnt/usr<br />/dev/stripe/var.journal  ufs      19G    12k    18G    0%    /mnt/var<br />/dev/stripe/log.journal  ufs    9.4G    8.2k    8.9G    0%    /mnt/var/log}}


{{Code|<nowiki>do (cat $file | tar --unlink -xpJf - -C ${DESTDIR:-/}); done</nowiki>}}
==FreeBSD Installation==
Now that the file system hierarchy is setup we can install the FreeBSD base system. In order to do so we will manually be entering the folder on the installation media where the installation files reside and then extracting them onto the new filesystem in its temporarily mounted location. (Only include the {{Mono|lib32.txz}} file if you are installing on an amd64 system with amd64 installation media.)


===Manual Install===
{{Code|cd /usr/freebsd-dist}}


{{Code|cp /tmp/zpool.cache /mnt/boot/zfs/zpool.cache}}
{{Code|export DESTDIR{{=}}/mnt}}


{{Code|exit}}
{{Code|for file in base.txz doc.txz ''lib32.txz'' kernel.txz;}}


Switch the {{Mono|zroot/var/empty}} zpool volume to read-only and then chroot into your newly installed system.
{{Code|<nowiki>do (cat $file | tar --unlink -xpJf - -C ${DESTDIR:-/}); done</nowiki>}}


{{Code|zfs set readonly{{=}}on zroot/var/empty}}
Next {{ManPage|man=chroot|section=8}} (change root) into your newly installed system.


{{Code|chroot /mnt}}
{{Code|chroot /mnt}}


==FreeBSD Configuration==
===System Configuration===
Setup the network and necessary startup files so the zpool will be mounted automatically on boot. Start by creating the {{Mono|/etc/rc.conf}} system configuration file.
Setup the network and necessary startup files so the zpool will be mounted automatically on boot. Start by creating the {{Mono|/etc/rc.conf}} system configuration file.


{{Code|<nowiki>cat >> /etc/rc.conf << _EOF_</nowiki>}}
{{Code|<nowiki>cat >> /etc/rc.conf << _EOF_</nowiki>}}
{{Output|<nowiki>hostname="VM.privatebox"
{{Output|hostname{{=}}"VM.freebsd"<br />ifconfig_em0{{=}}"DHCP"<br />geli_swap_flags{{=}}"-e aes -l 256 -s 4096 -d"<br />ntpd_enable{{=}}"YES"<br />ntpd_sync_on_start{{=}}"YES"<br />sshd_enable{{=}}"YES"<br />tmpmfs{{=}}"YES"<br />tmpsize{{=}}"1024m"<br />tmpmfs_flags{{=}}"-m 0 -o async,noatime -S -p 1777"<br />_EOF_}}
ifconfig_em0="DHCP"
geli_swap_flags="-e aes -l 256 -s 4096 -d"
ntpd_enable="YES"
ntpd_sync_on_start="YES"
sshd_enable="YES"
tmpmfs="YES"
tmpsize="512m"
tmpmfs_flags="-m 0 -o async,noatime -S -p 1777"
zfs_enable="YES"
_EOF_</nowiki>}}


Next we need to create the {{Mono|/boot/loader.conf}} boot configuration file. Let us start by setting some defaults and then telling it which kernel modules you need loaded on boot. Finally let's tell the loader which zpool to boot from.
Next we need to create the {{Mono|/boot/loader.conf}} boot configuration file. Let us start by setting some defaults and then telling it which kernel modules you need loaded on boot. Then tell the loader what to boot from and how to mount said {{Mono|root}} partition.


{{Code|<nowiki>cat >> /boot/loader.conf << _EOF_</nowiki>}}
{{Code|<nowiki>cat >> /boot/loader.conf << _EOF_</nowiki>}}
{{Output|<nowiki>autoboot_delay="5"
{{Output|autoboot_delay{{=}}"5"<br />loader_logo{{=}}"beastie"<br /><br />ahci_load{{=}}"YES"<br />geom_eli_load{{=}}"YES"<br />geom_journal_load{{=}}"YES"<br />geom_mirror_load{{=}}"YES"<br />geom_stripe_load{{=}}"YES"<br /><br />kern.geom.label.gptid.enable{{=}}"0"<br />vfs.root.mountfrom{{=}}"ufs:/dev/mirror/root.journal"<br />vfs.root.mountfrom.options{{=}}"rw"<br />_EOF_}}
loader_logo="beastie"
 
ahci_load="YES"
Edit the {{Mono|/etc/fstab}} and add all the appropriate entries for the {{Mono|swap}} and filesystem partitions.
geom_eli_load="YES"
 
geom_mirror_load="YES"
{{Code|<nowiki>cat >> /etc/fstab << _EOF_</nowiki>}}
geom_label_load="YES"
{{Output|# Local Mounts<br />/dev/mirror/swap.eli                    none                    swap  sw                  0    0<br />/dev/mirror/root.journal                /                      ufs    async,noatime,rw    1    1<br />/dev/label/home.journal                /home                  ufs    async,noatime,rw    2    2<br />/dev/stripe/usr.journal                /usr                    ufs    async,noatime,rw    2    2<br />/dev/stripe/var.journal                /var                    ufs    async,noatime,rw    2    2<br />/dev/stripe/log.journal                /var/log                ufs    async,noatime,rw    2    2<br />_EOF_}}
zfs_load="YES"
vfs.root.mountfrom="zfs:zroot/root"
_EOF_</nowiki>}}


Now that we have our default configuration lets set a root password, fix the local time zone, create a mail aliases database, and exit out of the chroot environment.
Now that we have our default configuration lets set a root password, fix the local time zone, create a mail aliases database, and exit out of the chroot environment.


{{Code|passwd}}
{{Code|passwd}}
{{Code|ln -s /dev/null /etc/localtime}}


{{Code|tzsetup}}
{{Code|tzsetup}}
Line 253: Line 324:
{{Code|exit}}
{{Code|exit}}


==Finishing the Installation==
At this point your FreeBSD system is fully installed with a very minimal base system. Go ahead and remove the installation media and {{ManPage|man=reboot|section=8}}.
Now that FreeBSD is installed lets setup the partitions that we designated as SWAP. For this we are going to {{ManPage|man=gmirror|section=8}} the partitions together, add them into fstab, and finally set some variables.
 
{{Code|gmirror label -b prefer swap gpt/swap0 gpt/swap1}}
 
{{Code|<nowiki>cat >> /mnt/etc/fstab << _EOF_</nowiki>>}}
{{Output|<nowiki># [Device]  [Mountpoint]  [FStype]  [Options]  [Dump]  [Pass#]
/dev/mirror/swap.eli  none  swap  sw  0  0
_EOF_</nowiki>}}
 
Finally we need to setup the new mount points for each zpool and set the bootable volume. Afterwards go ahead and {{ManPage|man=reboot|section=8}}.
 
{{Code|zfs set mountpoint{{=}}/ zroot}}
 
{{Code|zpool set bootfs{{=}}zroot/root zroot}}


{{Code|reboot now}}
{{Code|reboot now}}
At this point your FreeBSD system is fully installed with a very minimal base system. Exit out of the shell prompt and BSDInstaller, remove the installation media and reboot the machine.


==Notes==
==Notes==

Latest revision as of 18:32, 10 July 2017

The following is how to install FreeBSD using GEOM+UFS. This will offer a base system of which is redundant, scalable, efficient usage of disk space. This guide is mainly suited for use with workstations, it is setup for use with FreeBSD 9.0 or newer.

GEOM permits access and control to classes (Master Boot Records, BSD labels, etc.) through the use of providers, or the special files in /dev. Supporting various software RAID configurations, GEOM will transparently provide access to the operating system and operating system utilities.[1]

Booting the Installation Media

Boot from your chosen installation media, for use in creation of this article the following test environment was used:

Icon VirtualBox 4.0.14_OSE r74382
Icon FreeBSD-10.0-HEAD-20120130-JPSNAP-amd64-amd64-release.iso
Icon Download VM

Upon first boot you will see the standard FreeBSD boot loader menu, feel free to wait out the allotted time or press enter to continue more rapidly. After the system has completed its boot up, you will be presented with the 'Welcome' window inside the new bsdinstall(8). Select < Shell > from the options and press enter.

Remote Installation Setup (Optional)

This section takes two things for granted; (a) that you have a personal set of SSH keys, and (b) that they are located on another server on the network, one that is already running an SCP capable SSH server. If you do not have one of these requirements feel free to skip this section or pause to set this up on your own. I feel it is easier to install via SSH due to the large amount of actual typing you are required to do, whereas with SSH you can merely copy/paste into the SSH window.

Change /tmp from read-only to writable (used to store the SSH keys) and then remount it. Ignore any errors you may or may not see from executing this command, the /tmp directory will still be unmounted.

umount /dev/md1

mdmfs -s 512M md1 /tmp

Connect to the network via DHCP with dhclient(8), for network interface name use ifconfig(8) (common interface names are em0, nfe0, etc; look for the one that mentions the media being Ethernet). Then create our SSH host keys via ssh-keygen(1).

dhclient <network interface>

cd /tmp

ssh-keygen -f /tmp/hostkey -t rsa1 -b 4096 -N ''

ssh-keygen -f /tmp/hostkey_dsa -t dsa -N ''

Next we will need to download your personal SSH keys from the network. Replace the username, IP address, and folder/file with the required information. After that is done go ahead and start up the SSH daemon with sshd(8).

scp <user>@<0.0.0.0>:~/.ssh/authorized_keys .

/usr/sbin/sshd -o PermitRootLogin=yes -o HostKey=/tmp/hostkey -o HostDSAKey=/tmp/hostkey_dsa -o AuthorizedKeysFile=/tmp/authorized_keys

Connect to the IP address that was assigned to the installation computer using ssh(1) with your personal SSH keys.[2]

ssh -l root <0.0.0.0>

Disk Partition Setup

First thing we need to do is switch into an sh(1) shell, then load the required kernel modules via kldload(8).

sh

kldload geom_journal

kldload geom_mirror

kldload geom_stripe

Moving on to the disk setup, first locate all of your disks, we can use dmesg(8) and egrep(1) for this. The system I am using for this guide has three disks, two disks will be utilized for the system and one will be dedicated for use by the /home partition. (There are many reasons for this, one being that you can then seamlessly switch between operating systems and still retain your /home folder.)

dmesg | egrep "^ad|^da|^hd"

ada0 at ahcich1 bus 0 scbus1 target 0 lun 0 ada0: <VBOX HARDDISK 1.0> ATA-6 SATA 2.x device ada0: 300.000MB/s transfers (SATA 2.x, UDMA6, PIO 8192bytes) ada0: Command Queueing enabled ada0: 512000MB (1048576000 512 byte sectors: 16H 63S/T 16383C) ada0: Previously was known as ad6 ada1 at ahcich2 bus 0 scbus2 target 0 lun 0 ada1: <VBOX HARDDISK 1.0> ATA-6 SATA 2.x device ada1: 300.000MB/s transfers (SATA 2.x, UDMA6, PIO 8192bytes) ada1: Command Queueing enabled ada1: 512000MB (1048576000 512 byte sectors: 16H 63S/T 16383C) ada1: Previously was known as ad8 ada2 at ahcich3 bus 0 scbus3 target 0 lun 0 ada2: <VBOX HARDDISK 1.0> ATA-6 SATA 2.x device ada2: 300.000MB/s transfers (SATA 2.x, UDMA6, PIO 8192bytes) ada2: Command Queueing enabled ada2: 256000MB (524288000 512 byte sectors: 16H 63S/T 16383C) ada2: Previously was known as ad10

For partition table setup we will be using GUID Partition Table (GPT) via gpart(8). Let's first pull up a list of the current partitions.

gpart show

If there are existing partitions on any disk remove them with the delete option, then destroy the disk partitioning scheme. You will need to fill in appropriate values according to your setup, the disk is the device node you pulled from dmesg(8), and the partition number is the one listed in the column underneath the device node name when using 'gpart show'. Replicate this for all disks as necessary.

gpart delete -i <partition#> <disk>

gpart destroy <disk>

GUID Partition Table

Filesystem Mountpoint disk#0 disk#1 disk#2 Description
freebsd-boot 64K 64K bootstrap / GTP bootcode
freebsd-ufs / 5G 5G mirrored between disks, mounted read-only
freebsd-swap SWAP 8G 8G mirrored between disks, using geli(8)
freebsd-ufs /var 10G 10G striped between disks
freebsd-ufs /var/log 5G 5G striped between disks
freebsd-ufs /usr * * striped between disks
freebsd-ufs /home * separate disk dedicated to /home
/tmp 1gb mounted on encrypted SWAP with tmpmfs

Create a new partition scheme on each disk to prep each disk for its partition table. The disk setup I happened to be using mapped my drives out to be ada0, ada1, and ada2; your drives maybe be different, if so replace them in the following three commands.

disk0=ada0

disk1=ada1

disk2=ada2

gpart create -s gpt $disk0

gpart create -s gpt $disk1

gpart create -s gpt $disk2

Now we need to create all of the disk partitions, the following table indicates how we will be laying out the partition table of all the disks. Each disk will contain a boot, root and swap partitions (mirrored across $disk0 and $disk1), /var, /var/log, and /usr partitions (striped across $disk0 and $disk1), and finally a /home partition filling the entirety of $disk2. Adjust the size of your filesystem partitions to fit your disk size needs (starting trimming down with the /usr partition).

Create the boot partition and embed GPT bootstrap into protective MBR, then install GPT bootstrap onto the boot partition.

gpart add -s 64K -t freebsd-boot $disk0

gpart bootcode -b /boot/pmbr -i1 -p /boot/gptboot $disk0

Then create swap and filesystem partitions, and replicate the partition table you created for $disk0 onto $disk1.

gpart add -s 5G -t freebsd-ufs $disk0

gpart add -s 8G -t freebsd-swap $disk0

gpart add -s 10G -t freebsd-ufs $disk0

gpart add -s 5G -t freebsd-ufs $disk0

gpart add -t freebsd-ufs $disk0

gpart backup $disk0 | gpart restore -F $disk1

Finally create the boot and /home partitions on $disk2.

gpart add -s 64K -t freebsd-boot $disk2

gpart bootcode -b /boot/pmbr -i1 -p /boot/gptboot $disk2

gpart add -t freebsd-ufs $disk2

Verify the partition table to make sure all of the disks are setup correctly.

gpart show -p

=> 34 1048575933 ada0 GPT (500G) 34 128 ada0p1 freebsd-boot (64k) 162 10485760 ada0p2 freebsd-ufs (5.0G) 10485922 16777216 ada0p3 freebsd-swap (8.0G) 27263138 20971520 ada0p4 freebsd-ufs (10G) 48234658 10485760 ada0p5 freebsd-ufs (5.0G) 58720418 989855549 ada0p6 freebsd-ufs (472G) => 34 1048575933 ada1 GPT (500G) 34 128 ada1p1 freebsd-boot (64k) 162 10485760 ada1p2 freebsd-ufs (5.0G) 10485922 16777216 ada1p3 freebsd-swap (8.0G) 27263138 20971520 ada1p4 freebsd-ufs (10G) 48234658 10485760 ada1p5 freebsd-ufs (5.0G) 58720418 989855549 ada1p6 freebsd-ufs (472G) => 34 524287933 ada2 GPT (250G) 34 128 ada2p1 freebsd-boot (64k) 162 524287805 ada2p2 freebsd-ufs (250G)

RAID0 & RAID1

Now that the partition table is laid out we can move on to setting up the RAID configuration and filesystem labels. We will be using gmirror(8) to put the root and swap partitions into RAID1 systems. Then using gstripe(8) put the /var, /var/log, and /usr partitions into RAID0 systems.

gmirror label -v -b load root ${disk0}p2 ${disk1}p2

gmirror label -v -b prefer swap ${disk0}p3 ${disk1}p3

gstripe label -v var ${disk0}p4 ${disk1}p4

gstripe label -v log ${disk0}p5 ${disk1}p5

gstripe label -v usr ${disk0}p6 ${disk1}p6

UFS Journaling

Journaling capability stores a log of file system transactions, i.e.: changes that make up a complete disk write operation, before meta-data and file writes are committed to the disk proper. This transaction log can later be replayed to redo file system transactions, preventing file system inconsistencies. This method is yet another mechanism to protect against data loss and inconsistencies of the file system.[3] Begin by creating all the journals for the filesystems with gjournal(8).

gjournal label mirror/root

gjournal label stripe/var

gjournal label stripe/log

gjournal label stripe/usr

glabel label home ${disk2}p2

gjournal label label/home

Clear/Mount Filesystems

The next natural step is to construct all of the UFSv2 file systems with newfs(8). We will be setting the minimum free space threshold to 5% in addition to enabling journaling and setting UFS to UFSv2.

newfs -m 5 -O 2 -J mirror/root.journal

newfs -m 5 -O 2 -J stripe/var.journal

newfs -m 5 -O 2 -J stripe/log.journal

newfs -m 5 -O 2 -J stripe/usr.journal

newfs -m 5 -O 2 -J label/home.journal

After this mount(8) the root partition and create all the base folders for the other mounts and then mount them as well.

mount -t ufs -o async /dev/mirror/root.journal /mnt

mkdir -p /mnt/home /mnt/usr /mnt/var

mount -t ufs -o async /dev/label/home.journal /mnt/home

mount -t ufs -o async /dev/stripe/usr.journal /mnt/usr

mount -t ufs -o async /dev/stripe/var.journal /mnt/var

mkdir -p /mnt/var/log

mount -t ufs -o async /dev/stripe/log.journal /mnt/var/log

At this point you mounts should look like the following.

df -HTt ufs | egrep "Filesystem|journal"

Filesystem Type Size Used Avail Capacity Mounted on
/dev/mirror/root.journal ufs 4.2G 20k 3.9G 0% /mnt
/dev/label/home.journal ufs 259G 8.2k 246G 0% /mnt/home
/dev/stripe/usr.journal ufs 980G 8.2k 931G 0% /mnt/usr
/dev/stripe/var.journal ufs 19G 12k 18G 0% /mnt/var
/dev/stripe/log.journal ufs 9.4G 8.2k 8.9G 0% /mnt/var/log

FreeBSD Installation

Now that the file system hierarchy is setup we can install the FreeBSD base system. In order to do so we will manually be entering the folder on the installation media where the installation files reside and then extracting them onto the new filesystem in its temporarily mounted location. (Only include the lib32.txz file if you are installing on an amd64 system with amd64 installation media.)

Manual Install

cd /usr/freebsd-dist

export DESTDIR=/mnt

for file in base.txz doc.txz lib32.txz kernel.txz;

do (cat $file | tar --unlink -xpJf - -C ${DESTDIR:-/}); done

Next chroot(8) (change root) into your newly installed system.

chroot /mnt

System Configuration

Setup the network and necessary startup files so the zpool will be mounted automatically on boot. Start by creating the /etc/rc.conf system configuration file.

cat >> /etc/rc.conf << _EOF_

hostname="VM.freebsd"
ifconfig_em0="DHCP"
geli_swap_flags="-e aes -l 256 -s 4096 -d"
ntpd_enable="YES"
ntpd_sync_on_start="YES"
sshd_enable="YES"
tmpmfs="YES"
tmpsize="1024m"
tmpmfs_flags="-m 0 -o async,noatime -S -p 1777"
_EOF_

Next we need to create the /boot/loader.conf boot configuration file. Let us start by setting some defaults and then telling it which kernel modules you need loaded on boot. Then tell the loader what to boot from and how to mount said root partition.

cat >> /boot/loader.conf << _EOF_

autoboot_delay="5"
loader_logo="beastie"

ahci_load="YES"
geom_eli_load="YES"
geom_journal_load="YES"
geom_mirror_load="YES"
geom_stripe_load="YES"

kern.geom.label.gptid.enable="0"
vfs.root.mountfrom="ufs:/dev/mirror/root.journal"
vfs.root.mountfrom.options="rw"
_EOF_

Edit the /etc/fstab and add all the appropriate entries for the swap and filesystem partitions.

cat >> /etc/fstab << _EOF_

# Local Mounts
/dev/mirror/swap.eli none swap sw 0 0
/dev/mirror/root.journal / ufs async,noatime,rw 1 1
/dev/label/home.journal /home ufs async,noatime,rw 2 2
/dev/stripe/usr.journal /usr ufs async,noatime,rw 2 2
/dev/stripe/var.journal /var ufs async,noatime,rw 2 2
/dev/stripe/log.journal /var/log ufs async,noatime,rw 2 2
_EOF_

Now that we have our default configuration lets set a root password, fix the local time zone, create a mail aliases database, and exit out of the chroot environment.

passwd

ln -s /dev/null /etc/localtime

tzsetup

cd /etc/mail ; make aliases

exit

At this point your FreeBSD system is fully installed with a very minimal base system. Go ahead and remove the installation media and reboot(8).

reboot now

Notes

  1. ^ "FreeBSD Handbook". Chapter 20 - GEOM: Modular Disk Transformation Framework. http://www.freebsd.org/doc/handbook/geom.html. 
  2. ^ "PuTTY". If you are not using a Linux or BSD derived operating system you can alternatively use PuTTY. http://www.chiark.greenend.org.uk/~sgtatham/putty/. 
  3. ^ "FreeBSD Handbook". Chapter 20.7 - UFS Journaling Through GEOM. http://www.freebsd.org/doc/handbook/geom-gjournal.html.