Skip to content

VM Windows Printer with Linux

JTrampQ edited this page Apr 18, 2020 · 11 revisions

Based on: lubuntu-19.10-desktop-amd64.iso

Introduction

When printer in Linux is not supported and no equivalent driver is enabled, the only choice we have is to host VM windows for running this driver. Usually, Postscript printer is well supported in Linux. Unlike GDI printer which often requires specific driver. First, please be sure the driver is not available here: https://www.openprinting.org/drivers/

Prerequisites

sudo apt install qemu qemu-utils qemu-system-x86 qemu-kvm bridge-utils uml-utilities cpu-checker

Architecture

 +------------------------+                 +----------------------+
 |   Linux (Host)         |                 |   Printer            |
 |   192.168.1.200        |                 |    192.168.1.203     |
 |   +-----------------+  |                 +---------^------------+
 |   | Windows (Guess) |  |                           |
 |   | 192.168.1.201   |------------------------------+
 +---+-----------------+--+                                      
       

Create QEMU VM

  • create VM image
qemu-img create -f qcow2 win7.qcow2 40G
  • install win7 iso
qemu-system-x86_64 -m 4096 -cdrom Windows7.iso -boot d win7.qcow2

Set NetWork Bridge from Host (Linux) to Guess (VM Windows)

  • clear IP from physical interface (ens33)
ip addr flush dev ens33 
  • create bridge (br0) and tunnel (tap0) interface
sudo brctl addbr br0
sudo ip link set dev br0 up
sudo tunctl -t tap0
  • bridge physical interface (ens33) and tunnel (tap0)
sudo brctl addif br0 ens33
sudo brctl addif br0 tap0
  • check the bridge setting
$ brctl show
bridge name	bridge id		STP enabled	interfaces
br0		8000.000c29002de8	no		ens33
							tap0
  • assign bridge ip
dhclient -v br0
  • check interfaces settings
$ ifconfig -a
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.200  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 2001:41d0:fe16:600:20c:29ff:fe00:2de8  prefixlen 64  scopeid 0x0<global>
        inet6 2001:41d0:fe16:600:e0f7:aa3c:74c0:4907  prefixlen 64  scopeid 0x0<global>
        ether 00:0c:29:00:2d:e8  txqueuelen 1000  (Ethernet)
        RX packets 4566  bytes 714756 (714.7 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 764  bytes 99669 (99.6 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:0c:29:00:2d:e8  txqueuelen 1000  (Ethernet)
        RX packets 49635  bytes 25988592 (25.9 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 6147  bytes 641351 (641.3 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 859  bytes 80693 (80.6 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 859  bytes 80693 (80.6 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

tap0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::fcb0:f4ff:fe00:5519  prefixlen 64  scopeid 0x20<link>
        ether fe:b0:f4:00:55:19  txqueuelen 1000  (Ethernet)
        RX packets 4384  bytes 392997 (392.9 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 15579  bytes 16611057 (16.6 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  • check routing table
$ route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         _gateway        0.0.0.0         UG    0      0        0 br0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 br0

Start VM Windows

  • check KVM support
$ sudo kvm-ok
INFO: Your CPU does not support KVM extensions
KVM acceleration can NOT be used
  • start VM with KVM (optimized)
sudo qemu-system-x86_64 -m 4096 -enable-kvm -cpu host -smp 2 -nic tap,ifname=tap0,mac=00:00:00:00:00:01 win7.qcow2
  • start VM without KVM (slower)
sudo qemu-system-x86_64 -m 4096 -smp 2 -nic tap,ifname=tap0,mac=00:00:00:00:00:01 win7.qcow2
  • install network printer (follow classic windows printer instruction)
  • VM Windows should have local network IP as 192.168.1.201 in our example

Useful links

Clone this wiki locally