Running Adobe Photoshop CS5 Under Linux

Adobe Photoshop Logo When MS-Windows XP went out of support I upgraded all of my machines to Ubuntu 14.04. Whilst most had been dual-boot, all except one now only run Linux. Two of the few things that I regularly ran under MS-Windows were the odd game and Adobe Photoshop. The games were dealt with by the one computer I left as dual-boot, but Photoshop is a tool that I use often as photography is one of my hobbies. I also wanted to use this on my Linux desktop.

I started running Photoshop inside a VirtualBox MS-Windows XP guest running on the Linux host. It worked really quite well until one day I went to use the magic wand selection tool. It was dire. In actual fact as it turned out, it had nothing to do with running inside a VM but a corrupt settings file. However, not knowing that at the time, I incorrectly assumed that it was simply a performance issue.

So I looked at using Wine to run Photoshop. As you can see from their compatibility database, Photoshop 5.5 doesn’t rate very well at all, earning a rating between garbage and gold. Me thinks, your mileage may vary!

Anyway, not deterred by the ratings, I tried it out, initially following the guidance on the ratings page.

The machine I did this on is running Ubuntu 14.04 on Intel Pentium 4 x86 32 bit hardware with 4GiB of RAM.

Grabbing A Copy Of Photoshop

The first thing to do was to grab an installed copy of Photoshop, currently registered to Adobe, and zip up all of its installation files and registry keys. For this I used the copy that was installed on my MS-Windows XP VM.

Using a standard zip archiving package, I zipped up each of the following directories into their own zip files:

    C:\Documents and Settings\All Users\Application Data\Adobe
    C:\Documents and Settings\tony\Application Data\Adobe
    C:\Documents and Settings\tony\Application Data\Adobe Mini Bridge CS5
    C:\Program Files\Adobe
    C:\Program Files\Adobe Media Player
    C:\Program Files\Common Files\Adobe
    C:\Program Files\Common Files\Adobe AIR
    

By the way, the only Adobe product installed on this VM was Photoshop and Flash player. All of the above directories came from installing Photoshop. When I had finished I had seven zip files.

The next step was to dump the registry keys for Photoshop. I started the registry editor; using the Start menu, I selected Run... and then entered regedit when prompted and pressed <Return>. Don’t worry you’re not going to change the registry, just dump out a region of it to a .reg file. When the registry editor was running, I used the expandable tree pane on the left hand side to navigate to the HKEY_LOCAL_MACHINE\Software key and expanded it. Listed directly under it I found the Adobe key. I selected it, right-clicked and then selected the Export menu option. A standard save file as dialog appeared, allowing me to save the data as a .reg file.

Once I had got the zip files and the registry keys, I was finished with the VM. The rest was done on Linux.

Installing Photoshop Under Linux

To install Wine I did:

    sudo apt-get install wine winetricks
    sudo apt-get clean
    

I then set up Wine for my account and installed Photoshop by doing:

    winetricks atmlib gdiplus msxml3 msxml6 vcrun2005 vcrun2005sp1 vcrun2008 ie6 fontsmooth-rgb gecko
    cd .wine/drive_c/Program\ Files/
    unzip ~/windows/PS5/Program-Files/Adobe.zip 
    unzip ~/windows/PS5/Program-Files/Adobe\ Media\ Player.zip 
    cd Common\ Files/
    unzip ~/windows/PS5/Program-Files/Common-Files/Adobe.zip 
    unzip ~/windows/PS5/Program-Files/Common-Files/Adobe\ AIR.zip 
    cd ~/.wine/drive_c/users/Public/Application\ Data/
    unzip ~/windows/PS5/All-Users/App-Data/Adobe.zip
    cd .wine/drive_c/users/tony/Application\ Data/
    unzip ~/windows/PS5/tony/App-Data/Adobe.zip
    unzip ~/windows/PS5/tony/App-Data/Adobe\ Mini\ Bridge\ CS5.zip
    cd
    wine regedit ~/windows/PS5/adobe.reg
    

Please Note:

    Photoshop needs a 32 bit Wine prefix; which was irrelevant for me on 32 bit hardware, but on 64 bit hardware you need to make sure that you set up a 32 bit prefix instead of a 64 bit one.

The first step installs a bunch of MicroSoft libraries and may take some time to download. The rest basically consists of unzipping the software and its data in the right places and adding the exported registry keys.

Starting Up Photoshop For The First Time

Warning:

    On no account run Photoshop whilst connected to the Internet. I will explain all in a bit, but for now just unplug your computer from the network or use the Network Manager to disable the network interface.

I then ran up Photoshop by doing:

    wine .wine/drive_c/Program\ Files/Adobe/Adobe\ Bridge\ CS5/Bridge.exe &
    wine .wine/drive_c/Program\ Files/Adobe/Adobe\ Photoshop\ CS5/Photoshop.exe &
    

