Easy Thinking

Friday, October 16, 2015

Docker-engine install error libdevmapper1.02.1

Author: 

You have Vivid installed, and the necessary package with the required version (2:1.02.99) is in Wily. Therefore use the Vivid version of docker. Edit /etc/apt/sources.list.d/docker.list via
sudo nano /etc/apt/sources.list.d/docker.list
and replace the content with
deb https://apt.dockerproject.org/repo ubuntu-vivid main
and update the package database
sudo apt-get update

It's also possible to install the packages in Vivid
cd
wget http://mirrors.kernel.org/ubuntu/pool/main/l/lvm2/dmsetup_1.02.99-1ubuntu1_amd64.deb
wget http://mirrors.kernel.org/ubuntu/pool/main/l/lvm2/libdevmapper1.02.1_1.02.99-1ubuntu1_amd64.deb
sudo dpkg -i dmsetup_1.02.99-1ubuntu1_amd64.deb libdevmapper1.02.1_1.02.99-1ubuntu1_amd64.deb
If you have problems with the packages, downgrade via
sudo apt-get install libdevmapper1.02.1=2:1.02.90-2ubuntu1 dmsetup=2:1.02.90-2ubuntu1

Tested in my Vivid system
% apt-cache policy libdevmapper1.02.1 
libdevmapper1.02.1:
  Installed: 2:1.02.99-1ubuntu1
  Candidate: 2:1.02.99-1ubuntu1
  Version table:
 *** 2:1.02.99-1ubuntu1 0
        100 /var/lib/dpkg/status
     2:1.02.90-2ubuntu1 0
        500 http://archive.ubuntu.com/ubuntu/ vivid/main i386 Packages

Wednesday, September 30, 2015

what invalids Docker build cache

Author: kim hirokuni
Source: http://kimh.github.io/blog/en/docker/gotchas-in-writing-dockerfile-en/


Docker creates a commit for each line of instruction in Dockerfile. As long as you don’t change the instruction, Docker thinks it doesn’t need to change the image, so use cached image which is used by the next instruction as a parent image. This is the reason why docker build takes long time in the first time, but immediately finishes in the second time.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
$ time docker build -t blog .
Uploading context 10.24 kB
Step 1 : FROM ubuntu
 ---> 8dbd9e392a96
Step 2 : RUN apt-get update
 ---> Running in 15705b182387
Ign http://archive.ubuntu.com precise InRelease
Hit http://archive.ubuntu.com precise Release.gpg
Hit http://archive.ubuntu.com precise Release
Hit http://archive.ubuntu.com precise/main amd64 Packages
Get:1 http://archive.ubuntu.com precise/main i386 Packages [1641 kB]
Get:2 http://archive.ubuntu.com precise/main TranslationIndex [3706 B]
Get:3 http://archive.ubuntu.com precise/main Translation-en [893 kB]
Fetched 2537 kB in 7s (351 kB/s)

 ---> a8e9f7328cc4
Successfully built a8e9f7328cc4

real  0m8.589s
user  0m0.008s
sys   0m0.012s

$ time docker build -t blog .
Uploading context 10.24 kB
Step 1 : FROM ubuntu
 ---> 8dbd9e392a96
Step 2 : RUN apt-get update
 ---> Using cache
 ---> a8e9f7328cc4
Successfully built a8e9f7328cc4

real  0m0.067s
user  0m0.012s
sys   0m0.000s

However, when cache is used and what invalids cache are sometimes not very clear. Here is a few cases that I found worth to note.

Cache invalidation at one instruction invalids cache of all subsequent instructions

This is the basic rule of caching. If you cause cache invalidation at one instruction, subsequent instructions doesn’t use cache.

1
2
3
4
5
6
7
8
9
10
# Before
From ubuntu
Run apt-get install ruby
Run echo done!

# After
From ubuntu
Run apt-get update
Run apt-get install ruby
Run echo done!

Since you add Run apt-get update instruction, all instructions after that have to be done from the scratch even if they are not changed. This is inevitable because Dockerfile uses the image built by the previous instruction as a parent image to execute next instruction. So, if you insert an instruction that creates a new parent image, all subsequent instructions cannot use cache because now parent image differs.

Cache is invalid even when adding commands that don’t do anything

This invalidates caching. For example,

1
2
3
4
5
# Before
Run apt-get update

# After
Run apt-get update && true

Even if true command doesn’t change anything of the image, Docker invalids the cache.

Cache is invalid when you add spaces between command and arguments inside instruction

This invalids cache

