Fixing Screen Tearing on Linux Mint 17.3

I’m on Nvidia GF770 GTX, there is a decent, though proprietary, driver for my GPU from Nvidia but what bothers me a lot is that even despite having the correct driver with 3D-capabilities, able to run demanding 3D games I am still having a trivial issue of screen tearing in games and videos.. I have tried to enable V-Sync wherever I found the setting to no effect: still the same ugly tearing all over the video or a game scene.

After some research on the topic I decided to give Compton a try and because it has resolved the issue for me I stopped at this solution, here is the detailed guide on how to set this thing up:

Raspberry Pi 3 B as Media Center

Over the weekend experimented with OpenELEC Linux flavor for Raspberry Pi 1 B. Experimented with wired and wireless connection options, unfortunately in all cases performance was very laggy on high quality HD movies, if 720p was ok in some cases, 1080 was never played at an acceptable level. I compare it with Intel NUC which I setup for media center some time ago and now using it for different purposes – comparison is very bleak, if NUC is fully capable as media center, from playing music and movies to viewing vacation photos then RPi only able to play music somewhat ok. Still I have used Xonar USB audio because embedded sound produced noticeable static when playing music.

I understand that I compare something that costs ~600 EUR to something around ~50 EUR and it does not seem fair.. Anyways, I decided to give a shot at newer model of Raspberry Pi – model 3 B. Just ordered it at Will update this post once I get my hands on what is in the kit, here is the list I got in my mailbox, accompanying my order:

Supreme Kit Including NEW Raspberry Pi 3 Model B
– Includes Raspberry Pi: Raspberry Pi 3 B **R..
– Raspberry Pi Case: Raspberry Pi Foundat..
– Select Case Colour: Official Black and G..
– Micro SD Card Size: 8GB w/ Official Adap..
– Power Supply Select: Black Universal 5V 2..
– Video Cable Select: HDMI – Black – 2m **..
– USB Cable Select: Standard – Black – 1..
– RJ45 Cable Select: Black – 2m **CAB-000..
– Keyboard & Mouse Select: Wireless – Ultra-Min..

It Has Arrived!


Please note that Asus Xonar U3 was not part of the package, I use this external audio card in conjunction with Raspberry because Pi’s internal audio has too much interference and the situation did not change for the better with this newer model, sound output is as noisy as it was on RPi 1.

This new model came with 8GB flash card that had NOOBS installed on it. I have selected OSMC from the list of possible operating systems and installed it. Please note that you have to plug the wire into the Ethernet socket in order to get some other OS different from Raspbian, this is because NOOBS will download the needed OS from Internet, which would have been possible with WiFi too but unfortunately NOOBS does not support wireless and it seems it won’t get such support in foreseeable future, so get your Ethernet ready before powering on the RPi.

What was interesting about the package is this: Rii mini wireless keyboard with touchpad (and laser pointer). From previous experience with standalone media players running Linux, sometimes problems happen that require mouse and keyboard to be hooked to the player in order to fix the issue, so previously I was taking the devices from my workstation, plugging those into the player, fixing the issue and plugging the devices back to the workstation. Not anymore! Rii is going to be very close to the RPi device, always ready to intervene in case of an issue that cannot be solved with Kodi Remote (using Kore on Android phone).



You can configure anything and everything, as I mentioned above I am using additional sound card with RPi and I had no issues setting the sound output to the card instead of RPi analog output or my TV’s HDMI. There was slight annoyance though – I had to increase buffer size because some particularly large videos were not playing smoothly. Just create file called advancedsettings.xml with this code:


And copy the created file to /home/osmc/.kodi/userdata/. Just mind that you have to SSH into your RPi running OSMC and create file there, not on your workstation 🙂 Login / pass for default OSMC installation is osmc / osmc.


Split Traffic Per Process

The task at hand: route traffic from different processes to 2 distinct wifi adapters. First adapter is switched to normal wifi, second to the router with persistent vpn connection. I need an ability to chose which process will use which adapter.

I have searched for solution and found very similar here:

So, just adapted the above solution a little bit to suit my needs and summarized my changes below.

You have to replace several things in this script first of all user name, my username is kr0st, which is not a terrible secret 🙂 Anyway, should be replaced with yours.
My second wifi adapter is called “wlx001ee5ef5604” by the OS, most likely your second network adapter is named differently.
Finally this is my gateway for the second wifi:, yours could be different as well.

