Saturday, December 5, 2015

Upgrading all the brew cask packages in one command

Here is a nice (and simple) way to upgrade all your Homebrew cask packages at a single command.

All credits goes to Yann-R that wrote here the following command:
brew cask install `brew cask list`

Works perfectly.

Note that you can also run this command using the -f flag (force) to force installation.

- Tal Kain

Wednesday, September 16, 2015

ipython && tmux - saving history to a file


I had an ipython console open inside a tmux split window and I needed to save the history to a file.
Since I can't copy & paste the data from the screen (I was in the middle of a session, so the next time I would configure it correctly using this).

So I found a quicker way, Roberto Z wrote in his comment that in order to save the session's history you can use readline package:

import readline

This works like a charm in Ubuntu.

- Tal Kain

Wednesday, September 9, 2015

Linux: iptables: Removing a collection of iptables rules at once

Here is a small trick for removing several iptables rules at once,

Let's assume we would like to add some rules:
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
I can use the comment match and add a comment to this line:
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE -m comment --comment "SOME_COMMENT"

Now, cleaning all the relevant rules in a simple command would be:

# iptables-save | grep -v SOME_COMMENT | iptables-restore

 Probably not the best way to do it, but it's simple and fast.

Have fun,
-Tal Kain

Wednesday, September 2, 2015

Installing NVIDIA CUDA on an Amazon Web Services (AWS) machine (Ubuntu 14.04)

Disclaimer: I wrote this post several months ago and did not publish it for unknown reason, I assume that the information below is still relevant and correct.

While trying to install the machine, I started my research by reading Traun Leyden's great blog post: (you should too)

Amazon offers two types of machines that includes GPUs (
High-performance NVIDIA GPUs, each with 1,536 CUDA cores and 4GB of video memory
While writing this post, I used the g2.2xlarge machine, but you can also use the 8xlarge.

This will be quick and simple:

1. Make sure you are fully up-to-date
sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade
 When prompted, choose the "install maintainer package...."

2. Reboot the machine (so it will load the new kernel)
3. Install the kernel's header files
sudo apt-get install -y linux-image-extra-virtual linux-headers-`uname -r`
3. Configure the xorg-edgers PPA

sudo add-apt-repository ppa:xorg-edgers/ppa
sudo apt-get update
4. Install the NVIDIA's CUDA repository package
wget -O ${OUTPUT_PATH}
dpkg -i ${OUTPUT_PATH}

 5. Update the package manager and install CUDA
sudo apt-get update
sudo apt-get install cuda
6. Make sure everything is installed as expected:
sudo nvidia-smi -a

7. You can also compile and run a sample to make sure everything is ready:
cd /usr/local/cuda/samples/1_Utilities/deviceQuery

That's all!

- Tal Kain

Saturday, March 21, 2015

Ubuntu Linux: cannot find modules.dep.bin

While trying to load some kernel modules in one of my projects, I encounter the following errors:
root@ubuntu:~# modprobe carl9170
modprobe: ERROR: ../libkmod/libkmod.c:556 kmod_search_moddep() could not open moddep file '/lib/modules/3.10.17/modules.dep.bin'

and the following error:

modprobe: ERROR: ../libkmod/libkmod-index.c:821 index_mm_open() magic check fail: d00dfeed instead of b007f457

To solve this issue, run depmod
# depmod

"depmod creates a list of module dependencies, by reading each module
under /lib/modules/version and determining what symbols it exports, and
what symbols it needs. By default this list is written to modules.dep
in the same directory. If filenames are given on the command line,
only those modules are examined (which is rarely useful, unless all
modules are listed)."

After running depmod, everything should work as expected.

- Tal Kain

Friday, February 6, 2015

Ubuntu: schroot cannot bind the home directory

Hey everyone,

Several weeks ago I had to compile gdb and strace to a target device that runs on ARM (EBI). 
This time, instead of cross compile it, I decided to use my favorite way - schroot environment.

I had the pleasure of using schroot on my old system - an Ubuntu 12.04 desktop, and this was the first time I needed to use it on my current Ubuntu 14.04 system.

The problem started after creating the schroot environment and trying to use it.

As you will see in the following lines, I tried getting into the environment and got an error:

root@ubuntu:/home/talkain# schroot -c ubuntu-armel -u talkain
W: line 11 [ubuntu-i386] union-type: Configuration key name ‘union-type’ is not a permitted name.
W: line 11 [ubuntu-armel] union-type: Configuration key name ‘union-type’ is not a permitted name.
W: Failed to change to directory ‘/home/talkain’: No such file or directoryI: The directory does not exist inside the chroot. Use the --directory option to run the command in a different directory.W: Falling back to directory ‘/’

This was weird, since the directory exist, I had permissions to this directory (this is my home directory) and this was a fresh installation of this environment.

After digging a little bit, I found an excellent start point here:

So I looked at the schroot's config file:

[ubuntu-armel] description=ubuntu-armel groups=sbuild,root root-groups=sbuild,root # Uncomment these lines to allow members of these groups to access # the -source chroots directly (useful for automated updates, etc). #source-root-users=sbuild,root #source-root-groups=sbuild,root type=file profile=sbuild union-type=overlayfs file=/var/lib/schroot/tarballs/ubuntu-armel.tgz
So in order to solve this error, I changed the schroot configuration file's parameter called "profile" from sbuild to default as follows:
and now I can get into the schroot environment with no issues.

Hope this helps,
- Tal Kain

Thursday, January 22, 2015

Ubuntu: Installing a missing ath3k firmware

While trying to prepare a new Ubuntu box to use a new card based on the Atheros chipset, I encounter the following error:
Bluetooth: Firmware file "ath3k-1.fw" not found

According to
ath3k is the Linux Bluetooth driver for Atheros AR3011/AR3012 Bluetooth chipsets.
I saw this blog post:
So I decided to try installing the package linux-firmware which contains the relevant file (I used dlocate to
$ dlocate linux-firmware | grep -i ath3
linux-firmware: /lib/firmware/ath3k-1.fw
or you can find it by searching for ath3k:
$ dlocate ath3k-1.fw
linux-firmware: /lib/firmware/ath3k-1.fw
I just ran:
# apt-get install linux-firmware

and it fixed it by installing the missing firmware file.

Good luck!
Tal Kain