[HOWTO] Setup any windows-only printer for CUPS on Linux

[HOWTO] Setup any windows-only printer for CUPS on Linux

Postby msingh » 7. Nov 2010, 01:17

Yes. That is right. You can use any windows only printer (that means you do not have Linux / Mac drivers).

My situation was the following (YMMV, so modify accordingly, though I think that the kernel of this howto will be useful to most of you):

Fileserver running Samba on a Ubuntu box using ADS as the security model. Read no possibility of un-authenticated shares (but I digress).

A Dell MFP 1125 printer. It is a windows only printer. No linux or mac driver has ever existed for this printer, and given how old it is, likely never will.

An office full of hybrid computing environments - Windows XP, Linux, Mac, Windows 7. Need to provide a network printing solution to this set of people.

Here is what you need:

a. Ability to follow directions to the letter (please correct me if I miss something, so that I can make this a better HOWTO) and an addiction to Google.
b. A properly installed and configured linux server (I used Ubuntu, YMMV).
c. A valid Windows XP Professional (I have not tested this with the home version) license.
d. VirtualBox PUEL (not open source - PUEL - needed for USB support) version.
e. A slight understanding of the Linux boot process.
f. A CUPS installation.

That is it.

Steps

1. Install VirtualBox. If you are using a CLI only system, HOWTOs exist regarding setting up VirtualBox purely through CLI related commands. I did not take this route because I felt that I might be setting myself up for a failure down the road. I installed Xubuntu-desktop and went from there. However you choose to set up things, the rest of this howto assumes that the end of step 1, you have a working linux + virtualbox installation with enough space. I allocated 10GB to Windows. Seems like a waste to spend 10G on setting up a printer, but what can you do with windows-droid vendors ? Now, create a an unprivileged user (I used "winxp") with group memberships vboxusers, lp, fax, plugdev, lpadmin. Log in as that user. We want to make sure we do not compromise host security.

2. Install Windows XP (I named it winxpprint - call it whatever you like) and set up the printer. This assumes that USB works for you. You may have to set up a filter for the device so that it autoconnects everytime you plug it in, but there are many howtos for that step. At the end of this step, you have a working windows XP installation and a printer that prints from windows. Let us name your printer "Dell MFP 1125". Do not share it. Set it as the default. Substitute names as necessary.

3. On the windows XP machine, download and install ghostscript, ghostview and redmon. Now look at http://iharder.sourceforge.net/current/ ... acprinter/. The example there deals with a mac printer trying to print to a windows printer on the network. Somewhat different situation. Does not matter. Just follow the windows instructions there to the letter. Just in case that page goes offline for some reason, I will summarize what is needed:

i) Go to http://pages.cs.wisc.edu/~ghost/. Download GhostView (4.9), GhostScript (8.62) and Redmon (1.7 is the last one I think). Install all of them. Now shut down the virtual machine. In the virtual machine settings, change the networking from NAT (which is the default) to Host-only. This windows machine does not need to talk to any machine other than the host. This is why we downloaded the packages before changing this.
ii) Go to Printers and Faxes. Add printer. Local printer. Create New port. Redirected Port. Call it RPT1:. Pick Apple LaserWriter 12/640 PS. I pick this (in preference to what is in the HOWTO) because it works from Linux (as well as Mac). Call this "Redirected". Does not matter what you name this as. Your Linux / Mac host machine will never see this.
iii) Do NOT set this as the default. Do NOT share this printer. Do NOT try to print a test page right now.
iv) Browse to Printers and Faxes. Right click on "Redirected". Properties. Ports. Select RPT1: Redirected Port. Redirect this port to the program : C:\Program Files\Ghostgum\gsview\gsprint.exe. (This path may be version dependent.) Arguments: "-printer "Dell MFP Printer" -color -" (no quotes, and yes, there is a hyphen at the end). Output: Program handles output. Run: Hidden. Shut down delay: 300 seconds. Now print a test page from the General tab.
v) Unix print services. Control Panel > Add or Remove Programs. Add / Remove Windows Components. Other Network File and Print Services. Print Services for Unix. You may need your windows XP installation disk. Now, in the Administrative Tools Section, enable this service in the Services section (Contol Panel > Performance and Maintenance). The service you are looking for is TCP/IP Print Server (LPDSVC). Set it start automatically at boot and start it manually this time.
vi) Now we set up the third printer (the one that your Linux / mac will actually see). Printers and Faxes. Local printer. Create a new port. LPR Port. Name or address of server providing lpd: winxpprint (see above). Name of printer or print queue on that server: "Redirected". Apple LaserWriter 12/640 PS. I call this dellmfp1125postscript. I choose this name because it has no spaces/unusual characters and I do not want the later headache of spaces messing up names on the CUPS queue (see below). This is not the default printer (actually, you may decide to set it as the default printer if you have no other use for the windows XP virtual machine - does not really matter as we specify the queue explicitly). Do share this printer. I called the share Dell MFP 1125 PostScript. I am not sure that this step is necessary. You will likely get all kinds of warnings, but ignore them. The only machine this windows XP machine will see is the host (we change networking later). So, no worries. Print a test page.
vii) Go to windows firewall settings. There is a security icon on the bottom right hand corner of the windows XP desktop. Exceptions. File and printer sharing checked. Add Port. LPD Daemon. TCP port 515. Change scope. Custom list. 192.168.56.1/255.255.255.255. I will explain the reason for this choice later.
viii) Control Panel. Network and Internet Connections. Network Connections. Right click on Local Area Connection. Internet Protocol (TCP/IP). Properties. Use the following IP address: 192.168.56.2. Netmask 255.255.255.0. Be patient - the reason for the last two steps will become clear to you presently. Leave the virtual machine running.