1
2
3
4
5
# Before
Run apt-get update

# After
Run apt-get               update

Cache is used when you add spaces around commands inside instruction

Cache is valid even if you add space around commands

1
2
3
4
5
# Before
Run apt-get update

# After
Run                apt-get update

Cache is used for non-idempotent instructions

This is kind of pitfall of build caching. What I mean by non-idempotent instructions is the execution of commands that may return different result each time. For example, apt-get update is not idempotent because the content of updates changes as time goes by.

1
2
From ubuntu
Run apt-get update

You made this Dockerfile and create image. 3 months later, Ubuntu made some security updates to their repository, so you rebuild the image by using the same Dockerfile hoping your new image includes the security updates. However, this doesn’t pick up the updates. Since no instructions or files are changed, Docker uses cache and skips doing apt-get update.
If you don’t want to use cache, just pass -no-cache option to build.

1
$ docker build -no-cache .

Instructions after ADD never cached (Only versions prior to 0.7.3)

If you use Docker before v7.3, watch out!

1
2
3
4
From ubuntu
Add myfile /
Run apt-get update
Run apt-get install openssh-server

If you have Dockerfile like this, Run apt-get update and Run apt-get install openssh-serverwill never be cached.
The behavior is changed from v7.3. It caches even if you have ADD instruction, but invalids cache if file content is changed.

1
2
3
4
5
6
7
8
9
10
11
$ echo "Jeff Beck" > rock.you

From ubuntu
Add rock.you /
Run add rock.you

$ echo "Eric Clapton" > rock.you

From ubuntu
Add rock.you /
Run add rock.you

Since you change rock.you file, instructions after Add doesn’t use cache.

Hack to run container in the background

If you want to simplify the way to run containers, you should run your container on background with docker run -d image your-command. Instead of running with docker run -i -t image your-command, using -d is recommended because you can run your container with just one command and you don’t need to detach terminal of container by hitting Ctrl + P + Q.
However, there is a problem with -d option. Your container immediately stops unless the commands are not running on foreground.
Let me explain this by using case where you want to run apache service on a container. The intuitive way of doing this is

1
$ docker run -d apache-server apachectl start

However, the container stops immediately after it is started. This is because apachectlexits once it detaches apache daemon.
Docker doesn’t like this. Docker requires your command to keep running in the foreground. Otherwise, it thinks that your applications stops and shutdown the container.
You can solve this by directly running apache executable with foreground option.

1
2
3
4
5
6
7
$ docker run -e APACHE_RUN_USER=www-data \
                    -e APACHE_RUN_GROUP=www-data \
                    -e APACHE_PID_FILE=/var/run/apache2.pid \
                    -e APACHE_RUN_DIR=/var/run/apache2 \
                    -e APACHE_LOCK_DIR=/var/lock/apache2 \
                    -e APACHE_LOG_DIR=/var/log/apache2 \
                    -d apache-server /usr/sbin/apache2 -D NO_DETACH -D FOREGROUND

Here we are manually doing what apachectl does for us and run apache executable. With this approach, apache keeps running on foreground.
The problem is that some application does not run in the foreground. Also, we need to do extra works such as exporting environment variables by ourselves. How can we make it easier?
In this situation, you can add tail -f /dev/null to your command. By doing this, even if your main command runs in the background, your container doesn’t stop because tail is keep running in the foreground. We can use this technique in the apache case.

1
$ docker run -d apache-server apachectl start && tail -f /dev/null

Much better, right? Since tail -f /dev/null doesn’t do any harm, you can use this hack to any applications.

Saturday, March 7, 2015

Install TP-LINK TL-WN723N Wifi adapter driver on Raspberry Pi

source:
http://www.raspberrypi.org/forums/viewtopic.php?p=462982#p462982


by MrEngman » Mon Dec 02, 2013 10:22 pm
Driver files available for the TP-LINK TL-WN725N V2 and similar wifi dongles using the 8188eu driver module for systems using the Raspbian image.

IMPORTANT: First check the version of Linux you have. Use the command uname -a to find the version of Linux.
CODE: SELECT ALL
pi@raspberrypi ~ $ uname -a
Linux raspberrypi 3.10.24+ #614 PREEMPT Thu Dec 19 20:38:42 GMT 2013 armv6l GNU/Linux
pi@raspberrypi ~ $
The important part is 3.10.24+ #614. This is just an example and your version may be different. Select the right driver for the version you have from the list below.

