RSS Feed

Use WiFi router as switch


My workplace uses WiFi everywhere. Yet, my office room has a very poor WiFi signal. I was not sure whether it is poor signal problem or the ISP problem or any other problem, my Internet connection is suffered from the instability. When I use the Internet, or sending email, it is slow like heck and the messenger always disconnected from time to time. This is really annoyance. No Internet is better than slow or unstable Internet, because I need not wasting time to try to check mail or try to search information. Really wasting time.

Since my office room has an Ethernet cable port on the wall, and I was told by my colleague that using the cable is stabler and faster than using WiFi. Therefore, I decided to install a router in the room for me and my colleague. Without actual networking knowledge, I have to look for the information, and I found this page.

Since I do not have much information about the network topology of my workplace, I just try the solution and it works! In my workplace, when connected to WiFi network, then I can use the network printer and have Internet connection. My computer is assigned with IP address and also DNS servers IP addresses are given.

Thus, in order to install the router, yet can still connected to the network printer, online, and automatically obtain the IP address, I have to disable the NAT and DHCP server so that the router works as bridge or switch only.

I connected the computer to the Ethernet port on the wall to get the IP address of the default route and some other information such as DNS servers.

Since the router was no more acting as a router, and it did not assign IP address to the connected machine, with the available feature, I configured the router to use the remote DHCP server.

Enable the WiFi access point, then I can connect to the router with the wireless network and work as expected.

Since the network is using another IP address class, so I cannot access my router unless I configure my connection to connect to the router.

Though the connection is smooth and stable, there is a drawback. When using some Arch Linux commands such as yaourt or cURL, the connection does not work properly. Yet I have no idea how to solve this problem.

 

2014-10-29

The problem of yaourt and cURL I faced was showing the message such as “port: 80 No route to host” when using yaourt, or “curl error: Couldn’t connect to server” when using cURL, for some domains. After looking for some information from Internet, some forums mentioned that it is caused by IPv6 problem, by disabling it, the problem can be solved.

I have tried to disable it from the Network Manager. Then I found that it is not the solution. To disable the IPv6 effectively, I have to disable it from sysctl too. Now everything works fine.

(Without the router, there is no such problem. I am not sure that whether the router is configured incorrectly.)

Running multiple Firefox with different versions in Linux


Previously, in my post of the other blog, I mentioned that I have to use command-line to run multiple Firefox with different versions. Now, I found an easy solution to solve this problem. Please note that, running different version of Firefox should using different profile, just to avoid downgrading and upgrading the profile based on the Firefox version.

Assuming we installed Firefox Nightly version,

  1. Firstly, using the command-line to create a new profile using ProfileManager,
    firefox-nightly --no-remote -ProfileManager
  2. Then create a profile, such as “Nightly” as the profile name. After creating this profile, we can exit the Profile Manager.
  3. Make sure that we did not change our default profile, that means running “firefox” or “firefox-nightly” will use “xxxxxxxx.default” profile. This also means that whenever we run Firefox, the “xxxxxxxx.default” profile will be used.
  4. To run the Firefox Nightly version without entering the command-line “firefox-nightly –no-remote -P Nightly”, we can create the “desktop” file to the ~/.local. We can do this by copying the installed “desktop” file, such as
    cp /usr/share/applications/firefox-nightly.desktop ~/.local/share/applications/

    This will copy the firefox-nightly.desktop to the ~/.local/share/applications/ and override the default “desktop” file.

  5. Edit the ~/.local/share/applications/firefox-nightly.desktop, at the Exec key, change it to
    Exec=firefox-nightly --no-remote -P Nightly %u

    This will result that when we launch the Firefox Nightly from the Applications Menu, the “Nightly” profile will be used instead.
    As a result, we need not to use the command-line to run the instance with different profile.

Now, you can enjoy Firefox with Nightly, Aurora, Beta, or any other Firefox versions in one OS.

List installed AUR packages but removed or renamed in AUR


Recently I found that, even the packages in the AUR are renamed, the AUR helper such as yaourt also cannot solve. When I prepared to ask for some solution in the Arch Linux BBS, I just think that it is possible to solve it myself. Finally, I come out with the following script,

