FreeBSD/install_zfs_gpt.md

Fri, 08 Sep 2017 09:34:13 +0200

author
David Demelier <markand@malikania.fr>
date
Fri, 08 Sep 2017 09:34:13 +0200
changeset 12
56b6b50c0d7e
parent 6
0c4833b61520
permissions
-rw-r--r--

FreeBSD: add example for jails in poudriere.md

FreeBSD ZFS on root with GPT
============================

This small guide will show you how to install FreeBSD on root using ZFS from a
FreeBSD shell.

You need to boot a FreeBSD shell userland, official FreeBSD ISOs have a shell
option when booting them.

Partitioning
------------

In this example, we will use one disk `/dev/ada0` and one swap partition of 4GB
size, adjust to your needs.

### Destroy and create GPT scheme

    gpart destroy -F ada0
    gpart create -s gpt ada0

### Add partitions

    gpart add -t freebsd-boot -s 128k -l boot0 ada0 
    gpart add -t freebsd-swap -s 4g -l swap0 ada0
    gpart add -t freebsd-zfs -l disk0 ada0
    gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada0

### Create zpool

    kldload zfs 
    zpool create -f -o altroot=/mnt -O canmount=off -m none zroot /dev/gpt/disk0 

### Create ZFS datasets

The following datasets are mandatory.

    zfs set checksum=fletcher4 zroot
    zfs set atime=off zroot
    zfs create -o mountpoint=none zroot/ROOT
    zfs create -o mountpoint=/ zroot/ROOT/default
    zpool set bootfs=zroot/ROOT/default zroot

The following datasets are optional.

    zfs create -o mountpoint=/tmp -o compression=lz4 -o setuid=off zroot/tmp
    zfs create -o mountpoint=/usr zroot/usr
    zfs create zroot/usr/local
    zfs create -o mountpoint=/home -o setuid=off   zroot/home
    zfs create -o compression=lz4 -o setuid=off zroot/usr/ports
    zfs create -o compression=off -o exec=off -o setuid=off zroot/usr/ports/distfiles
    zfs create -o compression=off -o exec=off -o setuid=off zroot/usr/ports/packages
    zfs create -o compression=lz4 -o exec=off -o setuid=off zroot/usr/src
    zfs create zroot/usr/obj
    zfs create -o mountpoint=/var zroot/var
    zfs create -o compression=lz4 -o exec=off -o setuid=off zroot/var/crash
    zfs create -o exec=off -o setuid=off zroot/var/db
    zfs create -o compression=lz4 -o exec=on -o setuid=off zroot/var/db/pkg
    zfs create -o exec=off -o setuid=off zroot/var/empty
    zfs create -o compression=lz4 -o exec=off -o setuid=off zroot/var/log
    zfs create -o compression=gzip -o exec=off -o setuid=off zroot/var/mail
    zfs create -o exec=off -o setuid=off zroot/var/run
    zfs create -o compression=lz4 -o exec=on -o setuid=off zroot/var/tmp

Required if you have created the following datasets.

    chmod 1777 /mnt/tmp
    chmod 1777 /mnt/var/tmp

Installation
------------

Now we will fetch our sets for FreeBSD, adjust the version, in this guide we
will use 11.1-RELEASE.

    cd /mnt
    fetch http://ftp.fr.freebsd.org/pub/FreeBSD/releases/amd64/11.1-RELEASE/base.txz
    fetch http://ftp.fr.freebsd.org/pub/FreeBSD/releases/amd64/11.1-RELEASE/kernel.txz
    tar xJpf base.txz
    tar xJpf kernel.txz

Configuration
-------------

Enter the chroot to do minimal mandatory steps.

### Setup root password

    chroot /mnt
    passwd

### Enable ZFS

    echo "/dev/gpt/swap0 none swap sw 0 0" >> /etc/fstab
    echo "zfs_load=YES" >> /boot/loader.conf
    echo "zfs_enable=YES" >> /etc/rc.conf

### Add an user (optional)

    pw useradd your_user -c "Real Name" -G wheel,operator -m
    passwd your_user

Terminate
---------

Exit the chroot and reboot.

    exit
    shutdown -r now

mercurial