After I had finished with Photoshop, it left some daemons running in the background (as it did under MS-Windows incidentally). These do exit in time, say after about five to ten minutes. However if you want to tidy up straight away then you can either kill off the offending Adobe processes by using the standard kill command or by telling Wine to completely shutdown by doing:

    wineserver -k
    

Disabling Internet Access For Photoshop

Previously I stated that one must disconnect the computer from the internet when running Photoshop. There are two main reasons for this:

  • Try as I might, I was unable to get Photoshop to work online without it failing during the registration process and stating that I had an unregistered copy of Photoshop. I tried using a copy registered under MS-Windows and I tried unregistering the MS-Windows copy and then attempting to register it again under Wine. Neither worked. However when it can’t reach the Internet, Photoshop silently remains active. I know what some may be thinking at this point; but I do not condone the use of such measures as a means to circumvent licensing agreements. I just wanted to run one of my two copies of Photoshop on my Linux desktop, I never run more than two copies at once and I am the only user.
  • Adobe have a bad reputation for writing secure software, just look at Flash Player and their PDF viewers. If you run MS-Windows software under Wine, your Linux machine will potentially become vulnerable to any MS-Windows malware that can attack that software and anything associated with it. Yes it’s slightly different running under Wine but not that different and assuming otherwise is both wrong and stupid so don’t do it!

Well we obviously don’t want to go offline every time we want to use Photoshop. So is there a way of specifically blocking just that software? Well yes and no. One can use an IPTables firewall rule to block any access by a user group. If Photoshop is only run under that blocked group then it’s in effect blocked from the Internet. The downside is that files created by Photoshop will be owned by that group, but it’s a small price to pay and one can simply reset a file’s group ownership back again if so desired.

So I created a new group called winenet and then made sure that the users that wish to run Photoshop were secondary members of that group. The entry in the /etc/group file looked something like:

    winenet:x:1100:system,fbloggs
    

If you are doing this manually then don’t forget to update the /etc/gshadow file as well.

The firewall rule required to block network access for the winenet group was:

    iptables -I OUTPUT -m owner --gid-owner winenet ! -d 127.0.0.0/16 -j REJECT
    

I allowed the local host network through as certain things can get very upset if this isn’t allowed. How you add this rule is up to you, there are a number of choices:

  • Simply add it to existing firewall rules.
  • Issue the above iptables command and then use iptables-save and iptables-restore to save and restore the firewall state respectively. The iptables-restore command can be included in the scripts that being up the network interface or in something like /etc/rc.local.
  • Do as I did and write a script that can be run via sudo that dynamically adds and removes the rule to a running IPTables setup.

I called the IPTables script block-wine and this was its contents:

#!/bin/sh

PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/opt/tools/bin
export PATH

if test "$#" -ne 1 -o \( "$1" != "enable" -a "$1" != "disable" \)
then
    echo "usage: block-wine enable|disable" >&2
    exit 1
fi

iptables -nL | fgrep -q 'owner GID match 1100'
if test "$?" -eq 0
then
    blocked=1
else
    blocked=
fi

if test "$1" = "enable"
then

    # Add the winenet blocking firewall rule if necessary.

    if test -n "$blocked"
    then
        echo "Already restricted."
    else
        echo "Adding winenet network restriction..."
        iptables -I OUTPUT -m owner --gid-owner winenet ! -d 127.0.0.0/16 -j REJECT
    fi

else

    # Delete the winenet blocking firewall rule if necessary.

    if test -n "$blocked"
    then
        echo "Removing winenet network restriction..."
        iptables -D OUTPUT -m owner --gid-owner winenet ! -d 127.0.0.0/16 -j REJECT
    else
        echo "Already unrestricted."
    fi

fi

exit 0

Remember to change the code at line 12 to match the group id that you used for the winenet group.

I then wrote a script that starts Photoshop, called photoshop:

    #!/bin/sh
    
    # Switch the script to the winenet group.
    
    if test "$1" != "change-group"
    then
        exec sg winenet -c "$0 change-group"
    fi
    exec > /tmp/photoshop$$.log 2>&1
    sudo block-wine enable
    ps -eo comm= | grep -q '^[B]ridge.exe$'
    if test "$?" -ne 0
    then
        echo "Starting Bridge..."
        wine $HOME/.wine/drive_c/Program\ Files/Adobe/Adobe\ Bridge\ CS5/Bridge.exe &
        sleep 5
    fi
    wine .wine/drive_c/Program\ Files/Adobe/Adobe\ Photoshop\ CS5/Photoshop.exe &
    
    exit 0
    

All files created by Photoshop have a group ownership of winenet. However since the login user is an honorary member of that group, they can reset the group ownership back to that of the user’s primary group by using chgrp directly, i.e. there’s no need to do this as root.

