Gentoo FreeBSD

From Gentoo Wiki
Jump to: navigation, search
Sometimes, Gentoo/FreeBSD's @system is broken.

Please get latest information from "Depends on" of bug #462580.

Gentoo/FreeBSD is a Gentoo system based on FreeBSD. It is FreeBSD with the following changes:

  • Portage replaces ports.
  • The base system is managed by portage.
  • Software in ./contrib and ./crypto is replaced with Gentoo Linux versions.
  • The rc system is replaced with OpenRC.
  • Python, wget and bash are included in the base system to support portage.
  • FreeBSD's bootloader is removed from the base system (useful for jails).
Gentoo FreeBSD is not 100% binary-compatibility with regular FreeBSD due to SONAME differences. It is possible to workaround that by running regular FreeBSD in either a jail or chroot on Gentoo FreeBSD or vice versa.

Gentoo FreeBSD is also not 100% script-compatible with regular FreeBSD by default. Script compatibility can be restored by installing sys-freebsd/ubin-wrappers. This makes it possible to use *BSD software like pkgsrc.


Introduction to FreeBSD

What is FreeBSD?

FreeBSD is a free (license) Unix-like operating system. Back in 1993 when development of 386BSD stopped, two projects were born: NetBSD, commonly known to run on a huge number of architectures, and FreeBSD which supports the x86, amd64, ia64, sparc64 and alpha platforms. FreeBSD is renowned for its stability, performance and security, thus being used from small to huge companies all over the world.

FreeBSD's current production release is version 10.1. Gentoo/FreeBSD is based on version 10.1 and older versions of Gentoo/FreeBSD are discontinued and no longer supported.

What is Gentoo/FreeBSD?

Gentoo/FreeBSD is a subproject of the Gentoo/Alt project, with the goal of providing a fully-capable FreeBSD operating system featuring design sensibilities taken from Gentoo Linux, such as the init system and the Portage package management system.

FreeBSD and Linux

Users migrating from Linux to FreeBSD commonly consider the two operating systems "almost the same". In fact, FreeBSD really shares a lot of similarities with Linux distributions in general. Nevertheless, it has some key differences that are worth noting:

  • Contrary to Linux, which actually only refers to the kernel, FreeBSD is a complete operating system, consisting of a C library, userland tools and much more. This development approach makes the overall system very consistent.
  • Contrary to the Linux kernel, FreeBSD development is not led by one person, but instead managed by a small group of people called the Core Team.

Besides, FreeBSD also has some technical differences which set it apart from Linux. Some of them are very important to know, even if you don't plan on joining the Gentoo/FreeBSD development effort:

  • To get run-time dynamic linking functions like dlopen(), programs do not need to be linked against libdl like on GNU/Linux. Instead they are linked against libc.
  • FreeBSD doesn't have an official tool for kernel compilation, thus you'll have to resolve feature dependencies on your own.
  • FreeBSD supports UFS/UFS2 and ZFS as native file systems.
  • FreeBSD also supports Linux filesystems, but you cannot install your system on them. ext2/ext3 supports read/write access. ReiserFS, XFS are read-only support. details please see FreeBSD's handbook 21.3. Linux® Filesystems


Part of x86-fbsd is out of date. Please install amd64-fbsd.


Since this guide has only minimal information, knowledge of both Gentoo/Linux and FreeBSD may be needed. The Gentoo/Linux Handbook and FreeBSD Handbook are your friends.


The installation media of FreeBSD 9.0 to which the LiveCD function was added are used for installation. Please get the more suitable one of i386 or amd64. Of course, -bootonly.iso can be used to install Gentoo/FreeBSD. Write to a CD or memory stick as necessary.

Boot the PC using the installation CD. Wait a moment while watching the boot process. Please choose Live CD, if a Welcome screen is displayed. Then login prompt, enter root.

If you have 4KB/sector HDD (aka AFT Drive)

Please select "2. [Esc]ape to loader prompt" at boot time if you have a 4KB/sector HDD.

Set the device name of your HDD with 4KB sectors in the boot loader. ada1 and ada2... to increase if you have more than one.


Optional: Setting keymap

If your keyboard is not an English 101 keyboard, please set keymap.

root #kbdcontrol -l uk.iso

A list of key map is available with the following command.

root #ls -1 /usr/share/syscons/keymaps | less

Network setting

First, create a directory /tmp/bsdinstall_etc to rewrite the resolv.conf.

root #mkdir -p /tmp/bsdinstall_etc

Identify your network devices. This example is em0.

root #ifconfig
em0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
        ether 00:00:00:00:00:00
        media: Ethernet autoselect (1000baseT <full-duplex>)
        status: active
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
        inet6 ::1 prefixlen 128
        inet6 fe80::1%lo0 prefixlen 64 scopeid 0x3
        inet netmask 0xff000000
        nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>

Set the default gateway and IP address.

If you not use DHCP (IP address is an example)

root #ifconfig em0
root #route add default
root #echo "nameserver" > /etc/resolv.conf (example used a Google Public DNS)

If you use DHCP