4. You are done with the Windows XP configuration at this point. Hopefully, I did not miss anything. Let us setup CUPS on the host machine. Set up printer dellmfp1125 as an LPD queue (we are using LPD to communicate with the windows guest). URI: lpd://192.168.56.2:515/dellmfp1125postscript. Driver: Apple LaserWriter 12/640 PS. Now, its time to explain to you why I chose all those IP addresses. In a terminal on the host, type

/sbin/ifconfig.

About the last entry will be a network interface named vboxnet0 with an IP address 192.168.56.1. Well, there is the reason.Your linux host is the DHCP server (inbuilt into VirtualBox). The windows virtual machine is the only (fixed address) DHCP client.

Print a test page from CUPS. If it works, proceed to step 5. Otherwise, debug using previous documentation.

5. Now, shut down the virtual machine. Time to set it up as a headless service that starts at boot. I followed the howto at: http://www.glump.net/howto/virtualbox_as_a_service.

Just in case that link goes down, I will summarize the process here (you will note that my networking setup is different - I do not have any use for Windows XP virtual machine other than getting the printing to work):

i) Create a file named: /etc/init.d/virtualbox-winxp:

This following script is written by Brendan Kidwell. I have modified it for my own needs. You will likely do the same.

Code: Select all   Expand viewCollapse view
#! /bin/sh
    ### BEGIN INIT INFO
    # Provides:          virtualbox-winxp
    # Required-Start:    $local_fs $remote_fs vboxdrv vboxnet
    # Required-Stop:     $local_fs $remote_fs
    # Default-Start:     2 3 4 5
    # Default-Stop:      0 1 6
    # Short-Description: Windows XP Professional SP3 virtual machine
    # Description:       Windows XP Professional SP3 virtual machine hosted by VirtualBox
    ### END INIT INFO

    # Author: Brendan Kidwell <brendan@glump.net>
    #
    # Based on /etc/init.d/skeleton from Ubuntu 8.04. Updated for Ubuntu 9.10.
    # If you are using Ubuntu <9.10, you might need to change "Default-Stop"
    # above to "S 0 1 6".

    # Do NOT "set -e"

    # PATH should only include /usr/* if it runs after the mountnfs.sh script
    PATH=/usr/sbin:/usr/bin:/sbin:/bin
    DESC="Windows XP Professional SP3"
    NAME=virtualbox-winxp
    SCRIPTNAME=/etc/init.d/$NAME

    MANAGE_CMD=VBoxManage
    VM_OWNER=winxp
    VM_NAME="Windows XP" #This has to be the name exactly as it appears in your VirtualBox GUI control panel.

    # Read configuration variable file if it is present
    [ -r /etc/default/$NAME ] && . /etc/default/$NAME

    # Load the VERBOSE setting and other rcS variables
    [ -f /etc/default/rcS ] && . /etc/default/rcS

    # Define LSB log_* functions.
    # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
    . /lib/lsb/init-functions

    #
    # Function that starts the daemon/service
    #
    do_start()
    {

        # Return
        #   0 if daemon has been started
        #   1 if daemon was already running
        #   2 if daemon could not be started

        sudo -H -u $VM_OWNER $MANAGE_CMD showvminfo "$VM_NAME"|grep "^State:\s*running" >/dev/null && {
            echo "$VM_NAME" is already running.
            return 1
        }

        sudo -H -u $VM_OWNER $MANAGE_CMD startvm "$VM_NAME" -type vrdp >/dev/null || {
            echo Failed to start "$VM_NAME".
            return 2
        }

        echo "$VM_NAME" started or resumed.
        return 0
    }

    #
    # Function that stops the daemon/service

    #
    do_stop()
    {
        # Return
        #   0 if daemon has been stopped
        #   1 if daemon was already stopped
        #   2 if daemon could not be stopped
        #   other if a failure occurred

        sudo -H -u $VM_OWNER $MANAGE_CMD showvminfo "$VM_NAME"|grep "^State:\s*running" >/dev/null || {
            echo "$VM_NAME" is already stopped.
            return 1
        }

        sudo -H -u $VM_OWNER $MANAGE_CMD controlvm "$VM_NAME" savestate || {
            echo Failed to stop "$VM_NAME".
            return 2
        }

        echo "$VM_NAME" suspended.
        return 0
    }


    #
    # Display "State" field from showinfo action
    #
    do_status()
    {
        sudo -H -u $VM_OWNER $MANAGE_CMD showvminfo "$VM_NAME"|grep "^State:\s*.*$"
    }

    case "$1" in
      start)
        [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
        do_start
        case "$?" in
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
        esac
        ;;
      stop)
        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
        do_stop
        case "$?" in

                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
        esac
        ;;
      restart|force-reload)
        #
        # If the "reload" option is implemented then remove the
        # 'force-reload' alias
        #
        log_daemon_msg "Restarting $DESC" "$NAME"
        do_stop
        case "$?" in
          0|1)
                do_start
                case "$?" in
                        0) log_end_msg 0 ;;
                        1) log_end_msg 1 ;; # Old process is still running
                        *) log_end_msg 1 ;; # Failed to start
                esac
                ;;
          *)
                # Failed to stop
                log_end_msg 1

                ;;
        esac
        ;;
      status)
        do_status
        ;;
      *)
        #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
        echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status}" >&2
        exit 3
        ;;
    esac


