FreeNAS As a Print Server

190,460

52

120

Published

Introduction: FreeNAS As a Print Server

About: Twitter: @Tau_Zero

FreeNAS is an excellent network storage solution simple enough for anyone to install. The system and space requirements are ridiculously small for this stripped-down version of FreeBSD. It's got all manner of features accessible through it's clean web GUI, more than most will ever need. It even lets you stream media to game consoles!

Despite it's impressive built in abilities, there was one thing that I wanted it to do besides act as a great NAS, and that was to be a print server so I could share my HP Deskjet 6540 USB printer among my Windows and Mac OSX boxes. Easier said than done. After hours of playing around with CUPS and a few broken installs later, I saw the light.

On the FreeNAS forums, user sgrizzi created a thread on how to make it work with LPR, using the LPRng package, for a LiveCD based setup. It was EXTREMELY helpful, and he/she should get most of the credit, but the thread really needs to be condensed and clarified to be a useful guide. That is exactly what this Instructable is for, as well as modifying it for a standard full install of FreeNAS.

This guide assumes you already have a current standard install of FreeNAS set up and working.

Step 1: Preparation

First, let's get together a few things and take a look at the setup.

The Network
Your setup may be different, but mine is as follows.
- Linksys WRT54GL router running Tomato firmware v1.23
- FreeNAS box - v0.69, old Sony Vaio, 2 hard drives, static IP: 192.168.1.50
- PC - Windows XP SP3
- Macbook Pro - OSX 10.5.6
- HP Deskjet 6540 - USB connected printer, attached to FreeNAS

You will need to assign your FreeNAS box a static internal IP from within your router. There's plenty of guides online for that, all straight-forward, so do a quick Googling.

Stuff You'll Need
- Windows install disk if you're using Windows (necessary files may be availible elsewhere, but this is the easiest)
- Printer Drivers for your particular make/model
- The file "ulpt.ko" taken from a full FreeBSD install. File attached to this instructable.
- SSH client - For Windows, go with PuTTy. For Linux, Unix, Mac, etc you can just use the terminal/command line

Step 2: Connect Via SSH

Connect to your FreeNAS box via SSH. Normally it's bad practice to log in as root, but if you're really careful, things should go smoothly.

PuTTy is pretty self explanatory here for connecting. For the command line people, type:

ssh -l username static_ip_of_freenas

The static ip will be something like 192.168.x.xxx.
It will ask for a password, but when you type, nothing shows up. Don't worry, this is normal (hides password for security purposes); just type it and hit enter.