root #dhclient em0

Optional: want to install via ssh

So far we could not use ssh. If you want to install via ssh from this step.

root # mkdir -p /tmp/etc
root # mount -t tmpfs tmpfs /tmp/etc
root # mount -t unionfs /tmp/etc /etc
root # passwd
root # echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
root # /etc/rc.d/sshd onestart

Please connect with any ssh client. The username is root.

Setting the Partition

grub2 doesn't have KEYWORDS="~amd64-fbsd ~x86-fbsd" yet. sys-freebsd/boot0 is recommended for bootloader on Gentoo/FreeBSD.
If you want to use grub2, you need 1 MB free space at the beginning of the disk (MBR) or bios-boot partition (GPT).

grub2 can not find freebsd-boot partition. Please set the bios-boot (GPT).

The installation target device of serial ATA and IDE are /dev/ada*. SCSI and USB drive are /dev/da*. Please identify the HDD using ls /dev/ada* or dmesg | grep ada. In this case, the device is ada0.

root #dmesg | grep ada
ada0 at ata0 bus 0 scbus0 target 0 lun 0
ada0: <QEMU HARDDISK 0.15.> ATA-7 device
ada0: 16.700MB/s transfers (WDMA2, PIO 8192bytes)
ada0: 12288MB (25165824 512 byte sectors: 16H 63S/T 16383C)
ada0: Previously was known as ad0
If you want to use the UFS2 file system (GPT)
GPT partition is the standard FreeBSD 9.0. Please read the next MBR section if you want use MBR partition.

This example is simple only two partitions. If necessary, you can split /, /usr, /var, /tmp, and /home. Please set using gpart.

Partition Filesystem Size Description
/dev/ada0p1 none just a bit Reserved for bootloader
/dev/ada0p2 UFS2 + SU entire disk - swap space Root partition
/dev/ada0p3 swap Rest of the disk Swap partition
Please add options -a 4k to gpart add command of all, if you have AFT drive (4096 bytes/sector). Start of the partition is properly configured, you can get the best performance.
If you want to use FreeBSD's default bootloader. [Recommend]
root #gpart create -s GPT ada0
root #gpart add -s 64k -t freebsd-boot ada0
root #gpart add -s 10G -t freebsd-ufs -l root ada0
root #gpart add -t freebsd-swap -l swap ada0

Please run gpart show in order to verify the partition could be set.

root #gpart show
=>      34  25165757  ada0  GPT  (12G)
        34       128     1  freebsd-boot  (64k)
       162  20971520     2  freebsd-ufs  (10G)
  20971682   4194109     3  freebsd-swap  (2G)

Results when you create a partition with option -a 4k.

root #gpart show
=>      34  25165757  ada0  GPT  (12G)
        34         6        - free -  (3.0k)
        40       128     1  freebsd-boot  (64k)
       168  20971520     2  freebsd-ufs  (10G)
  20971688   4194096     3  freebsd-swap  (2G)
  25165784         7        - free -  (3.5k)
If you want to use grub2. [Experimental]
root #gpart create -s GPT ada0
root #gpart add -s 1024k -t bios-boot ada0
root #gpart add -s 10G -t freebsd-ufs -l root ada0
root #gpart add -t freebsd-swap -l swap ada0
If you want to use the UFS2 file system (MBR)
Partition Filesystem Size Description
/dev/ada0s1a UFS2 + SU entire disk - swap space Root partition
/dev/ada0s1b swap Rest of the disk Swap partition
If you want to use FreeBSD's default bootloader. [Recommend]
root #gpart create -s mbr ada0
root #gpart add -t freebsd ada0
root #gpart set -a active -i 1 ada0
root #gpart create -s bsd ada0s1
root #gpart add -s 10G -t freebsd-ufs ada0s1
root #gpart add -t freebsd-swap ada0s1
If you want to use grub2. [Experimental]
root #gpart create -s mbr ada0
root #gpart add -b 1024k -t freebsd ada0
root #gpart set -a active -i 1 ada0
root #gpart create -s bsd ada0s1
root #gpart add -s 10G -t freebsd-ufs ada0s1
root #gpart add -t freebsd-swap ada0s1
If you want to use the ZFS file system (experimental) / (GPT)
If you want to use FreeBSD's default bootloader. [Recommend]
root #gpart create -s GPT ada0
root #gpart add -s 64k -t freebsd-boot ada0
root #gpart add -t freebsd-zfs -l zfs-system ada0
If you want to use grub2. [Experimental]
root #gpart create -s GPT ada0
root #gpart add -s 1024k -t bios-boot ada0
root #gpart add -t freebsd-zfs -l zfs-system ada0

Creating and mounting a file system

If you want to use the UFS2 file system

Please do not forget newfs -L option to label.

Add option -j to newfs if you want to enable soft updates journaling. Add option -t if you want to enable TRIM.

Your choice GPT)

root #newfs -L gfbsdroot -U /dev/ada0p2

Your choice MBR)

root #newfs -L gfbsdroot -U /dev/ada0s1a

And mount it.

