423. Printing and scanning
This page covers printing through CUPS, adding and sharing printers, USB printers that speak IPP, and scanning through SANE, both with a scanner on the desk and one on the network. Finding printers and scanners on the network depends on Avahi, which has a page of its own, Avahi and mDNS.
Installation
The base the ISO carries holds the print service, the network and IPP-over-USB support, the Printers page and scanning through SANE. The printer drivers (gutenprint, hplip, brlaser, splix, foomatic-db), skanlite and ptouch-print are not in it; sudo kdos update install <port> adds each (see Installing software).
| Part | Ports |
|---|---|
| The print service | cups, with cups-filters, libcupsfilters, libppd and ghostscript to turn a job into what a printer takes |
| Printers announced on the network | cups-browsed |
| USB printers and scanners that speak IPP | ipp-usb |
| Drivers for printers that need one | gutenprint, hplip, brlaser, splix, foomatic-db |
| Setting printers up | print-manager: the Printers page of System Settings, the print queue window and the tray applet; system-config-printer |
| Scanning | sane-backends, sane-airscan for network scanners, skanlite |
| Label printers | ptouch-print |
Three service scripts are part of the base filesystem, in fs/etc/init.d:
| Script | Service name | Supervised process | Starts |
|---|---|---|---|
80_cups.sh |
cups |
cupsd |
The print service |
81_cups-browsed.sh |
cups-browsed |
cups-browsed |
Adds printers shared on the network to CUPS as they appear |
82_ipp-usb.sh |
ipp-usb |
ipp-usb |
Serves each IPP-over-USB device on localhost as it is plugged in |
The live medium starts all three, and so does an installed system unless you turn printing off in the installer: in its list of service choices, the last field of each entry is whether it starts ticked, and CUPS starts ticked:
const Service ki_services[] = {
{ "networkmanager", "NetworkManager", "wired, wifi and VPN", 1 },
{ "bluetooth", "Bluetooth", "bluez daemon", 1 },
{ "alsa", "ALSA state", "restore mixer levels at boot", 1 },
{ "cups", "CUPS", "printing daemon", 1 },
{ "sshd", "OpenSSH server", "accepts remote logins", 0 },
};
src/system/kinstall-core/conf.c, lines 29–35
Unticking it writes /etc/service.disabled/cups, which covers the two companions as well: 81_cups-browsed and 82_ipp-usb exist to hand printers to cupsd, so they run only while it does. 80_cups.sh starts each after cupsd unless that companion has a marker of its own, and stops both before cupsd; started any other way while cupsd is not supervised, each prints [SKIP] <name>: CUPS is off and starts nothing. A scanner that speaks IPP over USB reaches SANE only through ipp-usb, so it also needs CUPS running.
Configuration
The service scripts
Each runs its daemon in the foreground for the supervisor. cupsd takes -f; cups-browsed needs no flag; ipp-usb runs in standalone mode, which keeps it running between devices:
. /etc/init.d/service_helper
NAME="cupsd"
DAEMON="/usr/sbin/cupsd"
# cups-browsed and ipp-usb exist only to hand printers to cupsd, so they start
# and stop with it: whatever starts cups (rcS, `service start cups`) brings them
# up without a reboot, and stopping cups takes them down first. Each still has
# its own marker; a companion disabled on its own is not started here. rcS's own
# later start of 81 and 82 finds them supervised and prints `[SKIP] already
# supervised`.
COMPANIONS=("81_cups-browsed:cups-browsed" "82_ipp-usb:ipp-usb")
case "$1" in
start)
if [ ! -x "$DAEMON" ]; then
echo "[SKIP] $NAME: $DAEMON not found"
exit 0
fi
echo "[KDOS] Starting $NAME..."
mkdir -p /run/cups
# -f = run in foreground for supervision
supervise "$NAME" "$DAEMON" -f
_rc=$?
if [ "$_rc" = 0 ]; then
for _c in "${COMPANIONS[@]}"; do
[ -x "/etc/init.d/${_c%%:*}.sh" ] || continue
[ -f "/etc/service.disabled/${_c#*:}" ] && continue
"/etc/init.d/${_c%%:*}.sh" start
done
fi
exit "$_rc"
;;
stop)
# The companions first: neither has anything to do once cupsd is gone.
# A companion that is not running answers "not running", and cupsd is
# still stopped.
for ((_i = ${#COMPANIONS[@]} - 1; _i >= 0; _i--)); do
_c=${COMPANIONS[_i]}
[ -x "/etc/init.d/${_c%%:*}.sh" ] || continue
"/etc/init.d/${_c%%:*}.sh" stop || true
done
stop_service "$NAME"
;;
status)
check_status "$NAME"
;;
*)
echo "Usage: $0 {start|stop|status}"
exit 1
;;
esac
. /etc/init.d/service_helper
NAME="ipp-usb"
DAEMON="/usr/sbin/ipp-usb"
case "$1" in
start)
if [ ! -x "$DAEMON" ]; then
echo "[SKIP] $NAME: $DAEMON not found"
exit 0
fi
# CUPS is ipp-usb's consumer on KDOS's default path, so it runs only
# while cupsd does, and an IPP-over-USB scanner, which sane-airscan
# reaches through it, needs CUPS running too. A running cupsd decides,
# not the cups marker: `service start cups` runs on a machine whose
# marker exists, and 80_cups.sh starts this script once cupsd is
# supervised and stops it before cupsd.
if ! ksvc check cupsd >/dev/null 2>&1; then
echo "[SKIP] $NAME: CUPS is off"
exit 0
fi
echo "[KDOS] Starting $NAME..."
# standalone = run for ever and serve every IPP-over-USB device as it
# is plugged in, in the foreground for supervision (no -bg). udev mode
# exits with the last device, and nothing here starts it again.
supervise "$NAME" "$DAEMON" standalone
;;
stop)
stop_service "$NAME"
;;
status)
check_status "$NAME"
;;
*)
echo "Usage: $0 {start|stop|status}"
exit 1
;;
esac
81_cups-browsed.sh has the same shape and the same check for a running cupsd, and runs cups-browsed with no argument.
Who may manage printers
CUPS is configured with lpadmin and root as its administrative groups, runs filters as lp, and listens on a local socket under /run/cups:
--with-rundir=/run/cups \
--with-cupsd-file-perm=0755 \
--with-cups-user=lp \
--with-cups-group=lp \
--with-system-groups="lpadmin root" \
--with-domainsocket=/run/cups/cups.sock \
ports/core/printing/cups/build.sh, lines 26–31
The kdos account is in lpadmin, in the shipped /etc/group:
lpadmin:x:995:kdos
A password asked for by the web interface is checked through PAM, with the file the cups port writes:
install -d -m 755 $PKG/etc/pam.d
cat > $PKG/etc/pam.d/cups << "EOF"
auth required pam_unix.so
account required pam_unix.so
EOF
chmod 644 $PKG/etc/pam.d/cups
ports/core/printing/cups/build.sh, lines 49–54
/etc/cups/
cupsd.conf and cups-files.conf are upstream’s files; KDOS adds nothing there. Change cupsd.conf with cupsctl, or edit it and restart the service. printers.conf holds the queues and is written by cupsd itself as they are added; its first lines say not to edit it while cupsd is running.
/etc/ipp-usb/ipp-usb.conf
The ipp-usb port installs upstream’s configuration unchanged, and upstream’s quirks files for particular printers under /usr/share/ipp-usb/quirks:
install -Dm755 out/ipp-usb $PKG/usr/sbin/ipp-usb
install -Dm644 ipp-usb.conf $PKG/etc/ipp-usb/ipp-usb.conf
install -Dm644 ipp-usb-quirks/*.conf -t $PKG/usr/share/ipp-usb/quirks
install -Dm644 ipp-usb.8 -t $PKG/usr/share/man/man8
ports/core/printing/ipp-usb/build.sh, lines 16–19
Upstream’s defaults serve each device on the loopback interface only, on a port from 60000 to 65535, and announce it over DNS-SD, which is how CUPS and SANE find a USB device as though it were on the network. A quirks file of your own goes in /etc/ipp-usb/quirks; ipp-usb(8) describes the format.
Scanners: /etc/sane.d/ and the udev rules
SANE’s backends read their configuration from /etc/sane.d; dll.conf there lists the backends that are loaded, and sane-airscan adds itself through /etc/sane.d/dll.d/airscan. The sane-backends port writes the rules and the hardware-database file that mark each scanner a backend supports:
descs=doc/descriptions:doc/descriptions-external
install -d "$PKG/usr/lib/udev/rules.d" "$PKG/usr/lib/udev/hwdb.d"
tools/sane-desc -m udev+hwdb -s $descs -d 0 > "$PKG/usr/lib/udev/rules.d/65-libsane.rules"
tools/sane-desc -m hwdb -s $descs -d 0 > "$PKG/usr/lib/udev/hwdb.d/20-sane.hwdb"
ports/core/printing/sane-backends/build.sh, lines 22–25
The mark grants nothing by itself. KDOS’s own rule turns it into the dialout group, and gives the same group the USB devices of five scanner makers by vendor ID:
# KDOS — flatbed and sheet-fed scanners, for SANE.
#
# Class 255 subclass 255 is the vendor-specific bucket most scanners sit in, so
# this is deliberately narrower than "everything unclassified": the match
# requires the device to be one SANE has marked as a scanner, or a member of
# the small set of vendors that ship nothing else on that class.
#
# The mark is sane-backends': its 20-sane.hwdb sets libsane_matched on every
# USB id a backend supports, through the hwdb import in 50-udev-default.rules,
# and its 65-libsane.rules sets it on SCSI scanners (/dev/sg*). Neither grants
# anything; this line is the grant for both.
ENV{libsane_matched}=="yes", GROUP="dialout", MODE="0660"
# Canon, Epson, HP, Brother, Fujitsu scanner vendor ids
SUBSYSTEM=="usb", ATTR{idVendor}=="04a9", ENV{DEVTYPE}=="usb_device", GROUP="dialout", MODE="0660"
SUBSYSTEM=="usb", ATTR{idVendor}=="04b8", ENV{DEVTYPE}=="usb_device", GROUP="dialout", MODE="0660"
SUBSYSTEM=="usb", ATTR{idVendor}=="03f0", ENV{DEVTYPE}=="usb_device", GROUP="dialout", MODE="0660"
SUBSYSTEM=="usb", ATTR{idVendor}=="04f9", ENV{DEVTYPE}=="usb_device", GROUP="dialout", MODE="0660"
SUBSYSTEM=="usb", ATTR{idVendor}=="04c5", ENV{DEVTYPE}=="usb_device", GROUP="dialout", MODE="0660"
fs/etc/udev/rules.d/70-kdos-scanner.rules
So a user scans only as a member of dialout. Brother P-touch label printers, which ptouch-print drives over raw USB rather than through CUPS, go to lpadmin instead, in /etc/udev/rules.d/70-kdos-ptouch.rules.
Usage
Turning CUPS on and off (installed system)
CUPS runs on an installed system by default. If printing was turned off in the installer:
Enable it for every boot, and start it;
cups-browsedandipp-usbstart with it:sudo service enable cups sudo service start cupsCheck it:
service status cups lpstat -r
To turn printing off, sudo service disable cups and sudo service stop cups; the stop takes cups-browsed and ipp-usb down first, and at the next boot both skip with CUPS is off.
Adding a printer from the desktop
- System Settings → Printers → Add Printer. The wizard lists the printers CUPS finds: network printers announced by mDNS, USB printers and IPP-over-USB devices.
- Select the printer. For a driverless printer, choose IPP Everywhere (or driverless) as the driver; for one that needs a vendor driver, pick the make and model. Those models come from the driver ports, gutenprint, hplip, brlaser, splix and foomatic-db, so install the one your printer needs first, for example
sudo kdos update install gutenprint. - Name the queue and Finish. Set as Default and Remove are on the printer’s row.
CUPS lets a member of lpadmin change a queue; for anyone else the page asks for an administrator’s name and password, which CUPS checks itself. The tray’s printer applet shows the queue while a job prints.
Adding a printer from a terminal
List the device URIs CUPS can reach:
lpinfo -vA line with a full URI, such as
network ipp://printer.local/ipp/printordirect usb://…, is a device. A line carrying only a scheme, such asnetwork socketordirect hp, is a backend that found nothing by itself; with no printer reachable those are the only lines.Add and enable a driverless queue, with a name of your choice:
lpadmin -p office -v 'ipp://printer.local/ipp/print' -m everywhere -Eprinter.localresolves like any host name, through dnsmasq andkdos-mdnsd, which ask Avahi (see .local names through DNS), soping printer.localand the printer’s web page athttp://printer.localwork as well.For a printer that needs a driver, find its model with
lpinfo -mand give that name to-min place ofeverywhere.lpinfo -mlists every model the installed drivers cover, which with the driver ports installed is many thousands of lines, so filter it:lpinfo -m | grep -i laserjet.Make it the default and print a document:
lpoptions -d office lp document.pdfFollow the job:
lpstat -p -d lpstat -ocancel <job>removes one.
lpadmin, lpoptions, lp, lpstat and cancel need no sudo: membership of lpadmin is the authority CUPS checks. Root is granted the same, so the commands work under sudo too. lpoptions -d sets your own default, which lpstat -d then reports.
A USB printer
- Plug it in. A printer that speaks IPP over USB is served by
ipp-usbon localhost and announced there; it appears in the Add Printer wizard and inlpinfo -vlike a network printer. - An older USB printer appears in
lpinfo -vwith ausb://URI. Add it with that URI and, where it is not driverless, a driver fromlpinfo -m.
Sharing a printer with other machines
Tell CUPS to share its queues, as yourself and not with
sudo:cupsctl --share-printers lpadmin -p office -o printer-is-shared=truecupsctlrewritescupsd.conf, which CUPS allows only after a password, so it asksPassword for <user> on localhost?and takes your own login password.cupsctl | grep sharethen shows_share_printers=1.Open the
ippservice in the firewall, which needs membership ofwheel:kdos-power firewall ipp onippopens TCP 631. The other named services, and how to close one again, are on Firewall.
Scanning
Check that you are in
dialout:idList the scanners SANE can open. A network scanner that speaks eSCL or WSD is found by sane-airscan, through Avahi for eSCL and its own WS-Discovery for WSD:
scanimage -LWith none found it says
No scanners were identified.and exits 0.Scan, giving the device string
scanimage -Lprinted:scanimage -d '<device>' > scan.pnmFor a preview and a selection, install Skanlite (
sudo kdos update install skanlite) and open it from the application menu.
Tips
- CUPS’s own web interface is at
http://localhost:631, for every setting the Printers page does not offer. lpstat -tprints everything CUPS knows at once: the scheduler, the default, every queue and every job.- An application in a box prints through the host’s CUPS socket,
/run/cups, which is shared into the box when the box is created. A box created while CUPS was not running cannot print until it is created again; see Profile changes and re-creating a box. airscan-discoverlists the eSCL and WSD scanners on the network, with the lines that would name them in/etc/sane.d/airscan.conf; with none it prints only its[devices]header.- Programs for scanned documents, each installed with
sudo kdos update install <port>: gImageReader (portgimagereader, programgimagereader-qt6) reads text out of a scan with Tesseract, andocrmypdfadds a text layer to a scanned PDF.
Troubleshooting
lpstat says the scheduler is not running. Either CUPS was unticked at install time or cupsd is failing. service list shows cups as [DISABLED] for the first; see Turning CUPS on and off. Otherwise:
cat /run/kdos-init.cups.log
sudo tail -n 40 /run/kdos-svc.cupsd.log
A running service reports [ OK ] cupsd (pid N) to service status cups.
The Printers page says the print service is not available. The scheduler is down; the procedure above starts it. lpstat -r says scheduler is running or scheduler is not running.
Adding a discovered printer fails with Unable to connect to <host>.local:<port>: Name does not resolve. Neither the C library, through dnsmasq and kdos-mdnsd, nor CUPS’s own question to Avahi got an address. Check that Avahi runs (service status avahi), that getent hosts <host>.local prints an address (see Avahi and mDNS), and that avahi-resolve-host-name -4 <host>.local does; if it does not, the printer is not answering mDNS on this network, and adding it by address works: lpadmin -p <name> -v ipp://<address>:<port>/ipp/print -m everywhere -E.
lpadmin -m everywhere fails. IPP Everywhere driver requires an IPP connection. means the URI is not ipp:// or ipps://: the printer is on another backend and needs a driver from lpinfo -m. Unable to create PPD: Printer does not support required IPP attributes or document formats. means CUPS reached the address and found no driverless printer there.
lpadmin is refused. Check id for lpadmin. A user added with useradd is not in it unless the -G list named it; add it with sudo usermod -aG lpadmin <user> and log in again.
cupsctl says Unauthorized or Forbidden. Unauthorized means no password reached CUPS: cupsctl asks for one only on a terminal, so run it at a prompt rather than from a script, and answer with your login password. Forbidden means the account that asked is in neither of CUPS’s system groups, lpadmin and root: run it as a member of lpadmin, or with sudo.
A job stays in the queue. lpstat -t shows the queue’s state and the printer’s last message. CUPS’s log is /var/log/cups/error_log; for more detail, run cupsctl --debug-logging, print again, and read it. A job for a network printer that is still busy waits in five-second steps until the printer is idle; see Known gaps.
A USB printer is not found. Ask ipp-usb what it sees:
sudo ipp-usb check
sudo tail -n 40 /var/log/ipp-usb/main.log
ipp-usb check prints Configuration files: OK and then each device it serves, or No IPP over USB devices found.
A printer that does not speak IPP over USB is not one ipp-usb serves; look for it in lpinfo -v as a usb:// URI.
A network printer is not discovered. Discovery is mDNS. Check service status avahi and avahi-browse -rt _ipp._tcp; see Avahi and mDNS.
scanimage -L lists nothing for a scanner that is plugged in. Check the group first: a backend cannot open a device node it has no permission for. Compare with sudo scanimage -L; if root sees the scanner, add the user to dialout and log in again. If root does not see it either, the backend may not support the model; lsusb shows its USB ID.
Known gaps
- Broad hardware support is not a goal: no range of printers and scanners has been tested
- Some command-line programs build after Qt: sane-backends is among them, so a build that stops before
43_toolkitshas no scanning
See also
- Printing: the user guide’s section
- KDOS settings pages: the KDOS pages of System Settings, beside KDE’s Printers page
- Scanning, OCR and printing: the applications and drivers
- The device groups and the udev rules: the scanner and label-printer rules
- Avahi and mDNS, udev and device groups, Users and groups, Firewall, Services