Torch7 install in Fedora 22

[UPDATE 25/06: The patch that i wrote for Fedora 22 support has been merged upstream. Hence, the steps on Torch7 website can be used directly instead of following the below steps.]

Fedora is and will always be my first choice for a distro.. Given that I wrote about installing Torch7 in Ubuntu 15.04 recently, how could we leave behind Fedora!!

Unfortunately, the Torch install-dependencies script is hardcoded to support Fedora 20. I have made some changes to the script which makes it support Fedora 22 as well, and have made it available as a github gist (Torch7 install Fedora 22). Have also raised an issue and supplied a patch to the original developers of the script.

Enjoy ‘Torch’-ing away to glory on Fedora 22!!! πŸ™‚

Thick bottom border of titlebars in Gnome 3.16

This is supposedly a bug affecting Gnome 3.16.

However, if this issue is too much of an eye-sore for you too, there’s a simple way to remove this, as detailed in this archlinux blog.The change in appearance is best represented by the below screenshots.

This is the thing I truly love about Linux distros.. if you dont like something, just change it as per your wish! πŸ™‚

Bottom border thickness

Bottom border thickness

Bottom border thickness removed

Bottom border thickness removed

Install Torch7 in Ubuntu

I feel that the install steps listed at the official website of torch have a couple of issues:

  1. it assumes that some of the build system dependencies have been already installed, such as cmake, curl, etc.
  2. One of the cmake steps in file involves explicit use of luajit2.1, which supposedly is broken in Ubuntu, as listed in this issue.

The following step effectively solves the issue#1 listed above:

#install build related dependencies
sudo apt-get install curl cmake git build-essential \
python-dev libxml2-dev libxslt-dev libfftw3-dev \
libsox-dev libssl-dev

To solve the build error listed in issue#2, open the file in the torch source folder and edit the following line:




That’s it! Now delete the build/ folder in torch root directory and restart the build process..

Graphical view of new Android kernel flashing

A picture speaks a thousand words.. Hence, summarizing my experience from the previous two days, below is the graphical overview of new Android kernel flashing steps:

Android kernel flashing steps

Android kernel flashing – graphical overview

Key to the above figure:

  • Items in RED : things to be downloaded from the internet.
  • Boxes in GREEN : Step#1 of the new kernel install – making flashable kernel zip.
  • Box(es) in WHITE : Step#2 of the new kernel install – installing modules.
  • Boxes in YELLOW : a step producing multiple things, and used individually.

Solving “WiFi not working” issue after new kernel install on an Android device

Yesterday I managed to successfully install a self-built kernel onto my test Android phone. The major visible issue that cropped up was that of WiFi not working. After going through several blogs, have finally solved the issue :), thanks mainly to a great point mentioned on a geeksphone blog (point no. 9). I’ll summarize the issue and the solution here:

The filesystem present on the Android device contains several kernel modules at the location /system/lib/modules.These may have been compiled using an unknown toolchain (android-ndk or Linaro or Sabermod, etc.). Personally, am using Sabermod-4.7-32bit toolchain, given that I have a 32-bit linux OS installed on my laptop.

This mismatch in toolchains results in the zImage created by our kernel-build, and the several .ko files already present in devices’ /system/lib/modules being incompatible, and thus issues like WiFi not working crop up!

To solve this, copy all the .ko’s generated during our kernel build to the devices /system/lib/modules. This can be achieved through the following steps:

# cd to kernel source directory
cd kernel-src-dir/

#copy all kernel modules from kernel source directory
find . -name '*ko' -exec cp '{}' custom-dir/ \;