root #mount /dev/ufs/gfbsdroot /mnt
root #swapon /dev/gpt/swap (GPT)
root #swapon /dev/ada0s1b (MBR)
If you want to use the ZFS file system (experimental)

Load the kernel module in order to enable ZFS.

root #kldload zfs

Prepare the RAM disk to write /boot/zfs/zpool.cache.

root #mount -t tmpfs tmpfs /boot/zfs

Please use gnop if you have 4KB/sector HDD. You can get the best performance.

root #gnop create -S 4096 /dev/gpt/zfs-system

Creates a new storage pool. if you are using gnop, please specify /dev/gpt/zfs-system.nop instead of /dev/gpt/zfs-system.

root #zpool create zsys /dev/gpt/zfs-system
root #zfs set mountpoint=none zsys

Creates a new ZFS file system.

root #zfs create zsys/root
root #zfs set mountpoint=/mnt zsys/root
root #zfs mount -a
root #zfs create zsys/root/usr
root #zfs create zsys/root/var
root #zfs create zsys/root/tmp
root #zfs create zsys/home
root #zfs create -V 8gb zsys/swap
root #zfs set org.freebsd:swap=on zsys/swap
root #zfs set checksum=off zsys/swap
root #mkdir /mnt/home
root #mount -t zfs zsys/home /mnt/home

Downloading the Stage3 Tarball and Portage snapshot

Now, Gentoo/FreeBSD 9.0 stage3 is available for x86-fbsd. And Gentoo/FreeBSD 9.1 stage3 is available for amd64-fbsd.

If you want to use amd64-fbsd, please upgrade to 10.1 after the installation is complete. FreeBSD 9.1 is EOL on December 31, 2014. If you want to use x86-fbsd, please upgrade to 10.1 after the installation is complete. FreeBSD 9.0 is EOL on March 31, 2013.

Unpacking stage3 and Portage snapshot

The following error may be displayed. But, please continue the installation don't worry. This problem will be fixed in 9.2. Details, see bug #469454
./bin/fuser: Can't create 'bin/fuser'
tar: Error exit delayed from previous errors.
root #cd /mnt
root #setenv LANG "en_US.UTF-8"
root #tar xjpf stage3-*.tar.bz2 -C /mnt
root #tar xjf portage-latest.tar.bz2 -C /mnt/usr

Entering the new Environment

root #mount -t devfs devfs /mnt/dev
root #cp /etc/resolv.conf /mnt/etc/
root #chroot /mnt /bin/bash

Settings and install more in chroot environment

The first settings and time zone settings

env-update and time zone settings. Of course, you can modify /etc/portage/make.conf.

(chroot) root #env-update && source /etc/profile
(chroot) root #cp /usr/share/zoneinfo/GMT /etc/localtime (please select your time zone)
(chroot) root #emerge -u sys-apps/portage ; emerge sys-devel/libtool app-admin/eselect
(chroot) root #emerge app-editors/nano
(chroot) root #mv /etc/make.conf /etc/portage/ (if /etc/make.conf is exist.)
(chroot) root #nano -w /etc/portage/make.conf (if necessary)

Bug fixes (for x86-fbsd users, 9.0 stage3 only)

Bugs have been fixed in several packages. Please upgrade them. For details, see bug #324445, bug #412319, bug #417031 and bug #421191.

(chroot) root #emerge sys-devel/gcc-config
(chroot) root #emerge sys-freebsd/freebsd-mk-defs sys-freebsd/freebsd-lib app-arch/libarchive dev-libs/libedit

Special settings for ZFS

If you select ZFS file system, the following additional work is required.

(chroot) root #emerge flaggie
(chroot) root #flaggie +zfs
(chroot) root #emerge sys-devel/flex
(chroot) root #emerge sys-freebsd/freebsd-cddl
(chroot) root #emerge sys-freebsd/freebsd-lib sys-freebsd/freebsd-ubin sys-freebsd/boot0

Installing a kernel source

Unlike Gentoo/Linux, freebsd-sources package is the only sources.

(chroot) root #USE=symlink emerge freebsd-sources

Compiling and installing kernel

Now let's compile the kernel. Copy the GENERIC in conf, you can change it by changing the kernel configuration. For more information see the FreeBSD Handbook.

(chroot) root #emerge -u sys-devel/flex
(chroot) root #cd /usr/src/sys/i386/conf (case of x86-fbsd)
(chroot) root #cd /usr/src/sys/amd64/conf (case of amd64-fbsd)
(chroot) root #cp GENERIC.hints /boot/device.hints
(chroot) root #config GENERIC
(chroot) root #cd ../compile/GENERIC
(chroot) root #make cleandepend && make depend && make -j3 && make install

System setting

Familiar setting. Please refer to Gentoo Linux Handbook if you need more information.

If you select UFS2

(chroot) root #nano -w /etc/fstab
# Device	Mountpoint	FStype	Options	Dump	Pass#
/dev/ufs/gfbsdroot	/		ufs	rw	1	1

#your choice GPT (don't forget comment out)
#/dev/gpt/swap	none		swap	sw	0	0

