Work together: Linux and Windows

1 Introduction

Currently I have three laptops. They have Arch Linux, Windows 8.1 and Ubuntu Linux 13.10 installed respectively. The laptop with the Ubuntu is four years old and not quite usable because it has heat dissipation problem and would easily shutdown when running some CPU-consuming programs. But still, it could be used as a file server and run some light-weight workload.

Besides the laptops, I have a 27-inch 1080p IPS LED monitor. When working, I would use Arch Linux on my HP ultrabook and the 13-inch QHD screen is gorgeous. However, since I have done some HiDPI-related settings on KDE(my desktop environment on Arch Linux) as described in this post, it would become very ugly if I connect the ultrabook to the 27-inch monitor, whose DPI is only 81.59. Therefore I prefer connecting the Windows 8.1 machine to the monitor. The problem here is how to make these machines cooperate with each other.

2 Share files over Local Network

2.1 Server

The first thing I want to set up is to access files on another machine over the local network. I use a fairly simple Samba setup. The following steps are based on this Arch Wiki page.

First install samba and smbclient. Copy the example configuration file /etc/samba/smb.conf.default/ to /etc/samba/smb.conf. I only changed the line below:

name resolve order = lmhosts bcast host wins

because of the "Time Out" problem of Dolphin mentioned in this section. But the Dolphin's built-in Samba support is still very unusable. It is very slow and often can not even show the Samba server list completely. I use the command line tool smbclient instead.

In Arch's example configuration file, it enable user's home directory sharing by default. The situation of Ubuntu is a little different. You need to manually uncomment the [homes] part in Share Definitions. Now start the Samba server using systemctl start smbd nmbd and make them enable by default using systemctl enable smbd nmbd.

Next we need to grant users' access to the Samba drives. Using

smbpasswd -a qjp

will add the user qjp to the local smbpasswd file, and we can log into Samba drives as user qjp now. The server settings are all done.

2.2 Client

Essentially there are no apparent settings required in client side. To see some useful information of a Samba server:

smbclient -L hostname -U username

Now we manually mount the remote drive to a local mountpoint, using one of the sharenames you see in the output of previous command:

sudo mount -t cifs //hostname/sharename /path/to/mountpoint -o

Since this command is executed using sudo, the uid and gid options are necessary as I want write-permission to the mountpoint as a regular user qjp, not root.

2.3 A Use Case

Now let us see a use case of how to work effectively by using Linux and Windows together.

I use \LaTeX{} to generate pdf files in Linux, and with a plugin named latex-preview-pane of Emacs, the pdf file will be automatically regenerated every time I save the modified \LaTeX{} source file. In order to make use of the large screen of the 27-inch monitor, I want to write \LaTeX{} source file in my ultrabook while viewing the generated pdf file in the Windows machine, which is connected to the 27-inch monitor.

While Evince and Okular all support auto-reloading of pdf files when they are changed in Linux, I only find that Sumatra PDF has the similar functionality in Windows(It is also said the Evince's Windows version has the auto-reloading feature but it doesn't work properly when I tested it). The problem here is when using Sumatra to view the pdf file in the drive of my Linux machine via Samba, Sumatra will not automatically reload the pdf file when I regenerate it. It is not wierd because in the OS level, the file change notification isn't sent to the Sumatra in time, that is, Sumatra doesn't know that this pdf file has already been regenerated so it won't reload it. It is Samba's fault. From Samba's documentation here, there is actually a global option in the Samba server, named change notify timeout, which defaults to 60 seconds. Making this number smaller seems to solve this problem. However, the documentation said "Performing these checks too often can slow down the server considerably", so it is not feasible to make it small enough in order to achieve the effect of instant updating of the pdf files.

Currently the best solution I could think of is to synchronize the generated pdf file between Linux and Windows. Then Sumatra will open the pdf file locally, and every time I regenerate the pdf file in Linux, the file should be copied to Windows instantly. The file synchronization tools such as Dropbox are not fast enough to achieve this, so writing a simple shell script would be better. There is a package named inotify-tools in Arch's official repository, which contains a tool that could monitor the state changes of a particular file or directory. You could find some examples here. The script I use for this case is really simple:

inotifywait -m -e close_write example.pdf | while read foo; do cp example.pdf
/path/to/mountpoint/Documents/example.pdf; done

inotifywait will monitor the close_write events of example.pdf. Once it is regenerated, copy the new file to Windows via Samba. Then Sumatra will reload the new pdf file. This process is very fast.

3 Share keyboard and Mouse Between Laptops

In order to switch between different laptops seamlessly, I need to control the Windows on the other laptop using the keyboard and mouse of my Linux ultrabook. The first solution I thought of was to install a third-party VNC server on Windows(I have to do so because there is no built-in support in Windows 8.1, which is neither a pro nor enterprise version, to act as a remote desktop server) and use a VNC client to connect to the server so that I could use my keyboard and mouse of my Linux ultrabook to control the Windows. I could put the VNC client in a separate activity of KDE to make the switch more comfortable.

The above solution seems quite good, except that I don't really need to view the Windows desktop in the VNC client since I have the large-size monitor already. It is a waste to transfer the data and consume the CPU computation power. Luckily, I found this thread on superuser, which said that Synergy was good to solve this. Actually, it is. We could easily install it from Arch's official repository. Follow the instructions on this page to set up the server on Arch Linux. You could use the example configuration file, /etc/synergy.conf.example, or the GUI tool to generate the configuration file. I manually edited the aliases section to associate the hostnames with their corresponding IP addresses so that it is unnecessary to change the hosts file of the operating system.

I would make the Windows machine act as the client. However, at the time of writing, the lastest version, 1.4.15 Beta, still doesn't fix the bug of alt+tab mentioned in this issue. But someone else in that issue thread has already fixed that and applied his/her patch to version 1.4.14, which would make the alt+tab behave normally in Windows 8. You could find the download addresses for the patched versions in that issue. I'm suprised that the author doesn't apply that patch, which was quite simple and came out earlier than the new version was released.

After using Synergy for a while, I would say it is really a great piece of software. It is very fast. The Windows machine behaves like the extended desktop for my Linux. I could simply move the cursor to switch between them, which is really awesome.

4 Conclusion

OK. These are all my settings to make use of multiple laptops together. I could now take advantage of both Linux and Windows to finish different kinds of tasks. Most of my working is done under Linux, and Windows is mainly used for entertainment and viewing Microsoft Office documents. I also have the high DPI screen as well as the large Full HD screen to work at the same time, which makes working at home really an enjoyment. Every available device now works very well, except for the old and poor Ubuntu laptop. It could only serve as a internal file server and SSH server. Up until now, I couldn't think of anything interesting to make use of it:(.

Junpeng Qiu 09 February 2014
blog comments powered by Disqus