FreeBSD:Install: Difference between revisions

From Wiki³
Line 2: Line 2:
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.
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==
==Booting the Installation Media==
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>
 
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.
 
===Obtaining FreeBSD===
 
The first thing you are going to need is a copy of the most current {{mono|*-dvd1.iso}}, {{mono|*-release.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].
 
===Booting the Installation Media===


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


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


==Configuring the Installation Environment==
==Configuring the Installation Environment==

Revision as of 17:47, 27 January 2012

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.

Booting the Installation Media

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

IconIcon VirtualBox 4.0.14_OSE r74382 Icon FreeBSD-10.0-HEAD-20120120-JPSNAP-amd64-amd64-release.iso

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.

Configuring the Installation Environment

Load the required kernel modules via kldload(8).

kldload geom_journal

kldload geom_mirror

kldload geom_stripe

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 dhclient(8) (for network interface name use ifconfig(8)), then create our SSH host keys via ssh-keygen(1).

dhclient em0

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@192.168.x.x:~/.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.[1]

ssh -l root 192.168.x.x

Disk Partition Setup

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, your results may vary.

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: 2097151MB (4294965248 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: 2097151MB (4294965248 512 byte sectors: 16H 63S/T 163 ada1: Previously was known as ad8

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 disks partitioning scheme so we can start with 'clean slates'. The disk here is the device node you pulled from dmesg(8), and the partition # 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>

Create a new partition scheme on each disk, for the following setup I will be using the following two disk setup. Modify the settings according to the hard drives in your possession, keep in mine however that the

gpart create -s gpt <disk#0>

gpart create -s gpt <disk#1>

Now we need to create all of the disk partitions, the following table indicates how we will be laying out the partition table of each disk. Each disk will contain a boot partition, a swap partition (which will be mirrored together) and numerous filesystem partitions. Adjust the size of your filesystem partitions to fit your disk size needs (starting with /home and /usr).

GPT Filesystem Mountpoint Size Description
Partition #1 freebsd-boot 64K bootstrap / GTP bootcode
Partition #2 freebsd-swap SWAP 8G mirrored between disks, using geli(8)
Partition #3 freebsd-ufs / 5G mirrored between disks, mounted read-only
Partition #4 freebsd-ufs /home 5G mirrored between disks, mounted read-only
/tmp 1G mounted on encrypted SWAP with tmpmfs

gpart add -s 64K -t freebsd-boot <disk#0>

gpart bootcode -b /boot/pmbr <disk#0>

gpart add -s 8G -t freebsd-swap <disk#0>


gpart add -s 4G -t freebsd-swap <disk#0>

Now that we have the base partition setup, replicate this onto the other disk.

gpart add -s 64K -t freebsd-boot ada1

gpart add -s 4G -t freebsd-swap -l swap1 ada1

gpart add -s 495G -t freebsd-zfs -l zroot1 ada1

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.

gpart bootcode -b /boot/pmbr -i 1 -p /boot/gptzfsboot ada0

gpart bootcode -b /boot/pmbr -i 1 -p /boot/gptzfsboot ada1

Verify the partition table to make sure all of the disks match.

gpart show

=> 34 1048575933 ada0 GPT (500G) 34 128 1 freebsd-boot (64K) 162 8388608 2 freebsd-swap (4.0G) 8388770 1038090240 3 freebsd-zfs (495G) 1046479010 2096957 - free - (1.0G) => 34 1048575933 ada1 GPT (500G) 34 128 1 freebsd-boot (64K) 162 8388608 2 freebsd-swap (4.0G) 8388770 1038090240 3 freebsd-zfs (495G) 1046479010 2096957 - free - (1.0G)

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.

ZFS File System

Moving onto the ZFS volume setup, create the main zpool(8) and the root volume, then mount the root volume on to /mnt.

zpool create -O atime=off -O canmount=off -O checksum=fletcher4 -O mountpoint=/mnt -O setuid=off zroot raidz gpt/zroot0 gpt/zroot1

zfs create -o mountpoint=legacy -o setuid=on zroot/root

mount -t zfs zroot/root /mnt

Create the /usr container volume and then all the sub-volumes.

zfs create -o canmount=off zroot/usr

zfs create zroot/usr/home

zfs create -o compress=lzjb -o exec=on zroot/usr/obj

zfs create -o compress=gzip zroot/usr/ports

zfs create -o compress=off -o exec=off zroot/usr/ports/distfiles

zfs create -o compress=off -o exec=off zroot/usr/ports/packages

zfs create -o compress=gzip -o exec=off zroot/usr/src

cd /mnt ; ln -s /usr/home home

Then create the /var container and subsequent sub-volumes.

zfs create -o exec=off -o canmount=off zroot/var

zfs create -o compress=lzjb zroot/var/audit

zfs create -o compress=lzjb zroot/var/crash

zfs create zroot/var/db

zfs create -o compress=lzjb -o exec=on zroot/var/db/pkg

zfs create zroot/var/empty

zfs create -o compress=gzip zroot/var/log

zfs create -o compress=gzip zroot/var/mail

zfs create zroot/var/run

FreeBSD Installation

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.

cd

zpool export zroot

zpool import -o cachefile=/tmp/zpool.cache zroot

mount -t zfs zroot/root /mnt

zfs mount -a


sh

cd /usr/freebsd-dist

export DESTDIR=/mnt

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

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


cp /tmp/zpool.cache /mnt/boot/zfs/zpool.cache

exit

Switch the zroot/var/empty zpool volume to read-only and then chroot into your newly installed system.

zfs set readonly=on zroot/var/empty

chroot /mnt

FreeBSD 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.privatebox" 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_

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. Finally let's tell the loader which zpool to boot from.

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

autoboot_delay="5" loader_logo="beastie" ahci_load="YES" geom_eli_load="YES" geom_mirror_load="YES" geom_label_load="YES" zfs_load="YES" vfs.root.mountfrom="zfs:zroot/root" _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

tzsetup

cd /etc/mail ; make aliases

exit

Finishing the Installation

Now that FreeBSD is installed lets setup the partitions that we designated as SWAP. For this we are going to gmirror(8) the partitions together, add them into fstab, and finally set some variables.

gmirror label -b prefer swap gpt/swap0 gpt/swap1

cat >> /mnt/etc/fstab << _EOF_>

# [Device] [Mountpoint] [FStype] [Options] [Dump] [Pass#] /dev/mirror/swap.eli none swap sw 0 0 _EOF_

Finally we need to setup the new mount points for each zpool and set the bootable volume. Afterwards go ahead and reboot(8).

zfs set mountpoint=/ zroot

zpool set bootfs=zroot/root zroot

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

  1. ^ "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/.