#your choice MBR (don't forget comment out)
#/dev/ada0s1b	none		swap	sw	0	0

If you select ZFS. Note that the Pass# column should be zero for ZFS, because it cannot be checked by fsck.

(chroot) root #nano -w /etc/fstab
# Device	Mountpoint	FStype	Options	Dump	Pass#
#/dev/ad0s1a	/		ufs	rw	1	1
#/dev/ad0s1b	none		swap	sw	0	0
zsys/root	/		zfs	rw	0	0

Setting the host name

(chroot) root #nano -w /etc/conf.d/hostname
# (Set the hostname variable to your host name.  On BSD this is expected to be the FQDN.)

Editing network setting

(chroot) root #nano -w /etc/conf.d/net
# (Set the dns_domain variable to your domain name)

# Manually setting)
config_em0=" netmask"
routes_em0="default via"

# Using DHCP)

Adding net.em0 to the default runlevel

(chroot) root #cd /etc/init.d
(chroot) root #ln -s net.lo0 net.em0
(chroot) root #rc-update add net.em0 default

Setting keymap

Please edit /etc/conf.d/syscons if you want to change keymap.

(chroot) root #nano -w /etc/conf.d/syscons

A list of key map is available with the following command.

(chroot) root #ls -1 /usr/share/syscons/keymaps | less

Setting the root password

(chroot) root #passwd

Adding a User for Daily Use (sample)

(chroot) root #adduser
Username: nigoro
Full name:
Uid (Leave empty for default):
Login group [nigoro]:
Login group is nigoro. Invite nigoro into other groups? []: wheel
Login class [default]:
Shell (bash csh esh fish ksh sash sh tcsh zsh nologin) [sh]: bash
Home directory [/home/nigoro]:
Home directory permissions (Leave empty for default):
Use password-based authentication? [yes]:
Use an empty password? (yes/no) [no]:
Use a random password? (yes/no) [no]:
Enter password:
Enter password again:
Lock out the account after creation? [no]:
Username   : nigoro
Password   : *****
Full Name  :
Uid        : 1001
Class      :
Groups     : nigoro wheel
Home       : /home/nigoro
Home Mode  :
Shell      : /bin/bash
Locked     : no
OK? (yes/no): yes
adduser: INFO: Successfully added (nigoro) to the user database.
Add another user? (yes/no): no

You can also be configured to run at startup sshd.

(chroot) root #emerge -u net-misc/openssh
(chroot) root #rc-update add sshd default
Special settings for ZFS

If you select ZFS file system, the following additional work is required.

(chroot) root #rc-update add zfs boot
(chroot) root #rc-update add zvol default
(chroot) root #echo 'zfs_load="YES"' >> /boot/loader.conf
(chroot) root #echo 'vfs.root.mountfrom="zfs:zsys/root"' >> /boot/loader.conf
Special settings for virtual machine

If you are installing on a virtual machine, require additional configuration.

(chroot) root #echo 'kern.hz=100' >> /boot/loader.conf

Installing the required packages

If dhcpcd is required if you use DHCP.

(chroot) root #emerge net-misc/dhcpcd

Installing the boot loader

Let's install a boot loader to boot the Gentoo/FreeBSD.

(chroot) root #emerge sys-freebsd/boot0

Please see this section if you want to use grub2. But it is experimental!

Setting boot loader

Let's prepare for using sys-freebsd/boot0.

If you select UFS2 (GPT)

(chroot) root #gpart bootcode -b /boot/pmbr ada0
(chroot) root #gpart bootcode -p /boot/gptboot -i 1 ada0

If you select UFS2 (MBR)

(chroot) root #gpart bootcode -b /boot/boot0 ada0
(chroot) root #gpart bootcode -b /boot/boot ada0s1

If you select ZFS (GPT)

(chroot) root #gpart bootcode -b /boot/pmbr ada0
(chroot) root #gpart bootcode -p /boot/gptzfsboot -i 1 ada0

Exit from chroot environment

Work done in the chroot environment. exit from chroot environment.

(chroot) root #exit

Cleaning up and setting the remaining

Do you want to reboot now ? Just a minute. ZFS user must have setting a little more.

Special settings for ZFS

If you select ZFS file system, the following additional work is required.

root #umount /mnt/dev
root #cd /
root #zpool set bootfs=zsys/root zsys
root #zpool export zsys
root #gnop destroy /dev/gpt/zfs-system.nop (please run if you are using gnop)
root #zpool import zsys
root #mkdir /mnt/boot/zfs
root #cp /boot/zfs/zpool.cache /mnt/boot/zfs/
root #zfs unmount -a
root #zfs set mountpoint=none zsys
root #zfs set mountpoint=/usr zsys/root/usr
root #zfs set mountpoint=/var zsys/root/var
root #zfs set mountpoint=/tmp zsys/root/tmp
root #zfs set mountpoint=/home zsys/home
root #zfs set mountpoint=legacy zsys/root


Don't have a problem? Now we restart. Don't forget to remove the Installation CD of FreeBSD.

