Michael's Daemonic Doodles

...blogging bits of BSD

Running FreeBSD on the Lenovo T470s ThinkPad

Installing FreeBSD on this machine was super easy. As I couldn't find a comprehensive/encouraging how-to about installing FreeBSD on a recent ThinkPad, I just wrote up the one below. It includes details about my personal setup, which are not required to run FreeBSD on this model, but which are more to my own taste. I still think this can be a quite useful inspiration for others who want to run their own customized configurations.

Specs

The system I use has these specifications:

  • Type: 20JS-001EGE
  • CPU: Intel Core i7-6600U, 2x 2.60GHz
  • RAM: 20GB DDR4
  • SSD: 512GB NVMe
  • Graphics: Intel HD Graphics 520 (IGP), 1x HDMI 1.4
  • Display: 14", 1920x1080, non-glare, IPS
  • Ports: 3x USB-A 3.0, 1x Thunderbolt 3, 1x Gb LAN
  • Wireless: WLAN 802.11a/b/g/n/ac, Bluetooth 4.1, LTE (Micro-SIM)
  • Cardreader: SD/SDHC/SDXC/MMC
  • Webcam: 0.9 Megapixel
  • Extras: MIL-STD-810G, Pointing Stick, Fingerprint-Reader, Docking port

Things that work

Basically everything I care about:

  • Accelerated video
  • Keyboard
  • Touchpad/ClickPad (like expected in a modern laptop)
  • SSD
  • WiFi
  • Sound
  • HDMI out
  • Suspend to RAM
  • Webcam

Things that don't work

  • Fingerprint reader
  • Potentially anything I didn't test

Battery life is okay, but could be better.

Installation of the base system

I used a snapshot release of 12-CURRENT as the basis of my installation, particularly the one of 13th of December 2017.

I dd'ed it onto a memory stick and boot the laptop. I started a standard installation and created an encrypted ZFS pool on nvme0, using encryption, swap encryption and partition scheme "GPT (UEFI)".

After installation, it boots straight up.

Ports tree used

All work is based on a head ports tree from about Dec 18, 22:15 CET, which should be more or less r456672.

Preferred ClickPad configuration

As I'm not a fan of the the pointing stick, I disabled it in the bios. My final ClickPad configuration will be: Click to click (not tap), no middle button, right button in the lower right corner. As the old synaptics driver doesn't provide good thumb detection, libinput will be used.

Custom kernel

To allow using evdev, a custom kernel was installed:

cat >/usr/src/sys/amd64/conf/mykernel <<EOF
include GENERIC-NODEBUG

ident mykernel

# evdev support
device                evdev
options               EVDEV_SUPPORT
EOF

Build and install the custom kernel:

cd /usr/src
make -j4 kernel KERNCONF=mykernel

Then reboot.

evdev support in /etc/sysctl.conf

To support evdev, add rcpt mask to sysctl.conf:

echo "kern.evdev.rcpt_mask=12" >>/etc/sysctl.conf

Enable synaptics support in /boot/loader.conf

To enable synaptics support do:

echo 'hw.psm.synaptics_support="1"' >>/boot/loader.conf

Sound

Sound works out of the box, you might want to ajust hw.snd_vpc_0db if speaker volume seems to low.

To make headphone jack detection work properly, do:

echo 'hint.hdaa.0.nid33.config="as=1 seq=15"' >>/boot/device.hints

Enable wireless networking

Enable wireless networking in rc.conf (country depends on your actual location):

sysrc cloned_interfaces+=iwm0
sysrc wlans_iwm0=wlan0
sysrc ifconfig_wlan0="WPA DHCP country de"

Modify /etc/wpa_supplicant.conf to contain your network, example:

network={
  ssid="myssid"
  psk="mysupersecretkey"
}

Install and enable drm-next-kmod

To install and enable drm-next-kmod, do:

pkg install drm-next-kmod
sysrc kld_list="/boot/modules/i915kms.ko"

Note

In case the package builders are not in sync with your kernel, drm-next-kmod might cause a panic, therefore the safest way to install drm-next-kmod is to build it from ports, like in cd /usr/ports/graphics/drm-next-kmod && make install && make clean

Enable powerd++

To install and enable powerd++ do:

pkg install powerdxx
sysrc powerdxx_enable=YES

Install a patched version of libinput

If you're like me and prefer to have a small right button (touchpad not split equally), place patch-src_evdev-mt-touchpad-buttons.c in /usr/ports/x11/libinput/files. To prevent removing the trackpad device after SYN_DROPPED events, place patch-src_evdev.c.fixdrop in /usr/ports/x11/libinput/files (this is hacky, but works around the problem).

Then do:

cd /usr/ports/x11/libinput
make install clean

If you don't care, you can install libinput as a binary package.

Install libinput input driver

After patching libinput itself, xf86-input-libinput can be installed:

pkg install xf86-input-libinput

Reinstall a patched version of xorg-server

To make xorg-server work probably with evdev, two patches are required:

  • Fix a problem with VT switching without using xf86-input-keyboard - this is quite important, as otherwise anything you type will be echoed on the console and some bizarre things can happen. Described in bug 220562 (direct link to patch, mirror).
  • Support udev for autoconfiguration of input devives. Described in bug 222609 (direct link to patch, mirror).