ii) Test out the service. Start it: /etc/init.d/virtualbox-winxp start. Then try connecting to the running script over rdp to port 3389 (Google this - its in the docs). If you see a screen for windows XP, you are all set. Make sure you set the proper permissions for the script. Reboot the host. Try connecting again. And print a test page. If you are merely going to use windows printer locally from the machine, you are done.

6. On the CUPS configuration, share this printer and allow printing from the Internet. Add a class. Call it anything - this is necessary according to this webpage: http://www.owlfish.com/thoughts/winipp- ... 07-20.html, and my own experience. My class name was Officeprinter. The existing printer will be added automatically to the class.

The URI to use for your clients is:

http://<servername>:631/classes/Officeprinter

(servername is your linux host)

Edit the cups configuration file (from the browser) to add:

ServerName <servername>
ServerAlias <servername>

Restart CUPS (if you used the web interface to edit it, this will happen automatically).

On clients:

Set it up as a generic PostScript printer (linux), or Apple LaserWriter 12/640 PS (for mac, linux and windows XP), or MS Publisher Imagesetter (windows 7 - there is no Apple driver in-built into this OS). Print a test page.

You are done.

PS: It is possible that a similar method might work for a Windows 7 guest OS, but that will take 20GB to install (twice the overkill). Why bother ? As it stands, the headless service takes almost 35% of the memory on my machine.
msingh
 
Posts: 14
Joined: 6. Oct 2010, 22:08
Primary OS: Ubuntu other
VBox Version: PUEL
Guest OSses: Windows XP

Re: [HOWTO] Setup any windows-only printer for CUPS on Linux

Postby msingh » 12. Nov 2010, 13:51

I would appreciate it if people test this out. Reports of possible problems will help make this a better HOWTO.
msingh
 
Posts: 14
Joined: 6. Oct 2010, 22:08
Primary OS: Ubuntu other
VBox Version: PUEL
Guest OSses: Windows XP


Return to Linux Hosts

Who is online

Users browsing this forum: No registered users and 0 guests

cron