Installing & Using OpenBSD On A Laptop

Posted on

Hey there! Archie here. As you might know, I switched to OpenBSD. There's no particular reason I would switch, but sure I wanted to try out new stuff, and I wanted something different from what I'm used to, so I chose to install OpenBSD on my laptop.

Preparations Before The Install

So, I headed over to the OpenBSD website, and downloaded install79.img (the latest available). Then, I flashed it to a USB drive.

I booted my laptop, and there we have it: one of the simplest operating system installers out there! Now, I would've just pressed return on every option, but well, I chose to customize the hostname and stuff.

doas

doas is OpenBSD's reimplementation of sudo. It's great, it's minimalist and it does privilege escalation pretty well if configured properly. To configure doas i just did, as root:

echo permit archie as root > /etc/doas.conf

Wi-Fi Firmware & Network Configuration

One of the stuff I love about OpenBSD is how well integrated the base system already is. For example, to connect to Wi-Fi using the Intel Wi-Fi 6 AX210 card, we need the firmware!!!!! Soooo, we need to connect via ethernet (no ethernet for me lol) but i can use my phone's USB tethering to get online, get an IP address temporarily with dhcpleasectl, and do:

fw_update

and then a little reboot:

reboot

Now we can finally use ifconfig to connect!!!! yaaayyy!!!!

ifconfig iwx0 nwid "essid" wpakey "key"

or we can connect to an open network:

ifconfig iwx0 nwid "open-essid"

Get an IP address:

dhcpleasectl iwx0

For this to persist, we need to create the /etc/hostname.if file. "if" is the interface name that you got with ifconfig.

This is /etc/hostname.iwx0, in my case:

join <my essid> wpakey <my key> 

Then we restart the network:

ifconfig iwx0 down
sh /etc/netstart iwx0

We can reboot once again:

reboot

Xorg & Suckless Software Configuration

We have working Wi-Fi! Nice! Now to configure Xorg with dwm, dmenu and stuff, we need git to clone the suckless's dwm repo:

doas pkg_add git

Logout and login with your normal user (no privileges) and run:

mkdir .mnml

(or the folder you want suckless's stuff on)

Then probably you'd need to tweak some compiler parameters and such for it to compile properly on OpenBSD. Now configure config.h (copy it from config.def.h) and stuff, and do:

echo setxkbmap <your keymap here> > .xinitrc
echo exec dwm >> .xinitrc
chmod +x .xinitrc

Then install a wallpaper utility like xwallpaper, a compositor like picom and stuff...

doas pkg_add xwallpaper picom

You may now run startx.

Sysctl Tuning

Now, I'd like to get some kernel parameters configured the way I like, such as the laptop lid action, shared memory limits and such. So, I create the /etc/sysctl.conf file with the following content (this is for my laptop, which has 16 GB of RAM, you may need to adjust it):

# /etc/sysctl.conf
    
# laptop lid action on close
machdep.lidaction=1

# shared memory limits
kern.shminfo.shmall=3145728
kern.shminfo.shmmax=2147483647
kern.shminfo.shmmni=1024

# semaphores
kern.shminfo.shmseg=1024
kern.seminfo.semmns=4096
kern.seminfo.semmni=1024

kern.maxproc=32768
kern.maxfiles=65535
kern.bufcachepercent=90
kern.maxvnodes=262144
kern.somaxconn=2048

This will need a reboot.

Touchpad Configuration

I like to configure my laptop's touchpad so it's a little more comfy to use.

Open up (or create if it doesn't exist) the /etc/wsconsctl.conf file, and put this line to enable touchpad tapping:

mouse.tp.tapping=1

Now we need to reboot, or apply the changes immediately:

doas wsconsctl mouse.tp.tapping=1

That concludes the touchpad config.

Power Management & Battery Control

See the estimated battery time:

apm

See the current battery percentage:

apm -l

Now we're gonna set the apmd flags:

doas rcctl enable apmd
doas rcctl set apmd flags -L
doas rcctl restart apmd

Automatic Switching From Internal Speakers To Headphones & Fix Sound Skipping

Set this in /etc/rc.conf.local:

sndiod_flags="-f rsnd/0 -F rsnd/1 -m play -z 800"

What does this mean? It's simple. sndiod is the sound server for OpenBSD, and here we define its flags. The -f rsnd/0 -F rsnd/1 flags switches automatically between audio devices, though we can do sndioctl server.device=0 and sndioctl server.device=1 to switch between the two, 0 being the internal speakers and 1 being the USB audio interface. The -m play flag only enables playback, disabling the internal microphone. In my case it's nothing fancy, just a pair of Samsung AKG wired headphones powered by the USB type C interface. They work flawlessly with the uaudio(4) kernel driver, though sometimes i get: "uaudio0: can't reset interface" in the dmesg logs like bro what??? lmaooo, but yea, it is what it is.

Restart the sound server:

doas rcctl restart sndiod

You'll get no sound for a second, then the audio stuff will be fixed forever. If you use mpd for music, it may help to put this config block on ~/.config/mpd/mpd.conf:

buffer_time "500000"

on the "audio_output" part, then restart mpd:

pkill mpd
mpd

Web Browsers On OpenBSD

Web browsing on OpenBSD is pretty limited, with your only usable options being Firefox and chromium.

i found that for me, chromium is faster than firefox. But you can try and see for yourself.

To install one of them:

doas pkg_add firefox

or

doas pkg_add chromium

You can start them typing "firefox" or "chrome" in dmenu or your preferred application launcher/menu program.

if firefox or chromium decides to go berzerk and close themself, do this:

Add yourself to the staff group with:

doas usermod -G staff <your username>

Lastly, set the resource limits on /etc/login.conf, on the staff section. Again, this config is for my laptop, which has 16 GB of RAM, so I defined half of it (8 GB). You may adjust it to your RAM:

staff:\
  :datasize-cur=8192M:\
  :datasize-max=12288M:\
  :maxproc-cur=512:\
  :maxproc-max=1024:\
  :openfiles-cur=4096:\
  :openfiles-max=8192:\
  :stacksize-cur=32M:\
  :ignorenologin:\
  :requirehome@:\
  :tc=default:

Log out and log in again, then run startx, for the changes to take effect. Or just restart the system.

Perhaps you need to install additional software and stuff to get you going, but this should do for a basic OpenBSD system with suckless software.

You may want to head over to the OpenBSD frequently asked questions website, that has a ton of good docs and stuff to get you started.

That was it for this post, hope it has been useful, see you next time, take care of your self! Love yaa!!!

Go back to the blog's main index.