Quickly test FreeBSD 11 with KMS/VT (NewCons) support, hald and your keyboard layout


Warning: Missing argument 2 for Jetpack_AMP_Support::render_sharing_html() in /home/content/15/11463415/html/site/wp-content/plugins/jetpack/3rd-party/class.jetpack-amp-support.php on line 302

This is my super short how to install the latest X.org on FreeBSD 11 with KMS, hald enabled and a particular keyboard layout. Want to make a quick test on KVM/virt-manager or on your spare system with Intel or Radeon graphics? Here you go.

First of all, if you haven’t done it already, install the latest FreeBSD 11 image that contains VT (NewCons) support already built in. It rockes. The images are downloadable from here, just make sure to choose the image that has “VT” in the name.

ftp://ftp.freebsd.org/pub/FreeBSD/snapshots/amd64/amd64/ISO-IMAGES/11.0/

From FreeBSD 11 we will have everything required to run on the latest and greatest platforms, that is:

* VirtIO drivers (network, block devices, PCI and memory ballooning) for KVM/libvirt/virt-manager on Linux already integrated in the kernel
* Intel KMS drivers for Intel chipsets (loadable as modules)
* Radeon KMS drivers for discrete and AMD APU integrated Radeon chipsets (loadable as modules)

Install the latest X.org

Use PKGNG and install the latest and greatest xorg meta package. This will pull in all additional requirements:

# pkg install xorg

After installing, add the proper startup lines for DBus and Hald. People tend to disable Hald to set different keyboard layouts, but it’s not actually true. By disabling Hald and the option to auto add devices you lose the ability to dock and undock your laptop and things like that.

To start the services at boot add the following two lines in /etc/rc.conf:

dbus_enable="YES"
hald_enable="YES"

Then start the services:

service dbus start
service hald start

Now you can plug and unplug your devices while the system is running.

Load your appropriate KMS driver

The examples here use both Intel and Radeon drivers, just use the one for the hardware you have, or add them both, it makes no harm. Simply the driver will not be used.

Type one the following commands in a root shell to load the appropriate drivers:

kldload i915kms
kldload radeonkms

Your screen should change and you should have now a nice prompt on the native resolution of your monitor. To load the module at boot, edit the file /boot/loader.conf and add these lines:

i915kms_load="YES"
radeonkms_load="YES"

Configure your keyboard layout

By googling around I could not find an easy yet clean solution for having hot plug capabilities in X and at the same time set my keyboard layout. By looking at a Fedora system, I discovered that is actually very simple. Just create an /etc/X11/xorg.conf file with the following content (set the XkbLayout option to your desired language):

Section "InputClass"
        Identifier "system-keyboard"
        MatchIsKeyboard "on"
        Option "XkbLayout" "it"
EndSection

This will create a rule to match all keyboards attached to the system and set the appropriate layout. Easy, isn’t it?

Now start X in your preferred way, xinit, startx or whatever.

FreeBSD 10.0-CURRENT X.org repository (amd64)


Warning: Missing argument 2 for Jetpack_AMP_Support::render_sharing_html() in /home/content/15/11463415/html/site/wp-content/plugins/jetpack/3rd-party/class.jetpack-amp-support.php on line 302

I’ve just pushed a repository to the site that contains the very latest X.org packages for FreeBSD 10.0. All packages have been built with poudriere. The repository contains the following ports:

x11/xorg
x11/xorg-minimal
x11/nvidia-driver
x11/nvidia-settings
x11/nvidia-xconfig
multimedia/vdpauinfo
multimedia/libva
ports-mgmt/poudriere-devel

It should be everything required for running an (experimental) updated X.org stack on FreeBSD 10. Packages are built with the following /etc/make.conf settings:

SVN=/usr/bin/svnlite
SVN_UPDATE=yes
WITH_NEW_XORG=yes
WITH_KMS=yes
WITH_GALLIUM=yes
MALLOC_PRODUCTION=yes

The ports tree used to build all packages is generated from this:

  • Updated ports tree at 24th September 2013.
  • Niclas Zeising’s patch revision of 24th September 2013 that updates all the Mesa stack and enables experimental devd configuration of devices for FreeBSD 10.
  • Updated Nvidia driver and utilities at version 325.15.

Please note that the repository is for amd64 platforms only.

To enable the repository just add/replace this line to your current PKGNG repository configuration:

packagesite: http://negativo17.org/freebsd/xorg/

Currently, the proprietary Nvidia driver make my system crash on me with the following messages in the log; any hint for solving it would be greatly appreciated:

kernel: nvidia0:  on vgapci0
kernel: vgapci0: child nvidia0 requested pci_enable_io
kernel: vgapci0: child nvidia0 requested pci_enable_io
kernel: ACPI Warning: \_SB_.PCI0.AGP_.VID_._DSM: Argument #4 type mismatch - Found [Buffer], ACPI requires [Package] (20130823/nsarguments-97)
kernel: ACPI Warning: \_SB_.PCI0.AGP_.VID_._DSM: Argument #4 type mismatch - Found [Buffer], ACPI requires [Package] (20130823/nsarguments-97)
kernel: ACPI Warning: \_SB_.PCI0.AGP_.VID_._DSM: Argument #4 type mismatch - Found [Buffer], ACPI requires [Package] (20130823/nsarguments-97)
kernel: ACPI Warning: \_SB_.PCI0.AGP_.VID_._DSM: Argument #4 type mismatch - Found [Buffer], ACPI requires [Package] (20130823/nsarguments-97)
kernel: ACPI Warning: \_SB_.PCI0.AGP_.VID_._DSM: Argument #4 type mismatch - Found [Buffer], ACPI requires [Package] (20130823/nsarguments-97)
kernel: ACPI Warning: \_SB_.PCI0.AGP_.VID_._DSM: Argument #4 type mismatch - Found [Buffer], ACPI requires [Package] (20130823/nsarguments-97)
kernel: ACPI Warning: \_SB_.PCI0.AGP_.VID_._DSM: Argument #4 type mismatch - Found [Buffer], ACPI requires [Package] (20130823/nsarguments-97)
kernel: ACPI Warning: \_SB_.PCI0.AGP_.VID_._DSM: Argument #4 type mismatch - Found [Buffer], ACPI requires [Package] (20130823/nsarguments-97)
kernel: ACPI Warning: \_SB_.PCI0.AGP_.VID_._DSM: Argument #4 type mismatch - Found [Buffer], ACPI requires [Package] (20130823/nsarguments-97)
syslogd: kernel boot file is /boot/kernel/kernel
kernel: NVRM: RmInitAdapter failed! (0x26:0xb:1179)
kernel: nvidia0: NVRM: rm_init_adapter() failed!
kernel: 
kernel: 
kernel: Fatal trap 12: page fault while in kernel mode
kernel: ACPI Warning: \_SB_.PCI0.AGP_.VID_._DSM: Argument #4 type mismatch - Found [Buffer], ACPI requires [Package] (20130823/nsarguments-97)
kernel: ACPI Warning: \_SB_.PCI0.AGP_.VID_._DSM: Argument #4 type mismatch - Found [Buffer], ACPI requires [Package] (20130823/nsarguments-97)
kernel: ACPI Warning: \_SB_.PCI0.AGP_.VID_._DSM: Argument #4 type mismatch - Found [Buffer], ACPI requires [Package] (20130823/nsarguments-97)
kernel: ACPI Warning: \_SB_.PCI0.AGP_.VID_._DSM: Argument #4 type mismatch - Found [Buffer], ACPI requires [Package] (20130823/nsarguments-97)
kernel: ACPI Warning: \_SB_.PCI0.AGP_.VID_._DSM: Argument #4 type mismatch - Found [Buffer], ACPI requires [Package] (20130823/nsarguments-97)
kernel: ACPI Warning: \_SB_.PCI0.AGP_.VID_._DSM: Argument #4 type mismatch - Found [Buffer], ACPI requires [Package] (20130823/nsarguments-97)
kernel: ACPI Warning: \_SB_.PCI0.AGP_.VID_._DSM: Argument #4 type mismatch - Found [Buffer], ACPI requires [Package] (20130823/nsarguments-97)
syslogd: kernel boot file is /boot/kernel/kernel
kernel: NVRM: RmInitAdapter failed! (0x26:0xb:1179)
kernel: nvidia0: NVRM: rm_init_adapter() failed!
kernel: 
kernel: 
kernel: Fatal trap 12: page fault while in kernel mode
kernel: cpuid = 1; apic id = 01
kernel: fault virtual address   = 0x8
kernel: fault code              = supervisor read data, page not present
kernel: instruction pointer     = 0x20:0xffffffff81d151f4
kernel: stack pointer           = 0x28:0xfffffe01198f1590
kernel: frame pointer           = 0x28:0xfffffe01198f1670
kernel: code segment            = base 0x0, limit 0xfffff, type 0x1b
kernel: = DPL 0, pres 1, long 1, def32 0, gran 1
kernel: processor eflags        = interrupt enabled, resume, IOPL = 3
kernel: current process         = 1425 (Xorg)
kernel: trap number             = 12
kernel: panic: page fault
kernel: cpuid = 1
kernel: KDB: stack backtrace:
kernel: #0 0xffffffff808ea690 at kdb_backtrace+0x60
kernel: #1 0xffffffff808b2245 at panic+0x155
kernel: #2 0xffffffff80c8877a at trap_fatal+0x37a
kernel: #3 0xffffffff80c88a47 at trap_pfault+0x2b7
kernel: #4 0xffffffff80c88206 at trap+0x5e6
kernel: #5 0xffffffff80c714f2 at calltrap+0x8
kernel: #6 0xffffffff81d322a3 at nvidia_dev_dtor+0x23
kernel: #7 0xffffffff807acc29 at devfs_fpdrop+0xa9
kernel: #8 0xffffffff807ad5c2 at devfs_open+0x142
kernel: #9 0xffffffff80d40a52 at VOP_OPEN_APV+0x92
kernel: #10 0xffffffff8095a576 at vn_open_vnode+0x216
kernel: #11 0xffffffff8095a188 at vn_open_cred+0x358
kernel: #12 0xffffffff80953801 at kern_openat+0x261
kernel: #13 0xffffffff80c89067 at amd64_syscall+0x357
kernel: #14 0xffffffff80c717db at Xfast_syscall+0xfb