#mount the device after plugging it into the USB
adb shell mount -o remount,rw /system
for filename in custom-dir/*
  adb push `basename $filename` /system/lib/modules/

#reboot the device
adb reboot

Thats it! Next time you reboot, WiFi should be working as normal with your own new, shiny custom kernel.. Enjoy!!

Foray into Android Kernel hacking

A post after ages.. and we begin a new journey into the world of (Linux’s cousin) Android kernel hacking.

Presently, have taken baby steps in this field involving:

  • building the kernel from source using default defconfig of my device. Thanks to cheatman for the kernel source for my test device.
  • Thanks to excellent explanation provided at this xda link, kernel build was almost a cakewalk!
  • Kernel build produces a zImage, which is a compressed image of the kernel. Next step involves packaging the kernel into a form that a custom recovery installed in your Android devices can read it (FYI, I am currently using CWM Recovery).
  • Kernel packaging involves the following steps:
    1. Extract ramdisk (or, initramfs on older devices) from an existing boot.img. This can be obtained from freely downloadable flashable kernel zips corresponding to one’s device.
    2. Use this ramdisk along with the built zImage to create a new boot.img
    3. Create a zip out of this boot.img and META-INF folder that was obtained from flashable kernel zip in 1).
  • The linux tools for performing the above can be obtained from this link.
  • Once the zip is ready, copy it to your sdcard, boot to recovery and select option : install from zip and select your flashable kernel file.

Finally, a screenshot from my device πŸ™‚

Screenshot of new kernel install from device's settings view

Screenshot of new kernel install

A major problem am facing presently is that WiFi on this device is not working since the new kernel install. Will try to figure out the issue and post an update soon.

ginput() in opencv-python

The Image Processing Toolbox in MATLAB has this very useful utility called as ginput, which allows manually picking co-ordinate points from an image. I tried to recreate that functionality in python based OpenCV, and the result is the following code:

import cv2
import numpy as np
from matplotlib import pyplot as plt
import os

a = np.array([0,0], dtype='float32')
def getXY(imgPath):

   DEBUG = 1

 print "-------------------------------"
 print "Using OpenCV version : ",cv2.__version__
 print "-------------------------------"

 print "TASK : Mimic getxy() feature of MATLAB"
 print "***************************************"

 except KeyError:
    #print "For verbose mode, set DEBUG flag"
    DEBUG = 0

 #define the event
 def getxy(event, x, y, flags, param):
   global a
   if event == cv2.EVENT_LBUTTONDOWN :
      a = np.vstack([a, np.hstack([x,y])])
      if (DEBUG):
      print "(row, col) = ", (x,y)

   #Read the image
   img = cv2.imread(imgPath)
   if (DEBUG):
      print "Reading the image..."

   #Set mouse CallBack event
   cv2.setMouseCallback('image', getxy)
   if (DEBUG):
      print "Set MouseCallback functionality..."

   #show the image
   print "Click to select a point OR press ANY KEY to continue..."
   cv2.imshow('image', img)

   #obtain the matrix of the selected points
   b = a[1:,:]
   if (DEBUG):
      print ""
      print "The clicked points..."
      print b, b.dtype, b.shape

   print "The selected points are returned as a float64 MATRIX..."
   return b

Steps to use it :

  • save the above source code as in your working directory.
  • In your python code, import this file, i.e.,

from getXY import *

  • Pass the image path to getXY, and start clicking on the displayed image. The no. of times you click, those many points will get saved.
  • If you want a verbose version, set the environment variable DEBUG = 1 from the terminal before running the code, i.e.,

DEBUG=1;Β export $DEBUG

That’s it! I’ll upload the code onto a git repo as well soon and provide a link here as well.

  • To remove the verbose code, unset the DEBUG variable, i.e, :

unset $DEBUG

vnstat – keeping an eye on your network bandwidth

Once we leave the haloed portals of our alma mater, accessing the internet ceases to be a luxury it once used to be. Keeping an eye on network bandwidth usage in order to stay within data pack limits becomes utmost important. In such a scenario, a simple and extremely elegant command line tool called vnstat comes to our rescue.

  • To begin using vnstat, install it:

$ sudo yum install vnstat

  • Now, we need to tell vnstat which interface to monitor. First check the list of interfaces available on your system:

$ ip link show

This will print something like the following :

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: p2p1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN mode DEFAULT qlen 1000
link/ether 00:16:d3:26:73:dc brd ff:ff:ff:ff:ff:ff
3: wlp3s0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000
link/ether 00:16:cf:18:57:6c brd ff:ff:ff:ff:ff:ff
4: wwp0s29f7u2i1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000
link/ether 58:2c:80:13:92:63 brd ff:ff:ff:ff:ff:ff
5: ppp0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN mode DEFAULT qlen 3

  • On my system, am interested in the mobile broadband connection (ppp0). Hence, we point vnstat to monitor it :

$ sudo vnstat -u -i ppp0

  • Now, make vnstat daemon auto start at boot :

$ sudo systemctl enable vnstat.service

  • Unfortunately, vnstat log file gets created as a root and not as a normal user. Hence, we need to change its permissions to allow vnstat to write data to it. This step will remove the frustrating

ppp0: Not enough data available yet.

issue. Simple type the following to change owner and group:

$ sudo chown <owner_name> -R /var/lib/vnstat/*

$ sudo chgrp <group_name> -R /var/lib/vnstat/*


  • As pointed out by Jim, on a multiuser system, it may make more sense to allow everyone to have read-write permissions, that is if the admin so desires. In such a scenario we need to run the following:

$ sudo chmod a+rw -R /var/lib/vnstat/*

  • And we are done! From next boot, vnstat will start logging your network bandwidth. To see realtime / live usage statistics, type:

$ vnstat -l

For non-realtime data:

$ vnstat

There is an excellent article on various vnstat options on Linuxaria. Happy internet-ing without burning a hole into your pocket.