root #shutdown -r now

Howto run G/FBSD in vanilla FreeBSD's jail

Details of jail, please see the FreeBSD Handbook.

Preparing directory

root #mkdir -p /usr/jail/gfbsd
root #cd /usr/jail/gfbsd

Downloading and Unpacking the Stage3 Tarball and Portage snapshot

root #tar xjpf stage3-*.tar.bz2
root #tar xjf portage-latest.tar.bz2 -C /usr/jail/gfbsd/usr


Configure jail to start with FreeBSD.

FILE /etc/rc.confExample for start automatically jail
# You will also need to add the following line if you need network access.
# em0, please specify your network devices.

Setting to operate Gentoo/FreeBSD in jail.

root #echo 'rc_sys="jail"' >> /usr/jail/gfbsd/etc/rc.conf
root #echo 'hostname="gfbsd"' > /usr/jail/gfbsd/etc/conf.d/hostname
root #echo 'syslogd_args="-ss"' >> /usr/jail/gfbsd/etc/conf.d/syslogd
root #chroot /usr/jail/gfbsd /bin/bash
(chroot) root #rc-update add vixie-cron default
(chroot) root #exit

run jail

Let's run jail.

root #/etc/rc.d/jail start

Verify that worked.

root #jls
   JID  IP Address      Hostname                      Path
     1    gfbsd                         /usr/jail/gfbsd

To enter the jail environment will use the jexec command.

root #jexec 1 /bin/bash

Upgrade howto

This guide will show you how to upgrade Gentoo/FreeBSD 10.1 from previous version.

This guide is targeted to version 9.0 or higher.


Change to latest profile

To emerge related to FreeBSD 10.1 is necessary to change the profile.

Get a list of available profiles:

root #eselect profile list
Available profile symlink targets:
  [1]   default/bsd/fbsd/x86/9.1
  [2]   default/bsd/fbsd/x86/9.2
  [3]   default/bsd/fbsd/x86/10.1

Set the profile of 10.1:

root #eselect profile set 3

Updating sys-apps/portage

Please check first, what will be installed.

root #emerge -pu sys-apps/portage
[ebuild     UD] sys-apps/portage- [2.2_rc49] USE="(ipc%*) (-pypy1_9) -python2% -xattr%"

After confirming that masked by: EAPI error does not appear, please upgrade.