Please note that script resets everything you have in your iptables! Change it if you can’t allow script to do that. The script should be run as root, btw.

As a final step the script runs an instance of Firefox in which you can search “my ip” and see if traffic really goes via this route and not the default one.


mkdir /sys/fs/cgroup/net_cls/vpnonly
cd /sys/fs/cgroup/net_cls/vpnonly
echo 0x00110011 > net_cls.classid

iptables --flush
iptables --table nat --flush
iptables --delete-chain

iptables -t mangle -A OUTPUT -m cgroup --cgroup 0x00110011 -j MARK --set-mark 11
iptables -t nat -A POSTROUTING -m cgroup --cgroup 0x00110011 -o wlx001ee5ef5604 -j MASQUERADE

#!Run next line only once, all subsequent script calls should have it disabled
#echo 11 vpnonly >> /etc/iproute2/rt_tables

ip rule add fwmark 11 table vpnonly
ip route add default via table vpnonly

for i in /proc/sys/net/ipv4/conf/*/rp_filter; do echo 0 > $i; done

cgcreate -t kr0st:kr0st -a kr0st:kr0st -g net_cls:vpnonly
cgexec -g net_cls:vpnonly firefox&

Weird Mouse Behavior on VMWare Workstation Player 12

Used Linux Mint 17.3 as host and Windows 8.1 as guest.

Problem: dropdown lists seem to scroll to the last item on their own and it does not happen all the time, it appears random.
Cause: not sure if it is the root cause but strangely enough it was not mouse driver or 3D acceleration settings as advised on some forums, in my case it appeared to be keyboard layouts. I had 2 languages for input (on host OS) – English and Russian. So when host switches to Russian language – the problem manifests, when host input is English everything is normal.

To fix it I now work with VM only when my host is set to English and I have also changed keyboard shortcuts for switching languages so they are different in host and guest (guest also has 2 input languages).

I have also noticed that any mouse movement results in scrolling, so you move the mouse and dropdown list scrolls – this is only when host OS input language was not English. That’s it for the problem and resolution, hopefully I will save some time on this thing next time.

Plex, Twonky, XBMC & NUC

DLNA was out there for quite a while now, call me a slowpoke but I finally decided to give it a try!

First question that needs to be answered is WHY? Well, if you have a bunch of stuff like music, movies and photos on your home file server (NAS) it is likely you want to have some convenient way of accessing all those riches preferably from all your devices and in a more or less the same way – this is exactly what DLNA server on your NAS does for you. If you have one that is – some NAS devices come equipped with DLNA server right out of the box but if your file server is not a commercially available NAS but some custom solution, like maybe ageing PC turned into a file server then you have to add DLNA capabilities yourself.

Second question is WHAT? And here is what you need to get going:


Media centre that is able to find available UPnP devices on local network and play the content. Versions of this media centre is available for Linux, Android, Windows and OSX at least. I should note that for OSX I have also tried the alternative – PlugPlayer. Cannot say I was too impressed with it though because mostly I was seeing this screen below while trying to use PlugPlayer:
PlugPlayer dies again

My advise is to stick to XBMC/KODI.

Another very nice thing about XBMC/KODI is the remote control capabilities – you have to enable control over HTTP in the settings menu and after that you will be able to control the playback with Android app for example.

Plex or Twonky

Both of them are quite popular server side solutions that have Linux versions (my file server is running Linux) so I decided to try one of these first and see if I am good or should explore the alternatives.

I have started with Twonky and got a show-stopper issue right out of the box: scaling of the photos did something very ugly to the pictures – everything became very low resolution and blocky, pixelated. There are some solutions to try like this one for example but it did not work for me, after couple of hours of fruitless tinkering I decided to say goodbye to Twonky and move on to the alternatives.

Enter Plex – media server with a very good Web frontend that could do anything really be it playing video, music, browsing photos or configuring the server itself. It worked as expected immediately and you do not really have to create Plex account to use it, so I opted out and still got what I needed.
There was no issues and especially that nasty rescaling of photos was gone, picture quality was great.

Of course other solutions are out there like minidlna, for instance but Plex worked well for me and I decided to not fix what is not broken. There is one feature though that is heavily discussed online – accessing your content outside of your LAN. This is possible via Plex account and paid membership (I think so but did not actually try, so may be wrong). However people also write that you could have something like this done with SSH port forwarding feature just forwarding correct ports from the PC running Plex to your router with external static IP.

XBMC/Plex integration

To get all the content from your server shown on your XBMC/KODI media centre you have to add UPnP source for each of the sections – Music, Video, Pictures. However there is a different way of getting much more significant integration with proper search capabilities like that of a native Plex client. This could ‘theoretically’ be achieved by using PleXBMC addon (installed beta4 version because others gave me errors) I just did not try it yet so probably update the post once I have some positive experience with this addon.

One very annoying thing to keep in mind without the addon – search in XBMC/KODI will not work with your remote server, meaning that searching for anything will give you 0 results whatever you do. What you have to do is use ‘filtering’ instead of searching, meaning you have to get inside the directory on your remote server and once there, use the sliding menu on the left screen border to enter filter, so you get only entries that pass your filter. Not sure why XBMC is not recreating some local version of remote media database for search to work but this is how it is. Maybe I am doing something wrong but I was not able to figure out how to make search work.


The last part of the equation, not required by the way – a dedicated device that is always on, connected to LAN and a TV, hardware media player. There is nothing stopping you from running XBMC/KODI on whatever platform and device like your laptop for example. I just wanted a new toy so decided to try and turn some micro PC into a media player running Linux + XBMC/KODI hooked to my TV.

There definitely are many alternatives to NUC and cheaper ones however NUC is quite powerful, having i5 CPU, supporting 16 gigs of RAM and SSD HDDs. Basically a real PC but very small-sized. Opting for NUC gave me more flexibility to do something more with this little thing later – not just media player. Talking strictly about media player functionality Raspberry Pi would have been a way cheeper choice though very limiting in terms of hardware power and compatibility (it’s ARM, not x86/64 architecture, no normal version of Windows for instance).

I have decided to install Linux Mint 17.2 on my NUC, it is Long Time Support release so I’m all set until 2019! Windows would also work perfectly fine but where’s fun in that? As much as I would enjoy all these new spyware features in Windows 10 I would still prefer gewd ol’ reliable Linux which is also happens to be free as in free beer sense 🙂 By the way even Intel published a guide on making media centre box out of NUC using Linux Mint & XBMC. Didn’t use the guide though but maybe this one will be useful for somebody out there.

The best advice I got about NUC was from some blog post (unfortunately do not remember which post exactly) recommending UEFI boot – that really got NUC booting up instantaneously. Setting up Linux on NUC definitely use UEFI boot partition, search the web for guide on that if you need.

Overall my experience with the whole setup was quite positive but yeah, there are several annoyances, see below.

Annoyance #1: sporadic wake-ups from suspended state, fixed by turning off wake on LAN feature in BIOS.
Annoyance #2
: XBMC simply hangs after running for many hours straight in idle mode (i.e. not being used actively). No real fix for this one for now, seems I am using the latest version of KODI already, so I have just set up a cron job that restarts KODI during the night time.
Annoyance #3
: do not expect NUC to be completely silent during heavy load (using all CPU cores close to 100% utilisation) it has a very little fan and noise level is that of a small laptop. This does not happen during playback though but will happen during some CPU-intensive operations like creating large archives for example.

I would like to end this post with a little photo-session, so please welcome, NUC!



Reusing RDP session on Linux

This continues to be a pain every time I install new Linux distro on some device I need remote access to:

If you install whatever is available on Ubuntu / Mint (and I suspect a number of other Linux flavors) – say xrdp + tightvnc, what you get is non-persistent remote desktop session, meaning once you disconnect, it’s gone and next time fresh new session will be created.

What you have to do is just go there ->
Download this stuff as zip, unpack and run ‘‘. That’s it! It will take care of all dependencies, will compile and install x11rdp for you. I think this is really all you have to do, however you might still need to provide server side of the equation – something like x11vnc – unfortunately do not remember that because did the operation couple of days earlier before writing this post, which shows that writing those posts is a great idea because my memory sux 🙂

One last thing – if using remmina RDP client you are getting SEGFAULTs, try setting color to 24bpp and/or update.

UPDATE [20.03.2016]: It seems later versions of Ubuntu, after introducing systemd (15.04?) require one last step to make xrdp working, the step is to go to /lib/systemd/system/ folder and delete 2 files: xrdp.service and xrdp-sesman.service. After this step you will be able to control xrdp via /etc/init.d/ as before systemd. More details on the problem and solution here:

Archive repos for discontinued Ubuntu versions

This is bad advice for lazy ass Linux user, in this case my future self.

Some time ago, trying to update my Linux box, I realized that I cannot do that – package repositories return some 404-like error, cannot find any content in the official repos.
Of course I immediately started to search for mirror repos but it turned out to be much more tricky..  Finally I learned that non-LTS distribution packages go to special archive repos after support of the distribution version is officially discontinued and you will be able to find all the packages there.

So, here they are, couple of lines that saved me a lot of time and allowed me to continue using aging Ubuntu repo:

deb saucy main universe restricted multiverse
deb saucy partner

In my case these lines ended up inside /etc/apt/sources.list.d/additional-repositories.list
Just replace saucythere with code name of your distro version and you are good to continue using your old distro exposing yourself to all the possible security threats out there.. ENJOY!

Backup Your Files

After the important files are in order and synced between devices we sort of get them backed up this way to a certain extent of course – this backup will not make your workstation boot into OS again in case something bad happens with HDD or boot partition.. Below is the list of software I use for full partition/HDD backup.


Acronis True Image: it’s commercial, used it for years, restored backups successfully several times, allows creating live-cd to boot and restore HDD.


clonezilla + partclone: use for full disk backup, free as in beer & speech but make sure you have the compatible pair because clonezilla depends on partclone and in my case (Mint 17 disrto) default partclone was incompatible with default clonezilla version (issue was -z param of partclone). Seems the easiest way to get both correct versions of clonezilla and partclone is to use “Clonezilla Live” distribution on USB stick, installed using tuxboot.

You need a live-cd to boot & backup because partition/HDD you plan to backup has to be unmounted. I was actually looking into using Acronis for Linux but did not feel very enthusiastic about the price of this edition – it seems only Enterprise edition works on Linux with price tag around 1000$..

Deja Dup: home directory incremental backup/restore.


Time Machine? Not sure yet because did not set up backup on my Mac. Will be trying out that option but I’ve read it is now incompatible with Samba shares, however a workaround is available – will test that and update the post.

UPDATE (10.09.2015)
After almost a year I am finally ready to update this post with my OSX preference and this is SuperDuper!, whole disk backup.

Sync Your Files

Was thinking about making sense of “My Documents” folder for a long time already. This folder looks like the trash can on every device I have – basically a collection of stuff that is needed and relevant, that was relevant some time ago and stuff that should have been deleted around 10 years ago..

I have copies of old document folders archived from my previous work stations and laptops – everything is unstructured and of course I won’t find a needed doc without spending hours decompressing archives and searching and searching and searching..

Finally I gathered enough determination to stop this – put everything in order and make sure this structured way of storing my important files will transcend my current workstation, laptop, tablet, you got the idea. SO there will be the same folder with important stuff on every next system without manually copying and archiving everything and for that I need some software to sync my important stuff between the devices and OSes.

This is not a review therefore I am not going to compare all the alternatives I found, this is basically a message to my future self to refresh memory on the good stuff related to files sync.

Box – good sync clients for Windows and OSX, however to get proper files sync on Android I had to use different app – Auto Box Sync because as of now Android Box app does not offer automatic files sync – you have to select what you want to upload or download manually every time.

At the time of this post Box gives you 10GB free storage which is enough for my files, there are some limits like 250 megs per 1 file but you can lift the restrictions to 5GB per file and 100GB in total storage for 10$ a month.

UPDATE (10.09.2015)
On Linux you could easily use box without Box Sync app but with WebDav. You need to install davfs2 and configure it correctly, see this link for great description.

Why not Dropbox? It gives less space for free and it syncs all folders on all devices by default or so it seems, Box gives me a possibility to select which folders to sync and which not to. I do not sync all docs on my Android devices – only part due to the space restrictions but I still have the full sync benefits because I can put a file in a folder on my PC for sharing between Android devices and this file will appear on my phone and tablet.

That is not all though – if you have your own file server with stuff you do not want to be on the cloud or the total size is too large and cloud-storing this amount is too expensive then you need an app that would be able to run in the background and periodically sync over Samba/FTP/WebDAV/etc.

There is a free app for that with a very straightforward name – FreeFileSync however for that app to work you need some additional ground work like mapping your network location to some local file system path/drive.

I decided that I do not want to be doing that and would not like to have 2 points of potential failure instead of 1 (drive mapping failure or file sync app failure instead of just file sync app potential failure) so I used commercial alternative GoodSync which is ~30$ per workstation (Win or OSX) and used Synchronize Ultimate for Android. It has some in-app purchase options, most likely I used those but do not remember the actual cost, most likely it was something like couple of EUR.

Couple of words on security for the paranoid among us – yes it is possible your stuff will be snatched from the cloud but the chance your laptop would be stolen is much higher, the same goes for your phone. The simple conclusion is that you have to encrypt your home folder where your synced files are stored and you have to encrypt the device if we are talking about Android devices.

Use BitLocker for Windows, FileVault for OSX and EncFS for Linux.


Using Lua for Log Message Filters

Here is how the public API of fplog looks like:

//One time per application call.
FPLOG_API void initlog(const char* appname, fplog::Transport_Interface* transport = 0);

//Mandatory call from every thread that wants to log some data.
//Done to increase flexibility:
//each thread will have its own filters configuration and
//can decide independently which stuff to log.
FPLOG_API void openlog(const char* facility, Filter_Base* filter = 0);

//Optional but advised to call from each thread that logs data right
//before stopping and exiting the thread.
//Doing this will free some memory (amount is really small)
//that is needed to support logging from a given thread.
//Not doing closelog() does not lead to memory leak
//because everything will be deallocated in any case on app exit,
//fplog frees its resources when implementation class instance is destroyed.
FPLOG_API void closelog();

//Scope of filter-related functions is a calling thread -
//all manipulations will apply to calling thread only.
FPLOG_API void add_filter(Filter_Base* filter);
FPLOG_API void remove_filter(Filter_Base* filter);
FPLOG_API Filter_Base* find_filter(const char* filter_id);

FPLOG_API const char* get_facility();

//Should be used from any thread that opened logger,
//calling from other threads will have no effect.
FPLOG_API void write(Message& msg);

It resembles syslog closely however extended with per-thread message filtering capabilities along with few other things. Today I would like to concentrate on the filters because I was playing around with several ideas in this regard for couple of days now and the idea that has beaten the competition is to use Lua for log message filtering.

The thing is log message could contain many fields in addition to mandatory that only the log message author could know, therefore it would be nice to allow a fellow programmer to create as complicated filter passing condition as he likes. Well, but we do not need Lua for that, right? There is Filter_Base class that basically has 1 method that accepts log message and as a result tells true/false meaning message should pass further or be suppressed.

It works in case the only way we would be making adjustments in filtering conditions is by modifying the source code: creating new subclasses of Filter_Base that implement the filtering conditions we see fit. However as soon as there is an idea to change filter without modifying the source code the need for loading filters from something like config file arises.

I was thinking about some simple filters where you have only a small subset of logical operations and comparisons you could do, about regular expressions or some other pattern matching but everything what initially seemed simple turned into rather inflexible and/or complex stuff. Therefore step by step I approached the idea of using some existing scripting solution for filters and Lua was the obvious choice – lightweight and easily embedded into C++ code.

So, it goes like this:

  • there is an instance of Lua interpreter running all the time inside fplog – it is not created and destroyed for each message;
  • json.lua module in addition to all the standard Lua libs is loaded;
  • fplog_message object is available from Lua script, this object is an actual log message converted from json to native Lua tables structure (nested tables are possible – same as nested json objects);
  • Lua filter script should call filter_result function with true/false parameter in the end to inform the C++ code to either pass the message further or suppress it.

Of course the performance might be an issue, especially taking into account my intent of trying out fplog on embedded devices that could run Linux. Each log message would need to go via one or more Lua-based filters before it is potentially transported to a log collecting daemon via IPC. I will definitely need to run some tests and of course Lua-based filtering would be optional – if you do not need to be able to fine-tune logging “on-the-fly” via config files or some other methods then you will not be forced to use Lua filters.

Actually even without Lua you could implement several filters inside your application the will be pre-made and hardcoded but still it does not prohibit you from using config file to select a combination of pre-made filters to apply.