You should now have yourself a little greeting and a new command prompt (loggin in as root is freenas:~# and as a user is >)

Step 3: Put Ulpt.ko in the Right Spot

Use your preferred method (ftp, smb, etc.) to put the ulpt.ko file somewhere onto the FreeNAS box, and remember the full path (I'll call it UPath), which will probably be something like /mnt/drivename/ulpt.ko

Go back to the terminal with the SSH connection and command prompt, we're going to move the file to the proper place. Type:

mv Upath /boot/kernel/ulpt.ko

That ought to do it.

Step 4: Install LPRng

We will be using a package called LPRng. To install it, type:

pkg_add -r LPRng

Let that chug away for a bit while it downloads and installs the necessary bits.

Step 5: Configure Things to Load on Boot

Load ulpt.ko Module
First we want to make sure that ulpt.ko loads on boot so as soon as we connect a printer it'll recognize it properly. Type:

nano /boot/defaults/loader.conf

Scroll down with either the arrow keys or ctrl+V until you reach a section titled "USB Modules"
Change the line
"ulpt_load="NO" # Printer"
to
"ulpt_load="YES" # Printer"

Hit ctrl+X. Then type "y", and hit enter when it asks you to save.

Start LPRng

Navigate to the FreeNAS web interface in a browser. Then go to System-->Advanced-->rc.conf
Use the "+" button to add two new entries:

Name: lpd_enable
Value: NO

Name: lprng_enable
Value: YES

Step 6: LPRng Configuration: 1 of 3 - Printcap

There are three main files that contribute to LPRng working properly.
- /etc/printcap
- /usr/local/etc/lpd.perms
- /usr/local/etc/lpd.conf

Printcap (location: /etc/printcap) can be very complex or very simple. We'll go with very simple, but you can refer to the LPRng site and google for some different setups depending on your needs.

It'll be much easier to illustrate this by example:

# @(#)printcap HP Deskjet 6540
lp|deskjet:\
:sd=/var/spool/lpd/bare:\
:sh:\
:lp=/dev/ulpt0:
#

First line doesn't matter much. Just put your printer make/model in there for reference
- "lp|deskjet" - this is what you're printer will be known as. "lp" is the primary name, "deskjet" is an alias.
- "sd=" This is the path to the print spooler. We're going to make this directory in a second.
- "sh" This stands for "supress header". If you've ever printed in a computer lab, you'll have seen these. It's a page that prints before a job that identifies who the job is for. For most people at home, it's unnecessary. In a work environment with lots of people and printing, it's something you should look into.
- "lp=" this is the location of the printer. If ulpt.ko loads properly, then when you connect a printer, it should register as /dev/ulpt0.

Remember the spooler path from sd? Let's make it. Type:

"mkdir -p -m 700 /var/spool/lpd/bare"
and
"chown 1:1 /var/spool/lpd/bare"

This creates the proper directory with the necessary ownership and permissions.

Step 7: LPRng Configuration: 2 of 3 - Lpd.perms

lpd.perms (location: /usr/local/etc/lpd.perms) is a bit long. The default configuration should be fine. Scroll through and double check that these lines are uncommented (don't begin with a "#") by typing:

nano /usr/local/etc/lpd.perms

The lines that we want uncommented are:

ACCEPT SERVICE=C SERVER REMOTEUSER=root,papowell
ACCEPT SERVICE=C LPC=lpd,status,printcap
REJECT SERVICE=C
ACCEPT SERVICE=M SAMEHOST SAMEUSER
ACCEPT SERVICE=M SERVER REMOTEUSER=root
REJECT SERVICE=M
DEFAULT ACCEPT

Make any changes and then hit ctrl+X

Step 8: LPRng Configuration: 3 of 3 - Lpd.conf

lpd.conf (location: /usr/local/etc/lpd.perms) should also be fine as the default. Things to double check for:

# Purpose: always print banner, ignore lpr -h option
# default ab@ (FLAG off)
# Purpose: query accounting server when connected
# default achk@ (FLAG off)
# Purpose: accounting at end (see also af, la, ar, as)
# default ae=jobend $H $n $P $k $b $t (STRING)
# Purpose: name of accounting file (see also la, ar)
# default af=acct (STRING)
# Purpose: use long job number (0 - 999999) when a job is submitted
# default longnumber@ (FLAG off)
Longnumber

Step 9: Start Things and Set Permissions When Printer Connects

We're going to want to start up the proper LPRng processes when a printer is connected. Type:

"nano /usr/local/etc/devd/devd.conf"

Add to the file:

# start action when USB printer ulpt0 is plugged in
# wait 3 second and then start the spooler daemon
#
attach 100 {
device-name "ulpt0";
action "sleep 3; lpd;
checkpc -f;
chown 0:0 /dev/ulpt0;
chmod 666 /dev/ulpt0;
echo 'o5L25fgfab' > /dev/speaker;";
};
*/

This watches for the printer to be plugged in, waits a few seconds, and starts the LPD process. Once that's going it fixes any missing files or permissions with checkpc -f. It then sets proper ownership and permissions on the device and plays a little sound.

Step 10: Connecting a Windows PC

1) Go to Network Connections. Click the Advanced tab at the top, then "Optional Networking Components".
Enable both Management and Monitoring Tools and Other Network File and Print services. It will ask you to insert the Windows cd, which you should have around. This will allow us to connect via LPR

2) Go to the Control Panel and then to Printers. Run the Add a New Printer wizard.

3) Local Printer (do not automatically detect). Next.

4) Create New Port -> LPR Port. Next

5) Enter the IP address of the FreeNAS box. This is why we want it to be static. Enter the name of the print queue (if you copied my printcap, it's "lp" without quotes)

6) Install drivers and click through the rest of the wizard. Do not print test page.

7) Right click on the printer and open up properties.

8) Port Tab. Uncheck "bidirectional support"

9) Advanced Tab.
start printing after the last page is spooled. Check
Print directly& Uncheck
Hold mismatched& Uncheck
Print spooled& Check
Keep&.Uncheck
Enable advanced& Check

10) Now go back to the main tab and try printing a test page.

Step 11: Connecting With Mac OSX

1) Open up System Preferences -> Print and Fax

2) Click the "+" to add a printer