Fixing The Wine Defects

Unfortunately there are a number of defects with the version of Wine that ships with Ubuntu 14.04 LTS (Wine version 1.6). They are:

  • Bug #29871 – This manifests itself as the brush tool not drawing properly by just making a dot or splodge on the image instead of the wavy line that you drew. The source code patch can be got from here.
  • Bug #18517 – This manifests itself as the last tooltip that’s displayed won’t disappear. The source code patch can be got from here.

In order to apply these patches, you need to download the source code for Wine and recompile it. Don’t be scared! On Ubuntu this couldn’t be much easier. If you don’t want to contaminate your system with the extra packages needed to recompile Wine then you can always do it inside a virtual machine, on a scratch system or simply remove the packages afterwards with apt-get purge.

I first made sure that I had installed the software needed to recompile Wine:

    sudo apt-get build-dep wine
    sudo apt-get install fakeroot
    sudo apt-get clean
    

Then I got the source code for Wine, patched it and compiled it into a new Debian package (this can all be done as an ordinary user):

    cd ~
    apt-get source wine
    cd wine1.6-1.6.2/cd dlls/user32
    vi input.c
    cd ../comctl32
    vi tooltips.c
    cd ~/wine1.6-1.6.2
    dpkg-buildpackage -rfakeroot -uc -b
    

This produced a number of Debian packages that could be used to replace Wine as installed on the system; for example, the package relevant to me was called wine1.6-i386_1.6.2-0ubuntu4_i386.deb. Incidentally I edited the source code rather than use the patch command as the patches were so trivial to apply; it was simply my preference at the time.

However rather than installing the package I decided to opt for a minimum change approach and so replaced the offending shared libraries. Under the Wine build directory created above, you’ll find the following files:

    dlls/comctl32/comctl32.dll.fake
    dlls/comctl32/comctl32.dll.so
    dlls/user32/user32.dll.fake
    dlls/user32/user32.dll.so
    

and they need to replace the following files under /usr/lib/i386-linux-gnu/wine:

    fakedlls/comctl32.dll
    comctl32.dll.so
    fakedlls/user32.dll
    user32.dll.so
    

respectively.

I then pinned the wine1.6-i386 package to stop it from being upgraded. One can use the Synaptic package manager but if you use apt-get upgrade to update your system then remember to do:

    echo "wine1.6-i386 hold" | sudo dpkg --set-selections
    

as well. Yes unfortunately Synaptic and apt-get/dpkg don’t share pinning information (although this has apparently just been fixed in the code base). Incidentally if you fondly imagined that these tools did keep things in sync then this post may be of interest and this post discusses the various methods of pinning.

The details about faults and patching can be found on the Wine page for Adobe Photoshop CS5 towards the bottom.

Using Photoshop

It’s by no means perfect, but depending upon what you want to do with it, it can work very well. I have encountered the following remaining issues:

  • Bridge issues:
    • The magnifying glass widget, typically in the top right hand corner, doesn’t work and crashes Bridge.
      Solution: This magnifying glass widget can be removed and should be. Save any modified layout in a new workspace.
    • The full screen previewing function where you can switch between one picture and the next with your cursor keys works very slowly after you have changed a number of images. This preview mode is typically invoked by pressing the <Space> bar from within either Bridge or Mini-Bridge inside Photoshop. Admittedly it did operate quite slowly at times under MS-Windows but it always picked up again within a few seconds; but under Wine, once it slows down, it very rarely seems to speed up again.
      Solution: There isn’t one at the moment. I simply use a native Linux desktop application to preview the images. I have also tried increasing the cache size and maybe that will help. I’ll update this blog once I have found a solution.
    • Workspaces become corrupt or messed up.
      Solution: Simply save any changes made to the current workspace to a custom, user defined workspace that can be reset when it becomes corrupt.

    Other functions like generating PDF based contact sheets, which I use quite a lot, still work well, along with examining an image’s EXIF data.

  • Photoshop’s mini bridge issues:
    • There is no right-click menu.
      Solution: None.
    • Nothing happens when you double-click on an image, it should load into Photoshop.
      Solution: Run up MS-Windows Explorer and change the file association for images to Photoshop.
    • As above with Bridge, the full screen previewing function works very slowly.
      Solution: None.
  • Photoshop issues:
    • Photoshop’s main Window is corrupt when it is first started.
      Solution: Unmaximise and then remaximise the window and it will redraw correctly.
    • Photoshop’s main window will not unmaximise permanently.
      Solution: None.

These are just the issues that I have encountered, you may find a whole new set depending upon what you use Photoshop for. Also there may well be solutions out there for some of the issues, I just haven’t been motivated enough to find them out myself as they don’t bother me that much (apart from the slow preview issue).

Anyway I hope this has been of some use. Good luck.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s