stygix.org
the dark arts of unix, photography, and dungeons & dragons

Back to Stygix.org Main Page

Thinkpad x240 - FreeBSD Setup

12 January 2018

What follows is a record of how I set up FreeBSD to be my daily driver OS on the Lenovo Thinkpad X240. Everything seems to work great. Although, the touchpad needs some tweaking. I've tried several configurations, even recompiling Xorg with EVDEV support and all that, to no avail. Eventually I will figure it out. Do not sleep the laptop from the command line. Do it from within Xorg, or it will not wake up. I don't know why. You can do it from a terminal within Xorg, just not from the naked command line without Xorg started. It also will not sleep by closing the lid. I included a sudo config that allows you to run /usr/sbin/zzz without a password, so what I do is I have a key combo assigned within i3wm to run "sudo /usr/sbin/zzz". It works fine this way.

I go into detail when it comes to setting up Xorg with i3wm. You can skip this if you want, but if you've never used a tiling window manager, it will handle screen real estate very efficiently on a laptop with a 12.5-inch screen and a touchpad.

First, download the amd64 image for 11.1-RELEASE and flash it to a USB pen drive. For the Unices, use this:
# dd if=FreeBSD-11.1-RELEASE-amd64-memstick.img of=/dev/da0 bs=1M conv=sync
Obviously, you'll change /dev/da0 to whatever the USB pen drive is assigned. Plug it in, check dmesg.

Leave it plugged in, restart the laptop. When prompted, tap Enter to halt the boot process, then F12 to select a bootable device. Choose the USB drive.

I won't go through the actual install process, but it is pretty damn easy so just look at a guide or two and you'll be fine. If you can install Debian, you can install FreeBSD. I will, however, recommend ZFS if you have over 4GB of RAM (my particular variant of the X240 has 8GB of RAM, so yours should have at least 4GB), along with an encrypted disk, and an encrypted SWAP partition. When prompted to add an additional user, and you get to the question where it asks for additional groups, please make sure you add the user to "wheel". The rest should be self-explanatory during the install.

Now for the good shit. You just booted into a fresh FreeBSD install. Now what? Well, time to fire up vi and open some config files.

% vi /etc/rc.conf
clear_tmp_enable="YES"
sendmail_enable="NONE"
powerdxx_enable="YES"
powerdxx_flags="-a hiadaptive -b adaptive -i 75 -r 85 -p 500"
kld_list="i915kms if_iwm"
wlans_iwm0="wlan0"
ifconfig_wlan0="WPA DHCP"

The first two options, clear_tmp_enable and sendmail_enable, are for security reasons. Flush your tmp, don't "let it mellow", because it's not yellow. And don't f*%#@*ing use sendmail unless you know what you're doing. Powerd is power management. kld_list loads certain modules later in the boot process than normal. Usually, modules are loaded in /boot/loader.conf, however, for some reason my X240 hangs if I try to load either the video module (i915kms) or the wifi module (iwm) in loader.conf. So do it here.

% vi /etc/wpa_supplicant.conf

ctrl_interface=/var/run/wpa_supplicant
eapol_version=2
ap_scan=1
fast_reauth=1

network={
    ssid="myhomewifiwhatever"
    psk="passwordgoeshere"
    priority=5
}

You can later add more wireless networks by adding additional network blocks in /etc/wpa_supplicant.conf. Just assign them a lower priority. Like, I have one for a certain coffee shop with priority=1 (very low priority for connection) and no PSK. I also have the option key_mgmt=NONE for that one since it's an open network.

Now reboot. And behold! Wifi! Framebuffer on the console! Oh jee golly fucknuggets!

Log into root, run % visudo, and uncomment the line where people in wheel group can use all commands as root. But make sure it's not the one that says NOPASSWD. For usability's sake, we'll be adding our own lines after the wheel group line. I'll list the config options for sudo after that. Alternatively, instead of using these custom entries for shutdown/suspend/etc, you could add yourself to the operator group, but I'm not sure if that includes the ability to suspend the system.

## Uncomment to allow members of group wheel to execute any command
%wheel ALL=(ALL) ALL

