Francisco Fuentes

Person who happens to code and also loves music and books

Printing in OpenBSD

10 Jun 2021 » unix

Just adding some notes to some experiences I had while trying to print stuff in OpenBSD 6.9 on a Thinkpad with a cheap Brother HL-1200 Series (mine’s HL-1202). Remember I’m not a knowledgeable OpenBSD user. I’m relatively new to the BSD world.

Issue #1: Manufacturers don’t think about BSD (of course)

Here’s the issue: While at this time most printers work with GNU/Linux, it’s very unlikely that you find a printer that’s made to print with BSD. However, while it seems complicated it’s not that hard and that’s thanks to being a UNIX-like system. Now what I’m gonna do is to describe the problem and how I solved it. That doesn’t mean every printer is the same. Some printers even work out of the box.

In my case I bought a cheap B&W laser printer. I bought this one because I had a kind of a good experience with a Samsung ML-1660 at my parent’s house that lasted (original toner included) for several years. We only used it to print bus tickets, contracts that have to be signed and then scanned. At someone’s house this implies one sheet or two every month if any! So toner printers seem less prone to failure than ink based printers.

I have to be honest and accept a mistake I made with this printer. I didn’t research enough. I just looked for a printer that worked on Linux (I use two Linux devices too). So if you have the time, look for your printer or a model from the same series is mentioned in ports, pkg_info or even on github before buying. Also, there’s a website called Open Printing where there’s a collection of drivers or PPDs available with comments from people who’ve used them in different UNIX-like systems.

The driver for this printer does exist in OpenBSD and it’s called brlaser6. Available as a package to install with pkg_add.

Most documentation I read about the issue involves printing on “remote printers”. Now there’s even a IPP everywhere or driverless printing trend where it’s expected that the printer is available on the network but even docs as old as the reference to printers on Absolute OpenBSD (yeah, that book) which is from 2013 refers to a case where a printer is on an IP. So it’s not a bad idea to get a printer that has WiFi or has some sort of network capability. In my case, it’s just a USB printer. An added issue is that not only are they less popular but they are also harder to set up on OpenBSD. Even a “basic printing” tutorial could get me only so far because it relies on an example given in the Absolute OpenBSD book.

I tried that tutorial and after fiddling a bit and changing the variables I ended with a /etc/printcap file that worked only half way:


It was funny because the printer would take the jobs and then take the printer so it did EVERYTHING, all the weird sounds, it carried the paper all the way but it didn’t print anything! The sheet of paper was very warm though.

If you have the printer and you installed the driver or you think it can take postscripts (.ps files) driverless then you might still need to check how it’s detected by OpenBSD. This is important: If your printer is USB only and it’s not detected neither by LPR nor CUPS (which I’ll show you later) you’ll have to disable ulpt from the kernel and it’s not a permanent thing, especially if you care about updates, kernel erratas and that sort of security stuff that probably hooked you into OpenBSD anyway!

This is what I did to disable ulpt:

printf 'disable ulpt\nq\n' | config -ef /bsd

(some mailing list message also suggests adding the kernel SHA256 sum like this right after you do that above!):

sha256 /bsd >/var/db/kernel.SHA256

That allows you to see the printer with the other USB devices and not have a device busy issue when you wanna install your drivers. Then you reboot.

However, there’s still another hidden issue. it’s not so evident but while at this point I could already print with Manjaro and Debian I installed CUPS and realized that I couldn’t add USB printers at all in the CUPS web interface! (http://localhost:631). The documentation suggest doing the following:

First, install cups and run rcctl enable cupsd && rcctl restart cupsd as root. After that issue usbdevs -v and check where’s your printer at. In my case, my printer was at usb0 port and the driver was ugen2 so I typed the following command (this is also documented at /usr/local/share/doc/pkg-readmes/cups):

# chown _cups /dev/ugen2.* /dev/usb0 

Don’t copy and paste check what’s your driver and usb controller with usbdevs.

Only at this point you could hope to see your printer show up as a USB device in the CUPS interface. Go to Administration -> Add Printer and you should see it. When you reach the driver selection (provided that you selected Brother as brand) you should find something like “HL-1200 Series Driver, using brlaser v6”. That’s the driver. If you pick anything else it won’t work. Also just moving the PPD won’t work, at least not with this printer because it’ll look for a filter and the filter for another file.

Now print the test page.

Issue #3 Printing on the console

The reason I didn’t wanna stop using ulpt was that I thought I could only print with the console that way. Sometimes I’d like to print a man document as the guy from the “Basic printing” tutorial did with lpr which prints using the data from /etc/printcap. Now the thing is that if you use CUPS, lpr probably won’t work. There’s another command I thought was just a symlink to the former called lp but it is slightly different from lpr and it can use CUPS printers:

lp -d [PRINTER name in CUPS] file

So it uses -d instead of -P to identify the printer. Also you can set a default printer. If you don’t remember the name type lpstat -p -d and you can also set the default printer with lpadmin or just set a PRINTER in your ~/.profile. I printed the CUPS manual in the picture below using enscript (a program that transform files to PostScript), lp (of course) and stdout:

enscript /usr/local/share/doc/pkg-readmes/cups -o - | lp -d Brother_HL-1200_series 

Printed with the lp command in OpenBSD