This driver supports wifi modules with the following USB IDs
CODE: SELECT ALL
ID 2001:3310
ID 2001:330F
ID 07B8:8179
ID 0BDA:0179
ID 0BDA:8179

and for 3.12.28+ and newer the addition devices:

ID 056E:4008
ID 2001:3311
ID 0DF6:0076
With the wifi dongle connected to your Pi use command lsusb to show a list of USB devices connected to your Pi. You should see your wifi module in the list and the USB ID of the device which you can check is in the list above. If it is read on to find the device driver you need and how to install it.


rtl8188eu drivers for 3.6.11+
CODE: SELECT ALL
3.6.11+ #371 up to #520 inclusive    - 8188eu-20130209.tar.gz
3.6.11+ #524, #528, #532             - 8188eu-20130815.tar.gz
3.6.11+ #538, #541, #545, #551, #557 - 8188eu-20130830.tar.gz

rtl8188eu drivers for 3.10.18+ to 3.10.38+
CODE: SELECT ALL
3.10.18+ #577       - 8188eu-20131105.tar.gz
3.10.18+ #579, #585 - 8188eu-20131106.tar.gz
3.10.18+ #587       - 8188eu-20131110.tar.gz
3.10.18+ #590, #592 - 8188eu-20131111.tar.gz
3.10.18+ #594, #596 - 8188eu-20131113.tar.gz

3.10.19+ #600       - 8188eu-20131113.tar.gz

3.10.21+ #602, #604 - 8188eu-20131113.tar.gz

3.10.22+ #606       - 8188eu-20131206.tar.gz

3.10.23+ #608       - 8188eu-20131209.tar.gz
CODE: SELECT ALL
3.10.24+ #610       - 8188eu-20131209.tar.gz
3.10.24+ #614       - 8188eu-20131219.tar.gz

3.10.25+ #616, #618 - 8188eu-20131219.tar.gz
3.10.25+ #622, #624 - 8188eu-20131219.tar.gz

3.10.26+ #628       - 8188eu-20140110.tar.gz

3.10.27+ #630       - 8188eu-20140117.tar.gz

3.10.28+ #632, #634 - 8188eu-20140117.tar.gz

3.10.29+ #636, #638 - 8188eu-20140117.tar.gz
CODE: SELECT ALL
3.10.30+ #640, #642 - 8188eu-20140117.tar.gz

3.10.32+ #646, #648 - 8188eu-20140117.tar.gz

3.10.33+ #654, #656 - 8188eu-20140117.tar.gz
3.10.33+ #658       - 8188eu-20140117.tar.gz

3.10.34+ #660, #661 - 8188eu-20140117.tar.gz

3.10.36+ #662, #664 - 8188eu-20140117.tar.gz
3.10.36+ #665, #666 - 8188eu-20140117.tar.gz

3.10.37+ #667, #669 - 8188eu-20140117.tar.gz
CODE: SELECT ALL
3.10.38+ #675       - 8188eu-20140117.tar.gz
rtl8188eu drivers for 3.12.xx
CODE: SELECT ALL
3.12.18+ #673, #677 - 8188eu-20140425.tar.gz
3.12.18+ #679, #680 - 8188eu-20140501.tar.gz

3.12.19+ #681, #682 - 8188eu-20140509.tar.gz
3.12.19+ #684       - 8188eu-20140509.tar.gz

3.12.20+ #685, #686 - 8188eu-20140509.tar.gz
3.12.20+ #687       - 8188eu-20140509.tar.gz

3.12.21+ #688, #689 - 8188eu-20140509.tar.gz

3.12.22+ #690, #691 - 8188eu-20140616.tar.gz
CODE: SELECT ALL
3.12.23+ #692       - 8188eu-20140626.tar.gz

3.12.24+ #693, #694 - 8188eu-20140705.tar.gz

3.12.25+ #698, #700 - 8188eu-20140705.tar.gz
3.12.25+ #701       - 8188eu-20140705.tar.gz

3.12.26+ #702, #703 - 8188eu-20140705.tar.gz
3.12.26+ #704, #707 - 8188eu-20140705.tar.gz
3.12.26+ #708       - 8188eu-20140705.tar.gz

3.12.28+ #709, #710 - 8188eu-20140908.tar.gz
3.12.28+ #712, #713 - 8188eu-20140908.tar.gz
CODE: SELECT ALL
3.12.29+ #714, #715 - 8188eu-20140908.tar.gz

3.12.30+ #717       - 8188eu-20141017.tar.gz

3.12.31+ #718, #720 - 8188eu-20141026.tar.gz