myusername myhostname = (root) NOPASSWD: /usr/sbin/zzz
myusername myhostname = (root) NOPASSWD: /sbin/shutdown
myusername myhostname = (root) NOPASSWD: /sbin/halt
myusername myhostname = (root) NOPASSWD: /sbin/reboot
myusername myhostname = (root) NOPASSWD: /sbin/poweroff

Obviously, myusername will be your username and myhostname will be, uh, your hostname. You know what? Fuck it. I'm just going to assume you can figure that shit out on your own.

Let's get some software installed

% pkg-static install -f pkg
% pkg update
% pkg install powerdxx xorg xorg-server xterm xcompmgr transset i3 i3status i3lock dmenu feh firefox inconsolata-ttf
now get out of root and log in as your user

Run % service powerdxx start, because now you have powerdxx installed and you can get a better idea of BSD battery life.

Now run % vi .xinitrc

sh ~/.fehbg &
exec /usr/local/bin/xcompmgr &
exec /usr/local/bin/i3

This will start xcompmgr, a compositing window manager, along with i3. It will also automatically apply a background you've selected later by downloading something and running

% feh --bg-scale ~/wallpaper.jpg

You don't need to create ~/.fehbg, feh will create it for you.

Now let's pretty up xterm.

% vi .Xdefaults

XTerm*loginShell: true
XTerm*foreground: gray
XTerm*background: black
XTerm*faceName: inconsolata
XTerm*faceSize: 10
XTerm*scrollBar: false
XTerm*metaSendsEscape: true
XTerm*bellIsUrgent: true

Start up xorg with % startx. Let the wizard configure i3 for you, it will just ask if you want to use the Alt key or the Windows key for keybindings. I use the Windows key (aka Mod4) because I use Alt keybindings in firefox and irssi. Now time to bust open the command line again. With i3 open, hit Mod+Enter. If Mod+Enter doesn't work because of i3's wonky defaults, hit Mod+D then type xterm and hit Enter.

% vi .config/i3/config

# start a terminal
bindsym Mod4+Return exec xterm

for_window [class="XTerm"] exec "transset -a"
new_window pixel 1
new_float pixel 1

bindsym Mod4+Shift+Delete exec "i3lock"
bindsym Mod4+Shift+End exec "sudo /usr/sbin/zzz"

# now find the line that starts like this and modify it as such:
# exit i3 (logs you out of your X session
bindsym Mod4+Shift+e exec "i3-msg exit"

This will force xterm. It will then enable transparency for xterm. Then, it removes window decorations except for a 1 pixel border. Neat, huh? After that, you enable screen locking my pushing Mod+Shift+Delete. You allow sleeping by pushing Mod+Shift+End (closing the lid doesn't seem to work for me). Also, on FreeBSD, I had trouble getting i3 to exit with the nag bar enabled, so I changed it to just hard-exit without the nag bar. Problem solved. Now press Mod+Shift+R to reload the config.

Now, when I first had i3 running, the status bar shat itself. If yours did, too, let's clean it up and fix it.

% vi ~/.config/i3status/config

general {
    colors = true
    interval = 5
}

order += "ipv6"
order += "disk /"
order += "wireless wlan0"
order += "ethernet em0"
order += "battery all"
order += "load"
order += "tztime local"

wireless wlan0 {
    format_up = "W: (%essid) %ip"
    format_down = "W: down"
}

ethernet em0 {
    format_up = "E: %ip"
    format_down = "E: down"
}

battery all {
    format = "%status %percentage %remaining"
}

tztime local {
    format = "%Y-%m-%d %H:%M:%S"
}

load {
    format = "%1min"
}

disk "/" {
    format = "Root: %avail"
}

Last, but not least, let's fuck with sound. Run mixer.

% mixer

Each entry in the second column is what you would control from the command line. Volume too low? Run this:

% mixer vol 100

If you're unfamiliar with using dmenu to launch applications, here's a quick rundown. Just hit Mod+D within i3. A ribbon will pop up at the top. Start typing what you want to run, eg, "firefox". You usually won't even have to finish. When it's highlighted to the right of where you're typing, hit enter. Voilà.

Get it? Cool. Have fun, and enjoy FreeBSD on the Thinkpad X240.

©2016 stygix.org (powered by OpenBSD and httpd(8))

simplex sigillum veri