FreeBSD 10; new X.org, KMS, PKGNG, poudriere…


Warning: Missing argument 2 for Jetpack_AMP_Support::render_sharing_html() in /home/content/15/11463415/html/site/wp-content/plugins/jetpack/3rd-party/class.jetpack-amp-support.php on line 302

freebsdLately I’ve been playing with FreeBSD and its new technologies; PKGNG & poudriere and the new KMS/X.org stack that has been pushed to HEAD.

This is just my short how to for updating a FreeBSD CURRENT installation (10.0 at the moment of writing) with the new source code available on the FreeBSD servers.

Starting from FreeBSD 10.0 updating the base system through sources is performed with Subversion; and a lite version of it is shipped in the base system.

Get the source

First of all we must proceed in downloading the full sources from the FreeBSD servers:

svnlite checkout svn://svn0.eu.FreeBSD.org/base/head /usr/src
svnlite checkout svn://svn0.eu.FreeBSD.org/ports/head /usr/ports
svnlite checkout svn://svn0.eu.FreeBSD.org/doc/head /usr/doc

The ports directory; which is quite large; can also be downloaded and put in place with the following commands:

portsnap fetch
portsnap extract

This will populate all the directories with the required source code.

Define configuration for binaries

After getting the sources; we need to define some variables in the /etc/make.conf file to play with the new technologies being introduced.

Many things like PKGNG, CLANG, etc. have been enabled by default in recent builds, so the list is quite small:

# These lines are required to make sure that the make update command works
SVN=/usr/bin/svnlite
SVN_UPDATE=yes
 
# These lines enable the new X.org server (1.12.4) new Mesa libraries, KMS support, etc.
WITH_NEW_XORG=yes
WITH_KMS=yes
WITH_GALLIUM=yes
 
# Line for custom kernel configuration
KERNCONF=CUSTOM

FreeBSD still ships by default with X.org server 1.7; Mesa 7.x and a lot of outdated components. The new X.org components have not been switched yet to default; so specific lines need to be put in place for compiling the required port versions.

After this file, we need to create the kernel configuration file that is specified by the KERNCONF variable. I’m happy with the GENERIC kernel as I run it on multiple systems; so I will not change any option inside the configuration. What I do is turn off debugging support that is enabled by default on unrealeased FreeBSD versions.

So let’s create /usr/src/sys/amd64/conf/CUSTOM and put the following content inside:

include GENERIC
ident CUSTOM
 
# Disable debugging options
nooptions DDB
nooptions GDB
nooptions DEADLKRES
nooptions INVARIANTS
nooptions INVARIANT_SUPPORT
nooptions WITNESS
nooptions WITNESS_SKIPSPIN
nooptions MALLOC_DEBUG_MAXZONES

This kernel configuration file does nothing except specifying a new name and disabling the debugging options already enabled by default in the FreeBSD kernel. This way, when I update the sources; I don’t need to pay attention at which features are new or change in the GENERIC kernel. Pretty smart system.

Update the base system

To update the system, launch the following commands as root (you can of course build the system without being root, but for this short how to this is much clear):

cd /usr/src
make -s update
make -s -j5 buildworld
make -s -j5 buildkernel

The various make commands will make sure that you update the system with the latest sources and build all the toolchain required to compile the system and all the system commands and libraries. After this we’re good to go to install the new kernel and reboot the system:

make -s installkernel
shutdown -r now

When rebooting, choose “Boot in single user mode” (boot -s at the prompt) and perform the following commands to mount the root system in read/write mode:

mount -u /
mount -a -t ufs