3) Go to the "IP" tab
Protocol: LPD
Address: The IP of FreeNAS
Queue: Name of print queue (if you copied my printcap, it's "lp" without quotes)
Name and Location are up to you
Print Using: Pick correct drivers*

*Some printers, like my HP Deskjet 6540 wouldn't let me use the usb drivers with the LPD. I had to instead pick one as close as possible (turned out to be 5550) and go with that. If the two models are similar, it should work without a problem.

Share

    Recommendations

    • Oil Contest

      Oil Contest
    • Clocks Contest

      Clocks Contest
    • Water Contest

      Water Contest

    120 Discussions

    0
    user
    noahw

    9 years ago

    Hey, this is a great instructable and is very informative. Just one thing is missing... pictures! It really helps a lot when trying to follow directions so you should consider taking some photographs. Once you do that and leave me a message when you have so that we can publish your work. Thanks! Thanks for the cool instructable and we hope to publish this soon!

    the way is nolonger to support freenas 8X, i have try it, root ID cannot write nano because permission denid, but it also can use in nas4free

    hi. would you be so kind and make tutorial for version 8.3 please? i dont have rc.conf in interface in this version. thank you

    You need to remount the file system as readable/writable.

    # mount -uw /

    When you're finished, make sure you remount it as readonly.

    # mount -ur /

    Hi,
    I reached this point: by changing pkg_add -r LPRng to:
    pkg_add -r ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-7.4-release/Latest/LPRng.tbz
    But at the end it says:
    pkg_add: pkg_add of dependency 'gettext-0.18.1.1' failed!
    Does this mean a problem? or can I ignore it?

    1 reply

    did you ever find out the workaround to this problem? i'm stuck at the same point, if i go ahead like it's no problem i can't do the next step... i thought maybe because i'm running an AMD Sempron i should get the amd64 port rather than i386 but it didn't make any difference.
    Somebody help please!

    No, he is correct. Even as root, /boot/kernel will not allow any new files to be added to it.

    1 reply

    I should have included that I am trying this instructable on FreeNAS v.8.0.1. I have tried several ways to get the ulpt.ko file into the /boot/kernel directory, and it will NOT let me write to it or change the permissions on the directory.

    good morning, i´ll try to install but when done download file .tbz i can see in the screen:
    Last login: Fri Jun 24 08:27:39 2011 from 80.26.36.12
    Copyright (c) 1980, 1983, 1986, 1988, 1990, 1991, 1993, 1994
    The Regents of the University of California. All rights reserved.

    Welcome to FreeNAS!

    freenas:~# pkg_add -r LPRng
    Fetching ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-7.3-release/Lates
    t/LPRng.tbz... Done.

    /: write failed, filesystem is full
    bin/lpr: Write failed: No space left on device: No space left on device
    bin/lprm: Write failed: No space left on device: No space left on device
    bin/lpstat: Write failed: No space left on device: No space left on device
    lib/liblpr.a: Write failed: No space left on device: No space left on device
    libexec/filters/lpbanner: Write failed: No space left on device: No space left o
    n device

    /: write failed, filesystem is full
    libexec/filters/lpf: Write failed: No space left on device: No space left on dev
    ice
    libexec/filters/psbanner: Write failed: No space left on device: No space left o
    n device
    sbin/checkpc: Write failed: No space left on device: No space left on device
    ...
    tar: Error exit delayed from previous errors.
    pkg_add: leave_playpen: can't chdir back to ''
    freenas:~#

    i have installed freenas in a datatravel pendrive usb with 8 gb of capacity, but when i execute df, the command shown:
    freenas:~# df
    Filesystem 1K-blocks Used Avail Capacity Mounted on
    /dev/md0 190190 190188 2 100% /
    devfs 1 1 0 100% /dev
    procfs 4 4 0 100% /proc
    /dev/md1 31470 1292 27662 4% /var
    /dev/ad4p1 473018108 12433064 422743596 3% /mnt/cosas
    /dev/da0a 71062 66786 4276 94% /cf

    What i can do for install the pakage?
    Thanks

    1 reply

    If it is a memstick has plenty of memory try

    mount -uw /

    My stick was set to read only.

    Is this ok? just to clear stuff up?

    freenas# mv /mnt/start/ulpt.ko /boot/kernel/ulpt.ko
    mv: rename /mnt/start/ulpt.ko to /boot/kernel/ulpt.ko: Read-only file system

    I'm not sure if this is an error but i'm getting this...


    tar: Error exit delayed from previous errors.
    pkg_add: leave_playpen: can't chdir back to ''


    is it ok?

    I have the same problem. hp 1020.
    When l plugged my printer, FreeNAS beeping and typing "using bi-directional mode". Is it right?

    Looks like the package moved, This is how I got around the error.

    pkg_add -r ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages/Latest/LPRng.tbz

    Hi, is it possible to use this instruction for my FreeNAS 0.7.2 (FreeBSD 7.3) ?

    Completed after some very careful reading, and consulting the source thread.
    A few helpful hints to my fellow explorers:
    1) Instead of stating requires a "standard" installation, should state up front that it requires a FULL install, an embedded install will not get past 1st base.
    2) devd.conf must be placed in /usr/local/etc/devd - if the directory doesnt exist, create it.
    3) once all the pieces are in place, reboot to fully initialize the system.
    4) helps to manually run the
    echo 'o5L25fgfab' > /dev/speaker
    command so you know exactly what to listen for. This is the success trumpet :)

    All in all, a very good instructable. Thanks for the hard work Tau_Zero!!!

    Starting LPRng,

    freenas:~# lpd (enter)
    2010-10-29-03:29:08.044 freenas Read_file_list: cannot stat required or included file '/etc/printcap' - No such file or directory

    to fix
    freenas:~# mv /usr/local/etc/printcap /etc/printcap
    freenas:~# lpd (no error this time)

    I can't get it to print anything. As soon as I enter the IP address and name of the print queue, it comes up with a message box telling me that "the lpd request did not respond as expected to a test command". It lets me continue the set up but I cannot print. I shows in the printer properties as a document sent for print but reports "printer busy or error"

    I followed the instructions as given but I don't seem to have the /etc/printcap directory. Help!

    1 reply