3.12.32+ #721       - 8188eu-20141107.tar.gz

3.12.33+ #722, #724 - 8188eu-20141107.tar.gz

3.12.34+ #725, #727 - 8188eu-20141107.tar.gz

3.12.35+ #730, #733 - 8188eu-20141107.tar.gz
CODE: SELECT ALL
3.12.36+ #737       - 8188eu-20150114.tar.gz

Drivers for 3.18.xx+. See note below for installing 3.18.xx+ and 3.18.xx-v7+ drivers
CODE: SELECT ALL
3.18.3+ #739, #740 - 8188eu-20150120.tar.gz
3.18.3+ #741, #742 - 8188eu-20150120.tar.gz

3.18.5+ #744, #746 - 8188eu-20150130.tar.gz
3.18.5+ #748       - 8188eu-20150130.tar.gz

3.18.6+ #753, #754 - 8188eu-20150208.tar.gz

3.18.7+ #755, #756 - 8188eu-20150212.tar.gz
3.18.7+ #757       - 8188eu-20150212.tar.gz

3.18.7+ #758, #759 - 8188eu-20150223.tar.gz
CODE: SELECT ALL
3.18.8+ #761, #763 - 8188eu-20150227.tar.gz
3.18.8+ #764, #765 - 8188eu-20150227.tar.gz
Drivers for 3.18.xx-v7+ (Pi 2)
CODE: SELECT ALL
3.18.5-v7+ #746, #748 - 8188eu-v7-20150202.tar.gz

3.18.6-v7+ #753, #754 - 8188eu-v7-20150208.tar.gz

3.18.7-v7+ #755, #756 - 8188eu-v7-20150212.tar.gz
3.18.7-v7+ #757       - 8188eu-v7-20150212.tar.gz

3.18.7-v7+ #758, #759 - 8188eu-v7-20150223.tar.gz

3.18.8-v7+ #761, #763 - 8188eu-v7-20150227.tar.gz
3.18.8-v7+ #764, #765 - 8188eu-v7-20150227.tar.gz
NOTE: the driver files for 3.18.xx+ and 3.18.xx-v7+ contain two additional files, install.sh and 8188eu.conf. Download the driver file selecting the right driver for your kernel version from the list above then to install the 3.18 drivers first untar the tar.gz driver file and then run the install.sh command.eg.
CODE: SELECT ALL
wget https://dl.dropboxusercontent.com/u/80256631/8188eu-2015yyzz.tar.gz
tar xzf 8188eu-2015yyzz.tar.gz
./install.sh
change yyzz in the wget and tar commands to select the right driver file. install.sh will install the driver file and copy the file 8188eu.conf to directory /etc/modprobe.d. The 8188eu.conf file will disable power management for the 8188eu driver and disable the inbuilt driver version r8188eu.


Link to driver files - use date code from list above to download required driver
CODE: SELECT ALL
https://dl.dropboxusercontent.com/u/80256631/8188eu-201xyyzz.tar.gz


NOTE: If updating firmware revisions, say from 3.10.23+ to 3.10.24+, and they use the same driver, in this case 8188eu-20131209.tar.gz, you will still need to reinstall the driver on the newer version of Linux, even though the driver has not changed as it will be loaded from a different directory by the new Linux revision and you need to install it in the new directory.

The driver installation instructions expect you to be using Raspbian, either installed from a basic rasbian image or installed using NOOBS. The instructions are based on running from a Command Line Terminal, not a GUI (Graphical User Interface). If you are running using the GUI you will need to open a terminal window and run the commands from the terminal window but I can't guarantee they will work.

If you have a wired internet connection install the driver with the following commands
CODE: SELECT ALL
wget https://dl.dropboxusercontent.com/u/80256631/8188eu-201xyyzz.tar.gz <--set above="" br="" code="" data="" driver="" for="" version="">tar -zxvf 8188eu-201xyyzz.tar.gz                                         <--set above="" br="" code="" data="" driver="" for="" version="">sudo install -p -m 644 8188eu.ko /lib/modules/$(uname -r)/kernel/drivers/net/wireless
sudo insmod /lib/modules/$(uname -r)/kernel/drivers/net/wireless/8188eu.ko
sudo depmod -a

If you do not have an internet connection the driver file will need to be downloaded on another computer and copied to the SD card. I use a Windows laptop and will use that as an example of how to copy and install the wifi driver.

Open a web browser on your Windows computer and download the driver. Check the name of the driver file before saving it and correct it if necessary. I have sometimes found Windows tries to save the driver file as 8188eu-201xyyzz.tar.tar when it should be 8188eu-201xyyzz.tar.gz. Substitute the correct file name for "xyyzz".