Then check for conflicting configuration files that are to be updated (in my case 90% of the time I just need to press “i” to install the new configuration file); install the updated binaries and reboot.

mergemaster -p
cd /usr/src
make -s installworld
mergemaster
reboot

Configure poudriere for generating packages

FreeBSD 10 does not ship anymore with legacy package management tools but only with PKGNG; so the old way of building ports feels “obsolete” after you’ve been using a Linux distribution with package management for years. Thanks, poudriere comes to the rescue.

First of all we install the bleeding edge poudriere package (hey, we’re on 10.0-CURRENT; so we are already bleeding!). To install the package, go to the ports directory and install it:

cd /usr/ports/ports-mgmt/poudriere-devel
make install

After installing, we need to configure it and create a FreeBSD jail for building packages and some variables in poudriere’s configuration file.

cd /usr/local/etc/
cp poudriere.conf.sample poudriere.conf

Personally, this is what I have in my configuration file:

NO_ZFS=yes
FREEBSD_HOST=ftp://ftp.freebsd.org
RESOLV_CONF=/etc/resolv.conf
BASEFS=/share
USE_PORTLINT=no
USE_TMPFS=yes
DISTFILES_CACHE=/usr/ports/distfiles
CHECK_CHANGED_OPTIONS=yes
CHECK_CHANGED_DEPS=yes
NOLINUX=yes

As you can see I don’t have a ZFS filesystem, I’m not interested in Linux support and I’m sharing the downloaded source tarball directory with the ports system.

The /share directory is a separate mount point in my system where I link the base FreeBSD source folder, the ports directory, the documentation source directory and all the poudriere jails, work queues and package repositories. Make sure to have plenty of space!

We need to replicate the /etc/make.conf of our base system inside the jail to make sure all the packages get the correct settings. Create the file /usr/local/etc/poudriere.d/10-amd64-make.conf with the following contents:

WITH_NEW_XORG="yes"
WITH_KMS="yes"

Now we’re ready to start with poudriere. Issue the following commands:

poudriere ports -c
poudriere jail -c -m ftp -v 10.0-CURRENT -j 10-amd64

This will download a recent copy of the ports tree and create a FreeBSD jail taking the most recent snapshot of 10.0-CURRENT directly from the FreeBSD ftp servers! Awesome.

To update the ports tree, just issue the following command:

poudriere ports -u

Now that we’re ready to go, it’s time to list what ports we would like to build. Create a text file and put the list of ports you want to build inside of it; for example:

x11/xorg
x11/xorg-minimal
x11/nvidia-driver
x11/nvidia-settings
ports-mgmt/poudriere-devel

If you want some additional specific per-port configuration options, you can use the options subcommand. For example; to disable Linux support in the Nvidia driver, perform the following command:

poudriere options x11/nvidia-driver

and deselect Linux; much like you would do using standard ports.

Generate package repositories from the ports collection

Now that all is in place it’s time to trigger the builds. Perform the following command:

poudriere bulk -f portslist.txt -j 10-amd64

Poudriere will take care of setting a parallel task for each cpu you have and make sure all the dependencies are built in the correct order.

After munching for a long time (better go hack some Ingress portals or leave it running night long…) you will have a repository ready for use on your system. Depending on the paths/names you’ve chosen for the FreeBSD jail and for the configuration file you will have something like the following:
# cd /share/data/packages/10-amd64-default
# ls -l
total 176
drwxr-xr-x  2 root  wheel   8704 Sep 13 18:35 All
drwxr-xr-x  2 root  wheel    512 Sep 13 11:51 Latest
-rw-r--r--  1 root  wheel  12508 Sep 13 18:35 digests.txz
-rw-r--r--  1 root  wheel  46344 Sep 13 18:35 packagesite.txz
-rw-r--r--  1 root  wheel  97092 Sep 13 18:35 repo.txz

You just need to add the repository to your system and you’re ready to install packages! The repository also contains the latest pkg package for distribution.

This folder can be published on the web, left locally or wherever you choose. The only thing you need to do is enable the repository on your system(s) through the /usr/local/etc/pkg.conf file.

As an example, if you want to use the current package repository directly on the system where you’ve built everything just leave the following line in the configuration file:

packagesite: file:///share/data/packages/10-amd64-default

Using package repositories

Finally a great package management for FreeBSD. First of all update the repository definition:

pkg update

and then install the packages you want! For example:

pkg install xorg nvidia-driver

PKGNG will take care of everything.

Updating packages

To update packages, just re-update the ports tree with poudriere, rebuild with the bulk command (only the changed packages or the packages with changed dependencies will be rebuilt!) and upgrade your system!

poudriere ports -u
poudriere bulk -f portslist.txt -j 10-amd64
pkg update
pkg upgrade

Awesome.