Please add --exclude sys-freebsd/* option if failed messages sys-freebsd packages are mask is displayed.

root #emerge -u sys-apps/portage

Successfully updated, please check the version.

root #emerge --version
Portage (default/bsd/fbsd/x86/9.1, gcc-4.4.2, freebsd-lib-7.2, 9.1_rc3-Gentoo i386)

need version 2.2. If it is not 2.2, update portage again.

root #emerge -u sys-apps/portage --exclude sys-freebsd/*

Recheck the version.

root #emerge --version
Portage 2.2.0_alpha144 (default/bsd/fbsd/x86/9.1, gcc-4.4.2, freebsd-lib-7.2, 9.1_rc3-Gentoo i386)

In addition, check that it includes preserve-libs to FEATURES. If it does not, please add FEATURES="preserve-libs" in make.conf.

Please be sure to check whether preserve-libs is set to FEATURES. If it is not set, then your system will not work because required libraries are removed.
root #emerge --info | grep FEATURES= | grep preserve-libs
FEATURES="assume-digests binpkg-logs chflags config-protect-if-modified distlocks ebuild-locks fixlafiles merge-sync news parallel-fetch preserve-libs protect-owned sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch"
For too old x86-fbsd stages.

Currently, profile requests EAPI=5. However, not very old x86 stage support it. Please forcibly update the portage.

root #emerge -pu sys-apps/portage
!!! Unable to parse profile: '/etc/portage/make.profile'
!!! ParseError: Profile contains unsupported EAPI '5': '/usr/portage/profiles/default/bsd/fbsd/x86/10.1/eapi'
!!! Your current profile is invalid. If you have just changed your profile
!!! configuration, you should revert back to the previous configuration.
!!! Allowed actions are limited to --help, --info, --search, --sync, and
!!! --version.
root #cd /tmp
root #tar xjf portage-2.2.18.tar.bz2
root #PYTHON_TARGETS="python2_7" portage-2.2.18/bin/emerge --nodeps dev-lang/python-exec
root #PYTHON_TARGETS="python2_7" portage-2.2.18/bin/emerge --nodeps sys-apps/portage

Move /etc/make.conf

Recently, /etc/make.conf has been moved to /etc/portage/make.conf. If it exists in /etc, please move it.

In addition, remove LDFLAGS from make.conf. If it is set, upgrade may fail.

root #mkdir -p /etc/portage
root #if [ -e /etc/make.conf ] && [ ! -e /etc/portage/make.conf ] ; then
root #mv /etc/make.conf /etc/portage/make.conf
root #fi
root #gsed -i '/LDFLAGS=/d' /etc/portage/make.conf

Package updates the minimum required

update the minimal packages needed to upgrade.

root #emerge sys-freebsd/freebsd-mk-defs
root #emerge -u sys-apps/findutils --exclude sys-freebsd/*
root #emerge sys-devel/libtool --exclude sys-freebsd/*
root #emerge -u sys-devel/flex sys-devel/patch sys-devel/m4 net-libs/libpcap sys-devel/gettext app-arch/libarchive --exclude sys-freebsd/*
root #emerge sys-devel/libtool --exclude sys-freebsd/*

Kernel update

First of all, you need to update your kernel. It is because the package of a userland may use the new function of a kernel.

Please be sure to update a kernel first !

clang is required for kernel compile. clang requires gcc-4.7 or higher. Please update the gcc if old.

Please try clang-3.4.x if latest clang fails to compile.

root #emerge -C freebsd-sources
root #emerge binutils --exclude sys-freebsd/*
root #emerge sys-devel/clang --exclude sys-freebsd/*
root #emerge --nodeps freebsd-sources

failed to compile the kernel

Please get the GENERIC kernel of FreeBSD if you fail to compile the kernel. If you are using amd64-fbsd, please replace the i386 to amd64 in URL.

Don't forget to rebuild the kernel after updating FreeBSD userland!
root #mv /boot /boot.orig
root #cd /
root #tar xvJf /tmp/base.txz ./boot
root #tar xvJf /tmp/kernel.txz


Don't have a problem? Now we restart.

root #shutdown -r now

After rebooting your machine, please check if the kernel is new.

root #uname -a
FreeBSD daemon 10.1-Gentoo FreeBSD Gentoo 10.1 #0: Fri Jan 20 00:01:04 JST 2012
     root@daemon:/var/tmp/portage/sys-freebsd/freebsd-sources-10.1/work/sys/amd64/compile/GENTOO  amd64

Prepare of multilib (for amd64-fbsd users)

Do not skip this chapter!

If you're using the old amd64-fbsd stage before multilib migration, additional steps are required.

Let's check.

root #[[ ! -e /libexec/ ]] && echo "need prepare multilib"

Please execute additional when "need prepare multilib" is displayed.

root #[[ ! -e /etc/portage/profile ]] && mkdir -p /etc/portage/profile
root #echo "sys-freebsd/freebsd-libexec abi_x86_32" >> /etc/portage/profile/package.use.mask

Updating FreeBSD userland

The first emerge the core library.

root #emerge -C dev-libs/libelf dev-libs/libexecinfo dev-libs/libiconv
root #emerge binutils
root #emerge --nodeps sys-freebsd/freebsd-libexec
root #USE=build emerge --nodeps sys-freebsd/freebsd-lib sys-freebsd/freebsd-share
root #[[ -e /etc/portage/profile/package.use.mask ]] && gsed -i '/sys-freebsd\/freebsd-libexec abi_x86_32/d' /etc/portage/profile/package.use.mask

Update the userland of FreeBSD.

root #emerge -C sys-process/fuser-bsd
root #emerge -auN boot0 freebsd-bin freebsd-lib freebsd-libexec freebsd-mk-defs freebsd-pam-modules freebsd-sbin freebsd-share freebsd-ubin freebsd-usbin

Please to emerge again sys-freebsd packages. Some of the package is in need of include files of 10.1, did not use it when the upgrade.

root #emerge boot0 freebsd-bin freebsd-lib freebsd-libexec freebsd-mk-defs freebsd-pam-modules freebsd-sbin freebsd-share freebsd-ubin freebsd-usbin

Cleanup, utmp related files

root #rm /var/run/utmp /var/log/lastlog /var/log/wtmp*

Change CHOST and rebuild toolchain

You can skip this step if you are minor upgrading. Please next Cleaning step.

Change CHOST, and emerge binutils gcc. (FYI, Changing the CHOST variable)

x86-fbsd users)

root #gsed -i 's:CHOST=.*:CHOST="i686-gentoo-freebsd10.1":g' /etc/portage/make.conf

amd64-fbsd users)

root #gsed -i 's:CHOST=.*:CHOST="x86_64-gentoo-freebsd10.1":g' /etc/portage/make.conf

emerge binutils gcc

root #emerge --oneshot sys-devel/binutils sys-devel/gcc

check gcc's 9.x stuff

root #gcc-config -l
  [1] i686-gentoo-freebsd10.1-4.8.4 *
 * broken config file: /etc/env.d/gcc/i686-gentoo-freebsd9.0-4.5.3
 [2] i686-gentoo-freebsd9.0-4.5.3

remove 9.x stuff.

root #emerge -C '<gcc-4.6'
root #gcc-config -c

also check binutils

root #binutils-config -l
  [1] i686-gentoo-freebsd10.1-2.25 *
root #binutils-config -c

remove FreeBSD 9.x env data.

root #cd /etc/env.d/
root #grep gentoo-freebsd9. *

target file name is 04gcc-i686-gentoo-freebsd9.0 in this case.

root #rm 04gcc-i686-gentoo-freebsd9.0
root #env-update && source /etc/profile

Recreate all packages.

root #emerge sys-devel/libtool
root #emerge -ae @world --exclude sys-apps/portage
root #emerge sys-apps/portage

Failure to compile the package if any, 'emerge --resume --skipfirst' is your friend. Also, please bug report the problem if you like.

If emerge fails to compile sys-freebsd/boot0, please see #Troubleshooting.


Let's remove the backup files when you have finished all the steps.

don't forget etc-update !
root #emerge sys-devel/libtool app-admin/eselect
root #emerge @preserved-rebuild
root #etc-update

Re-select profile

Please re-select the profile if make.profile exists in /etc.

root #ls -l /etc/make.profile
lrwxr-xr-x  1 root  portage  48 Dec  1 00:00 /etc/make.profile -> ../usr/portage/profiles/default/bsd/fbsd/x86/9.1
root #rm /etc/make.profile
root #eselect profile list
Available profile symlink targets:
  [1]   default/bsd/fbsd/x86/9.0
  [2]   default/bsd/fbsd/x86/9.1
root #eselect profile set 2

Experimental Zone

How to use X Window System with vesa video card

Please update wiki if you know a better way. Also welcome to fix the problem. Please file a bug.
root #emerge portage ; emerge libtool app-admin/eselect
root #mv /etc/make.conf /etc/portage/make.conf (be careful !)
root #emerge -u flaggie
root #flaggie +python +X
root #echo 'INPUT_DEVICES="keyboard mouse"' >> /etc/portage/make.conf
root #echo 'VIDEO_CARDS="vesa"' >> /etc/portage/make.conf
root #emerge -p xorg-x11
root #emerge xorg-x11
root #emerge xterm twm xclock

If you are using a USB mouse, please load kernel module first.

root #kldload ums
root #echo 'ums_load="YES"' >> /boot/loader.conf


root #Xorg -configure
root #mv /root/ /etc/X11/xorg.conf

Check the device for mouse

root #grep /dev /etc/X11/xorg.conf
        Option      "Device" "/dev/sysmouse"

OK, In this case /dev/sysmouse has been detected.

root #/etc/init.d/moused start
root #rc-update add moused default
root #startx

Other video cards

xf86-video-vmware) Please see bug #477604.

xf86-video-virtualbox) Please check my experimental overlay.

xf86-video-intel) Please see bug #493436.


Q. mouse does not work

A. PS/2 mouse is /dev/psm0. USB mouse is /dev/ums0. Another one is /dev/sysmouse. Please specify in xorg.conf correctly. You need to start moused to use /dev/sysmouse. Run /etc/init.d/moused start.

Portage Overlay

Gentoo/BSD Project Overlay
It is the official overlay. Good quality, it contains bugfixes for e.g. system packages. You can add using layman -a gentoo-bsd.
nigoro's Gentoo/FreeBSD experimental overlay
It is a highly experimental overlay. Bad quality, but most packages work. List of tested packages. You can add using layman -a nigoro-fbsd

Experimental clang stages

clang stages is using clang as the system compiler. It's very experimental.

clang stages is available from the following URL:

Please see bug list and page Clang. In addition, please report to Gentoo Bugzilla if you find a package that can not be compiled with clang.

Bug list

  • bug #417795: dev-libs/openssl-1.0.0j and dev-libs/openssl-1.0.1c fail to build with Clang
  • bug #474486: dev-libs/libgcrypt-1.5.2-r1: build fails with using clang-3.3 on x86-fbsd
  • bug #417789: [TRACKER] Packages that fail to build with LLVM/Clang on Gentoo FreeBSD

How to migrate from amd64/9.1 profile to amd64/9.1/clang

Please check bug #474042 first. Please apply patches attached to the bug.
root #emerge -a sys-devel/clang sys-libs/libcxx
root #CC=clang CXX="clang++ -stdlib=libc++" emerge -B sys-devel/llvm sys-devel/clang
root #emerge -K sys-devel/llvm sys-devel/clang
root #eselect profile set default/bsd/fbsd/amd64/9.1/clang

Why make the package once ?

When compiled with CXX="clang++ -stdlib=libc++" to llvm or clang, clang command does not work at all (Segmentation fault occurs always).

When set CXX="clang++ -stdlib=libc++", in order to successfully compile them, should both be linked to

How to use sys-boot/grub2

Install grub2

root #mkdir -p /etc/portage/package.keywords /etc/portage/patches/sys-boot/grub
root #echo "=sys-boot/grub-2.00_p5107* amd64" >> /etc/portage/package.keywords/grub
root #emerge sys-boot/grub

Configure grub2

If you select UFS2 (GPT)

root #grub2-install --modules="part_gpt fat ufs2" --no-floppy /dev/ada0
root #grub2-mkconfig -o /boot/grub/grub.cfg

If you select UFS2 (MBR)

root #grub2-install --modules="biosdisk part_msdos bsd search_fs_uuid ufs2 msdospart" --no-floppy /dev/ada0
root #grub2-mkconfig -o /boot/grub/grub.cfg

If you select ZFS (GPT)

root #grub2-install --modules="part_gpt fat zfs" --no-floppy /dev/ada0
root #grub2-mkconfig -o /boot/grub/grub.cfg

Developing for Gentoo/FreeBSD

How to help

There are many things you could help with, depending on your skill level and spare time:

  • Working on current ebuilds: this means working closely with ebuild maintainers in order to create patches or modify ebuilds in a way that can be accepted into the main tree.
  • Security: if you are into security, we need you! Although security advisories from the FreeBSD project are tracked and fixed, we can always use help in this area.
  • Contacts: we need people who can get in touch with FreeBSD developers to maintain contacts between us and the original project to exchange patches and discuss various problems and their solutions. Note that this should never involve any kind of spamming of mailing lists or IRC channels.
  • Testing: the more people are actively using Gentoo/FreeBSD, the more bugs will be discovered, which helps us improving the quality of the port. If you are good at describing bugs or problems, we definitely want to hear from you.
  • Other areas where we need help include: system ebuilds, creation of installation CDs, documentation, kernel hacking.



All commands is not working after emerge sys-apps/baselayout

After failing to emerge baselayout, all commands will not work. Details, see bug #436560

root #ls
Shared object "" not found, required by "ls"

If you have not restarted the PC, please run this command first.

root #export LD_LIBRARY_PATH="/lib64:/usr/lib64"

If you restart or turn off your PC already has a need to restore your system using the installation CD of FreeBSD.

  1. boot using the installation media of FreeBSD.
  2. Live CD select
  3. Mount the root partition of G/FBSD (e.g. mount /dev/ufs/gfbsdroot /mnt)
  4. cd /mnt (Please replace to /mnt/, /mnt/usr, ... from /, /usr, ...)

Please check lib in /, /usr, /usr/local.

root #ls -l /lib /usr/lib /usr/local/lib
ls: /lib: No such file or directory
lrwxr-xr-x  1 root  wheel  5 Oct 14 06:41 /usr/lib -> lib64

lrwxr-xr-x  1 root  wheel  5 Oct 14 06:41 /usr/local/lib -> lib64

In this case, the symbolic link /lib is simply removed. Let's re-create symbolic link /lib.

root #ln -s lib64 /lib

You need to migrate from lib64 to lib before run emerge baselayout so far. Run the script for migration.

If you have to recover by using FreeBSD's installation media, please enter in G/FBSD run chroot /mnt !

root #bash /tmp/
root #emerge sys-apps/baselayout

can not boot a kernel panic always occurs

Details, see bug #408019

workaround is to use gcc 4.3 or clang to compile the kernel.

amd64 kernel + x86 stage environment, tar will not work successfully.

Details, see bug #444918

Error messages:

tar: getvfsbyname failed: No such file or directory
tar: Error exit delayed from previous errors.

workaround fix

root #emerge =libarchive-3.0.3

gcc fails to compile, Error message is recompile -fPIC

Details, see bug #415185 .

workaround fix

root #emerge --ask sys-devel/gcc

Architecture Independent Issues

The kernel fails to mount a ZFS root filesystem with error 2

Your /boot/zfs/zpool.cache file is missing information about the pool containing your root filesystem.

Boot a FreeBSD LiveCD and enter the shell. Then import your pool using the name of your pool intead of "rpool":

root #zpool import -f -N rpool

Inform ZFS what your root dataset is using its name instead of "rpool/ROOT/freebsd":

root #zfs set mountpoint=/ rpool/ROOT/freebsd

Export the pool

root #zpool export rpool

Import the pool again, except this time over your Live CD's root filesystem:

root #zpool import rpool

Now force the system to reboot and it should work. This procedure originally described on the FreeBSD forums.

Emerge fails net-misc/openssh

Details, see bug #391011

workaround fix for openssh

root #EXTRA_ECONF='--disable-utmp --disable-wtmp' emerge '>net-misc/openssh-6.0'

Another issue. If the following error message is displayed, please try EXTRA_ECONF='--disable-lastlog'

loginrec.c: In function 'lastlog_openseek':
loginrec.c:1506:46: error: invalid application of 'sizeof' to incomplete type 'struct lastlog'
loginrec.c: In function 'lastlog_write_entry':
loginrec.c:1536:17: error: storage size of 'last' isn't known
loginrec.c:1536:17: warning: unused variable 'last' [-Wunused-variable]
loginrec.c: In function 'lastlog_get_entry':
loginrec.c:1589:17: error: storage size of 'last' isn't known
loginrec.c:1589:17: warning: unused variable 'last' [-Wunused-variable]

Emerge fails app-misc/screen

Details, see bug #393039 and bug #409819.

Please use app-misc/tmux instead of app-misc/screen.

lex: not found

root #emerge --ask sys-devel/flex

cc: not found

Details, see bug #412319

root #emerge '>=sys-devel/gcc-config-1.7.1'

Emerge fails sys-freebsd/boot0 using >gcc-4.6

Details, see bug #409815


root #emerge -u '<sys-devel/gcc-4.6'
root #CC=gcc-4.5.4 emerge boot0


See also