Take the SD card and load it into an SD card reader on your Windows computer. Copy the driver file, 8188eu-201xyyzz.tar.gz, from your Windows computer to the SD card. Safely remove the SD card from the card reader by clicking the safe removal icon in the task bar and install the SD card in your Raspberry Pi and power on and login.

After logging in you will need to copy the driver file to your home directory. How you do this is dependent on whether you installed rasbian using NOOBS or directly from a Rasbian image. If you are running raspbian installed using NOOBS you need to run the following commands to copy the driver file to your home directory
CODE: SELECT ALL
sudo mount /dev/mmcblk0p1 /mnt
sudo mv /mnt/8188eu-201xyyzz.tar.gz .
sudo umount /dev/mmcblk0p1
You will need the period, full stop (.), after the filename in the sudo mv command. The mount/umount commands are required as the driver file is in the NOOBS boot directory, not the rasbian boot directory, so the NOOBS boot directory needs mounting and accessing to get to the driver file.

If you installed raspbian directly from a rasbian image use the following command to copy the driver file to your home directory
CODE: SELECT ALL
sudo mv /boot/8188eu-201xyyzz.tar.gz .

Now the driver file has been moved to your home directory the driver installation can be completed using the following commands
CODE: SELECT ALL
tar -zxvf 8188eu-201xyyzz.tar.gz                                         <--set above="" br="" code="" data="" driver="" for="" version="">sudo install -p -m 644 8188eu.ko /lib/modules/$(uname -r)/kernel/drivers/net/wireless
sudo insmod /lib/modules/$(uname -r)/kernel/drivers/net/wireless/8188eu.ko
sudo depmod -a

Once the driver is loaded you will need to configure the network set up so the Pi will connect to your wifi network if it is not already done. There are some basic details on how to do that available here.

To help in installing or updating the driver @LaFambe has produced a very simple script available here which will automatically select and install the correct version of the driver for the version of Raspbian being used. I was quite impressed by it and it really does make life much simpler. You will need an internet connection for the script to work.

Thank you very much, LaFambe.


MrEngman

Monday, January 26, 2015

Install bcm2835 library for the Raspberry Pi

source: https://gist.github.com/annem/3183536

fix this error:

fatal error: bcm2835.h: No such file or directory

cd;
// wget http://www.open.com.au/mikem/bcm2835/bcm2835-1.5.tar.gz; // My Pi can't figure out this URL
wget http://67.192.60.197/mikem/bcm2835/bcm2835-1.5.tar.gz
tar xvfz bcm2835-1.5.tar.gz;
cd bcm2835-1.5;
./configure;
make;
sudo make install

Friday, July 5, 2013

Decode Android APK file to get source code

Author:  prankul garg
Procedure for decoding .apk files, step-by-step method:

Step 1:

Make a new folder and put .apk file in it (which you want to decode). Now rename the extension of this .apk file to .zip (eg.: rename from filename.apk to filename.apk.zip) and save it. Now you get classes.dex files, etc. At this stage you are able to see drawable but not xml and java files, so continue.

Step 2:

Now extract this zip apk file in the same folder (or NEW FOLDER). Now download dex2jar from this linkhttp://code.google.com/p/dex2jar/ and extract it to the same folder (or NEW FOLDER). Now open command prompt and change directory to that folder (or NEW FOLDER). Then write dex2jar classes.dex and press enter. Now you get classes.dex.dex2jar file in the same folder. Then download java decompiler from http://java.decompiler.free.fr/?q=jdgui and now double click on jd-gui and click on open file. Then open classes.dex.dex2jar file from that folder. Now you get class files and save all these class files (click on file then click "save all sources" in jd-gui) by src name. At this stage you get java source but the xml files are still unreadable, so continue.

Step 3:

Now open another new folder and put these files
  1. put .apk file which you want to decode
  2. download apktool v1.x AND apktool install window (both can be downloaded at the same location) and put in the same folder
  3. download framework-res.apk file and put in the same folder (Not all apk file need framework-res.apk file)
  4. Open a command window
  5. Navigate to the root directory of APKtool and type the following command: apktool if framework-res.apk
  6. apktool d "fname".apk ("fname" denotes filename which you want to decode)
now you get a file folder in that folder and now you can easily read xml files also.

Step 4:

It's not any step just copy contents of both folder(in this case both new folder)to the single one
and now enjoy with source code...