After applying the patches to the port, do:

cd /usr/ports/x11-servers/xorg-server
make deinstall
make config
# select UDEV as the autoconfiguration backend
make reinstall clean

Configure input devices for X.org

The configuration below makes sure that the keyboard uses evdev xkbrules and makes the touchpad use two button mode (and disable turning it off while typing):

cat >/usr/local/etc/X11/xorg.conf.d/99-myinput.conf <<EOF
Section "InputClass"
  Identifier "libinput keyboard catchall"
  MatchIsKeyboard "on"
  MatchDevicePath "/dev/input/event*"
  Driver "libinput"
  Option "XkbRules" "evdev"
EndSection

Section "InputClass"
  Identifier "libinput touchpad catchall"
  MatchIsTouchpad "on"
  MatchDevicePath "/dev/input/event*"
  Driver "libinput"
  Option "MiddleEmulation" "on"
  Option "DisableWhileTyping" "off"
EndSection
EOF

Configure tear-free for the intel graphics driver

This enables tearfree for the intel graphics driver:

cat >/usr/local/etc/X11/xorg.conf.d/98-tearfree.conf <<EOF
Section "Device"
  Identifier  "Intel Graphics"
  Driver      "intel"
  Option "TearFree" "True"
EndSection
EOF

Enable dbus

To enable dbus, do:

sysrc dbus_enable=YES

Install additional packages

These additional packages are required for the configuration of dwm below, which brings in useful features like locking and compton to improve video playback. Even if you don't plan to use dwm, this might be interesting to you:

pkg install compton dmenu firefox hsetroot intel-backlight \
    redshift slock xautolock xkbset

Install dwm with custom configuration

I used a couple of patches found at https://dwm.suckless.org/patches, plus a few I created my own (noborder , customized attach at end and customized warped pointer).

Place those thee files in /usr/ports/x11-wm/dwm/files, then create a custom dwm.config.h (copied from the original config.h).

You can download my full dwm configuration directly from here.

This accomplishes the following (might be interesting to you, even if you're using a different window manager):

  • Use Windows key as MODKEY
  • Adjust a couple of things just like I prefer them (like mod+enter to start xterm, mod+tab to switch to next window)
  • Enable brightness control (uses intel-backlight) using mod+f5/f6
  • Enable volume control (fn+f2/f3 and mod+f2/f3)
  • Add screenlock command (mod+l)
  • Add suspend command (includes locking): mod+shift+z
  • Add fix pointer command (on dropped synatics event the pointer might get lost, this re-enables it - see patch to libinput above to prevent this from happening)

$HOME/bin/suspend:

#!/bin/sh
xautolock -locknow
sudo zzz

$HOME/bin/fixpointer:

#!/bin/sh
xinput --disable 9
xinput --enable 9

To install dwm, do:

cd /usr/ports/x11-wm/dwm
make clean
make DWM_CONF=/path/to/dwm.config.h install clean

My $HOME/.xinitrc

This enables a couple of things I care about (set my keyboard layout, map print button to middle mouse click for pasting the primary x selection, set my keyboard layout, start compton compositor for smooth video playback etc.):

#!/bin/sh

# set keyboard layout
setxkbmap -model pc105 -layout de

# map "print" button to middle mouse key (paste)
xkbset m
xkbset exp =m
xmodmap -e "keysym Print = Pointer_Button2"

# start gpg-agent
gpg-agent --daemon

# start ssh-agent
eval `ssh-agent`
export SSH_AUTH_SOCK
export SSH_AGENT_PID

# start compton compositor (slows down dwm, but gives great video
# playback, no shadows, no frills)
compton --backend=glx --no-fading-openclose --no-dock-shadow \
  --no-dnd-shadow --shadow-opacity=0 --menu-opacity=1 \
  --glx-no-stencil --daemon

# set background color to black
hsetroot -solid "#000000"

# enable auto lock on idle (also used by mod+l and lock on pointer in
# upper left corner)
xautolock -locker 'sh -c "xset dpms 10 && slock && xset dpms 0"' \
  -corners +000 -time 5 -cornerdelay 1 -cornerredelay 10 &

# Enable redshift
redshift -l 48.13:11.57 &

# Update dwm status (time/day etc.)
$HOME/bin/updatedwmstatus&

# Start window manager
/usr/local/bin/dwm

# Primitive clean up
killall redshift
killall gpg-agent
if [ -n "$SSH_AGENT_PID" ] ; then
     kill -TERM $SSH_AGENT_PID > /dev/null 2>&1
fi

Example $HOME/bin/updatedwmstatus script

#!/bin/sh

while sleep 2; do
  NAME=`date`
  xsetroot -name "$NAME" || exit 1
done

Patched acpi_ibm

There is a patch to acpi_ibm under review that allows you to load acpi_ibm and use features like:

  • Mute/get mute status using sysctl dev.acpi_ibm.0.mute
  • Control keyboard backlight using sysctl dev.acpi_ibm.0.kbd_backlight
  • Control keyboard backlight using the led(4) interface /dev/led/kbd_backlight

Conclusion

Installation FreeBSD on the Lenovo T470s was quite straightfoward and it's a great machine for work an leisure.

Questions?

If you have questions, remarks, ideas for improvements etc. feel free to contact me.