#!/bin/bash
#
# @author	Allen Choong
# @date		2014-09-04
# @version	0.0.1
#
# This script is to identify the installed AUR packages, to check whether they are still
# available in the AUR. This is because some packages are renamed or removed.

#Get the packages
packages=(`pacman -Qmq | sort`)


#For each of the package, check with the AUR
packagesStr=''
for x in ${packages[@]} ; do
  packagesStr+="'$x' "
done

packagesOnAur=(`/bin/sh -c "package-query -A -f '%n' $packagesStr | sort"`)

#As the rule of thumb, the installed packages are more than packages checked in the AUR
for((i=0;i<${#packagesOnAur[@]};i++)) ; do
  j=0
  while [[ $j -lt ${#packages[@]} ]] ; do
    if [[ ${packagesOnAur[$i]} == ${packages[$j]} ]] ; then
      unset packages[$j]
      packages=("${packages[@]}")
      break
    fi
    ((j++))
  done
done

for x in ${packages[@]} ; do
  echo $x
done

The script requires package-query. It will list out all the installed packages which are not found in the AUR. This includes the packages we installed ourselves locally, or deleted or renamed packages in the AUR.

Machine learning


Machine learning is one of my favourite studies (though I am not very knowledgeable in machine learning). It impressed me very much during my first time entering the lecture of the course. I was wondering how can a machine learn? I know how searching and optimisation work, they are just trial-and-error to get almost all the possibilities. But how a machine learn?

How does it work?

The simplest example is using the perceptron. It is a very basic Artificial Neural Network (ANN) concept. It can be used to learn a very simple pattern. (All the learnings are related to the pattern.) Perceptron simulates the neurons of the brain. In human, when we learn something, the connections of the neurons become stronger. In perceptron, the connections of the neurons are represented as the “weights“. The stronger the weight, the stronger the connection.

In a nerve cell (neuron), the electrical signal will only be activated when a certain threshold is reached. Similarly, in the perceptron design, the activation function will be used so that the value (represents the signal) will be transferred when triggered.

Perceptron is a supervised learning. Meaning that, the machine will only learn when someone/something is supervising it, that is the machine must be told whether the output is correct or incorrect during the process of learning. The differences of the desired output (from the supervisor) and the actual output (from the perceptron) is called error. Thus, the purpose of the learning is to reduce the error, so that the actual output is as similar as the desired output. This is just like a child who starts to learn something and supervised by the parents.

In order to let a machine to learn, the machine must be given a set of training samples. The machine will update the weights of the neurons when given the training. The weights will be updated in each training. The training sample set should be large and diverse so that the machine will “experience” various conditions. Each sample can be trained several times. The order of the training sample can be randomised. Each round of training with all samples, we called it as an epoch. Thus, the more epochs it goes, the mean squared error will theoretical be reduced.

The training of the machine can be ended if the mean squared error is close to zero. This indicates that the machine can produce the actual outputs that are very close to desired output. Another condition to end the training is when the mean squared error does not reduced for many cycles of training consecutively. This indicates that, there is no more improvement on the weights any more even more epochs are run. (Please bear in mind that, not all information has a pattern, such as a sequence of random numbers, there is no pattern so that there is no way to learn from the random.)

The last condition to let the machine to end is the number of  epochs reaches the user defined number, such as 1000 or more. That means, after a long time of learning, the weights is not stabled and the mean squared error is not reduced to the desired level. So, the training just ended because the training does not improve the machine any more.

After the machine is trained, the machine can be given a set of testing samples. The testing samples should not derived from the training samples. This is to evaluate the performance of the machine. Zero error in the training samples does not indicates zero error in the testing samples. Normally, the testing samples are the real world data and also our actual input. Only after the testing samples produce the satisfying result, the machine can only be considered success.

Learning rate

There is a very interesting mathematical formula for the machine to learn, especially perceptron. In order to update the weights, the weights need to be added (or substracted) by a value. The calculation of the weight is

wi(t+1) = wi(t) + α ⋅ e ⋅ xi(t)

where wi(t+1) is the new weight, wi(t) is the current weight, α is the learning rate, e is the error, xi(t) is the current input value of the neuron.

The interesting part is the learning rate. It is a value within the interval of [0,1]. The higher the learning rate, the more changes of the weights for each update (training); the lower the learning rate, the less the changes of the weights. The higher learning rate will results faster learning, but not guarantee an optimal result (because the changes is too big); the lower the learning rate, the slower the learning, yet it may produce better result than higher learning rate.

So does our learning. Some children, they are fast learner, but their learning performance is dropping when they get older. Yet, some children are slow learner, then the performance becomes better and better when they grow older.

Over-train

If the training samples given to the learning machine contain limited patterns, yet in fact the real world problems contain wider range of the patterns, and the machine is trained with these samples thoroughly, this will result over-train. That is the machine weights are totally adapted to the given pattern. When given another set of training samples (which contains other patterns), the machine will will need to have a longer time to be trained or even may be failed. That is why, randomize the training samples are important during the training.

This is exactly similar to us. If we are “over-trained” with something, we will stick to it, and difficult for us to change, such as our language, our habits, our hand-writing, etc.

Momentum

In the ANN, the training process will sometimes produce a long time of static stage, that is, no more improvement after many epochs. This is sometimes a local optima, which we may think that this is the optimal result. In fact, continue with more epochs, this local optima will be passed and a better result will be produced (global optima).

Metaphorically, this is just like a ball rolling down from the mountain to get the lowest point, yet due to the rugged surface, the ball will stuck at some point. With the momentum (stronger power) to move the ball, the ball may by pass the small peak to reach the bottom. (The peak indicates larger error; the bottom indicates the minimal error).

Interestingly, when we learn something, we will often reach a bottleneck. This bottleneck make us feel no improvement and boring. With the further persistent like momentum, we can possibly by pass this bottleneck to reach a higher level of what we are learning.

Implications

Because of this machine learning, I learnt something else in my learning method.

  • The machine can learn, with just 2 input neurons and 1 output neuron can demonstrate a simple learning. Yet our brain is even more complex, why can’t we learn?
  • A machine can learn with the supervision. This is why supervision from the superior to the subordinate is sometimes important, especially when the subordinate is a beginner.
  • When we learn, we are trying to figure out the pattern. Just like playing games, doing maths, learning a language, learning a skill, etc. In the example of doing maths, the more questions we do, the better our mathematical skills. Because we experienced various types of questions. This is just like the large set of training samples improve the machine learning.
  • When we learnt a skill from book or from some other learning materials, and we can solve the problems perfectly, yet this doesn’t mean that we can solve the real world problem as well. This is just like the training sample set and the testing sample set.
  • Slow learner is not necessary more inferior. Stable and smooth learning seems work better.
  • If a person is over-trained to certain patterns, he/she will stick to the pattern.
  • In order to surpass our learning bottleneck, we need perseverance.

Unsupervised learning

Interestingly, the perceptron algorithm was developed during 1957. Then unsupervised learning methods are developed. In my opinion, the development of these algorithms just like a human life. When we are children, we need parents and teachers to supervise our learning, to tell us what is right and wrong. When we have reached the reasoning age, we can learn by ourselves little by little. And this is the unsupervised learning.

 

P/S: The parents can recognise/differentiate their twin children, this is because they are over-trained to differentiate them. For people not familiar, will see the twins as identical. Yet the parents can differentiate, because they “learn” them everyday for years.

Linux containers (LXC) on Arch Linux


Due to a recent Q&A from DistroWatch.com, I am considering the advantages of using the scheduled-release or fixed-release distros, especially Debian which is famed of its stability. The following is the quote from DistroWatch.com,

Rolling releases do tend to have their downsides though. For instance, it is difficult for third-party developers to create software for rolling-releases as a rolling-release distribution is a moving target. It is difficult to target and support an operating system which is changing on a regular basis.

I agree with this point, because I have to change the source code on my old project which uses CEGUI. Moreover, latest PHP source code may not work on the web hosting server, due to the version differences. Though some people argue that rolling release like Arch Linux is not stable, yet I am very satisfied with its stability. The only thing is the compatibility problem to our own source code and other distros or OSes.

Because of this problem, the Debian is always my interested distro. Yet Debian packages are normally not up-to-date, and there is no Mozilla Firefox in its official repository due to the strong philosophy in Debian.

Running the different OSes in the virtual machines such as VirtualBox and Qemu with KVM is a very good solution. However, both solutions show a strong feeling that an OS (guest) within another OS (host). VirtualBox is really useful because of the configuration of the bridged network is very easy. Moreover, the USB devices sharing allows to use the Windows in the VirtualBox to do the printing and using the interactive projector (which beyond my expectation). On the other hand, Qemu is difficult to setup the bridged network. (But Android Emulator is using Qemu.)

There are some disadvantages on VirtualBox. The 3D graphics do not work properly in VirtualBox (I didn’t try on Qemu about 3D graphics). However, we can still install the Direct3D drivers through the VirtualBox Guest Addition. Furthermore, the solutions of using VirtualBox and Qemu require to create virtual hard drives. That means, transferring the files requires some networking solutions such as FTP or SSH. Yet, VirtualBox allows easier solution that mounts the shared folder from the host.

Interestingly, when I come across to the Linux Containers (LXC), this shows an interesting alternative to the VirtualBox and Qemu. Unlike the VirtualBox or Qemu, the guest OS can be run almost side-by-side with the host OS.

Running GVim in LXC on Arch Linux

Running GVim in LXC on Arch Linux

Setup LXC network

There are some useful tutorials/documents regarding how to setup LXC on the Linux distribution on the Internet. However, I found some difficulties when setting up the LXC on the Arch Linux. In Arch Linux, the kernel does not support User Namespace for the LXC. Thus, the LXC has to run in root privilege.

(I will not explain some of the basic steps such as using the commands lxc-create, lxc-start, lxc-stop, etc.)

After creating the container, the network support is also very important, because by default, the container cannot access the network. The easiest way is using bridge.

To setup the bridge, we can use the netctl.

Create a static IP for the netctl,

#In the /etc/ctl/lxbridge
Description="LXC Bridge"
Interface=br0
Connection=bridge
BindsToInterfaces=(wlan0) #Depends which connection we want to bind, do not use multiple interface
IP=static
Address=10.0.2.1/24 #Any
FwdDelay=0

Then,

sudo netctl start lxcbridge

This will produce a bridge interface br0.

Then, similar to Qemu, iptables and IP fowarding are required.

sudo sysctl net.ipv4.ip_foward=1
sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE #where wlan0 can be others

Note: iptables is a must, despising whether the iptables service is started or not.

Then, in the “config” file of the created container, we have to setup the networking

lxc.network.type=veth
lxc.network.link=br0
lxc.network.flags=up
lxc.network.name=eth0
lxc.network.ipv4=10.0.2.2/24
lxc.network.ipv4.gateway=10.0.2.1 #Based on the Bridge address

Because of using the root, the lxc-usernet file is not required to be configured.

In order to run the GUI application, in the config file, we can add this

lxc.mount.entry = /dev/dri dev/dri none bind,optional,create=dir
lxc.mount.entry = /dev/snd dev/snd none bind,optional,create=dir
lxc.mount.entry = /tmp/.X11-unix tmp/.X11-unix none bind,optional,create=dir
lxc.mount.entry = /dev/video0 dev/video0 none bind,optional,create=file

After installing GUI application such as GVim in the guest, to run and use the display,

DISPLAY=:0 gvim

This will run the GUI application as on the host.

Setup LXC sound

In order to play the sound, this can be done through PulseAudio. (I mostly refers to this page.)

The easier way is using the paprefs on the host OS and “Enable network access to local sound devices” in the “Network Server” tab. However, it can also be done in the command-line,

pactl load-module module-native-protocol-tcp #no root required

(If referring to other tutorials, there are other parameters. But in my case, the above command is sufficient.)

Note: The above command is run on host OS.

Once the module loaded, in the guest (container), we can set the environment variable,

export PULSE_SERVER=192.168.1.2 #where the IP address is the host IP address

Then, using the mplayer on any audio file can play the sound successfully.

 

Please note that LXC does not work with non-Linux OS such as Windows. There are some available OS templates for the container, such as Debian, CentOS, Fedora, Gentoo,OpenMandriva, OpenSUSE, and Ubuntu. This is very interesting that we can use different package manager in one computer almost seamlessly working on the host OS.

So far I didn’t test the OpenGL in container. But running glxinfo, it shows the same output as the host computer. I expect that it is using the host display, so the OpenGL should have no problem.

 

What next?

My next intention is to make the container accessible through the LAN of the host OS. Needs time to figure it out.

elinks “Host not found” crash in Arch Linux


I have come across with this problem for quite a long time. Whenever I elinks to a website, such as google.com or yahoo.com, it shows the message “Host not found”. I tried to google about the “elinks host not found”, “elinks resolve problem”, etc, none of them are relevant to my problem.

I thought it is the package error. But when I come across installation of the Arch Linux on a fresh computer, the elinks works fine.

The elinks can browse the http://localhost without any problem. And if I browse a website with the IP address (not the domain name), and if the website does not have redirection, then it works fine also. I think the problem is happened when elinks is trying to resolve the domain.

When going to seek for the help in the forum, in order to prepare significant information to other users, I tried to gather the error message as much as possible. Then I come across with the following message and I typed it out in “leafpad” (since copy and paste does not work in the terminal emulator).

elinks(dump_backtrace+0x22)[0x80ff9c2]
elinks[0x80cf3da]
elinks[0x80cfa5c]
linux-gate.so.1(__kernel_sigreturn+0x0)[0xb77c1d28]
elinks(timeval_add+0xf)[0x810463f]
/usr/lib/libsamba-util.so.0(timeval_current_ofs+0x34)[0xb5d51b64]
/usr/lib/samba/libgse.so(name_query+0x87)[0xb5cabe87]
/usr/lib/libnss_wins.so.2(_nss_wins_gethostbyname_r+0x4e8)[0xb5f24148]
/usr/lib/libnss_wins.so.2(_nss_wins_gethostbyname2_r+0x32)[0xb5f242]
/usr/lib/libc.so.6(+0xd217c)[0xb703917c]
/usr/lib/libc.so.6(getaddrinfo+0xe8)[0xb703a798]
elinks(do_real_lookup+0x69)[0x80cb0a9]
elinks[0x80cb24d]
elinks(start_thread+0xc0)[0x80cf110]
elinks[0x80cb360]
elinks(find_host+0xaf)[0x80cb4af]
elinks(make_connection+0xac)[0x80cc15c]
elinks(http_protocol_handler+0x4f)[0x80e22df]
elinks[0x80c91e0]
elinks[0x80c994f]

From the error message, I found that there is something wrong about the libnss_wins.so.2. Then I remembered I have done something regarding the nss for the Samba before. Thus, I open the /etc/nsswitch.conf and found the “wins” in “hosts” key.

The following is the corresponding line,

hosts: files wins dns myhostname

I remembered that this setting was done long time ago, and elinks never faced this problem before. Just a trial-and-error, I remove the “wins” from the line and elinks to Google again. Now it works.

So, it is confirmed that the “wins” is a problem. Then I add the wins again and disable the sambad systemd service and run the elinks. The problem still exists. That means it is not the sambad service problem, but the nsswitch.conf.

As a result, I just put the “wins” after the “dns”. Now, elinks work fine.

As a conclusion, the “wins” can be added, but only after the “dns”. So that, the elinks will use the DNS to resolve the domain first instead of using libnss_wins.so to resolve the the Windows computer name before hand, which causes some errors. Problem solved.

Experience of flashing ROM to Samsung devices

Posted on

Previously, I wrote my experience about installing CyanogenMod on the old Samsung phone. There are something worth to know before flashing, other than backup the precious data, download the ROM and tools, and take for any risk.

In my experience, it is best to get the stock ROM (that is the original ROM or firmware). This is to prevent some unexpected outcomes. With the stock ROM, at least we can recover to the (true) factory setting.

In order to flash the ROM, rooting is not required. But with an un-rooted Android, the backup will only works on the SD card (internal or external) and backup feature from the apps themselves, such as WhatsApp conversation backup and Wechat conversation backup. That means, all the games data and other apps data cannot be backup.

Therefore, if possible, root the phone then backup the data with Titanium Backup, then we no need to save the data to the cloud.

Flash a ROM or root only?

In my opinion, flashing a ROM is simpler than just rooting a phone. In order to root the phone, the method is varied between the phones. But to flash the ROM, the method is similar (in my case, Samsung device only). (As I never successfully root the phone directly, even using the one-click rooting tool.)

Flashing a custom ROM, normally provides a lot of features especially superuser (root) and busybox. Both are my favourites, as I can adb shell to do a lot of things. However, if root only, then we need to install busybox ourselves. This may be time consuming. Furthermore, with root only, we may have difficulty to upgrade the Android version, such as from Froyo to Jelly Bean. Yet, if flashing the ROM, we can choose the version of Android that we prefer (normally the latest stable).

Benefits

Originality and genuineness is nice. Root an Android phone or flash in a custom ROM will void the warranty. If the warranty is expired, and the phone is “dying”, maybe flashing a new ROM is good solution to “renew” the phone. After flashing a custom ROM, you can enjoy the features provided by the ROM, especially root. So that you can install more powerful apps to your phone, including advertisement blocking apps.

Other than that, some new apps (such as games) require higher version of Android. The official firmware may only support to Ice Cream Sandwich. But, now already KitKat, you at least try to get Jelly Bean. But your Android is still Froyo or Gingerbread. Where is Honeycomb? You have missed a lot of things.

The best thing I like is busybox. With busybox, I can enjoy command-line in Terminal Emulator and also the adb shell to hack the device.

IMEI

After flashing the CyanogenMod, then I had a message about the invalid IMEI. This is seriously exhaustive when I want to restore it. Finally, I give up the IMEI.

In order to restore IMEI, I had done several things. Firstly, I re-flashed the stock ROM. Then the IMEI is restored. However, in order to preserve IMEI for the custom ROM, I have to backup the /efs folder. Yet, this folder cannot be accessed without the root permission. That is why, root is needed. I failed to root the phone. As a result, I used the psneuter method to gain the root access then used the busybox to “tar” the /efs folder.

According to the forums, if we have backup efs, then we can restore the IMEI. But, after I re-flashed the CyanogenMod, then I restored the efs folder, there is a message related to “not enough disk space”. Rebooted the phone, the phone then had a valid IMEI, but it could not call and no signal. This was worse than invalid IMEI. That is why I give up the IMEI.

Heimdall and Odin

In order to flash ROMs to Samsung devices, we need to use either Heimdall or Odin. I personally use Heimdall since I am using Linux. The stock ROM I obtained are the files end with tar.md5 extension. These files are compatible to Odin. However, they can be still flashed by using Heimdall. I used “tar xf” command to extract the tar.md5 files. As a result, I got some files like recovery.img, modem.bin, factoryfs.rfs, etc. These are the files that can be flashed with Heimdall.

Therefore, to flash with Heimdall, I can use a command like

heimdall flash --KERNEL zImage --CACHE cache.rfs --DBDATAFS dbdata.rfs --FACTORYFS factoryfs.rfs --MODEM modem.bin --PARAM param.lfs

For the parameters, such as --KERNEL, these are depending on the device. In order to know what parameters are available, we can use

heimdall print-pit

By these information, we can relate the parameters with the corresponding files.

During flashing, I caused my phone always boot into the Recovery Mode. The phone cannot boot into the Bootloader. I think that was because the files I flashed were incompatible and they damaged the bootloader. Thus, I downloaded another stock ROM that contains the boot.bin. Flashed it, then only that the phone can boot normally.

So, now I can enjoy my phone with custom ROM or stock ROM. Great Android phone!

Follow

Get every new post delivered to your Inbox.

Join 157 other followers