Sunday, September 22, 2013

Ubuntu slow connection with Atheros AR9485

Took the latest snapshot from https://www.kernel.org/pub/linux/kernel/projects/backports/  ran make defconfig-ath9k && make && sudo make install. Hopefully the patches will get in soon enough, so that I don't need to rerun the module building every time kernel updates.


[src: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/971809/comments/63]

Monday, July 29, 2013

FreeNAS Resize Root Partition

FreeNAS designed to fix into sdcard, the default root partition only come with 1GB, it's insufficient if you try install mediatomb + transcoder. Below is steps on how to resize the root partition of FreeNAS.
Before proceed, boot into option 4 (single user mode) for all steps below.

1. )  Add another disk to NAS machine or virtual disk if running on VM.

2. )  Backup the current partitions for reference, type:
# gpart backup da0
<da0> is the geom label, your case may difference.

3. ) Backup all partition to new added disk.
# dd if=/dev/da0s1 of=<new disk path>/da0s1
# dd if=/dev/da0s2 of=<new disk path>/da0s2
# dd if=/dev/da0s3 of=<new disk path>/da0s3
# dd if=/dev/da0s4 of=<new disk path>/da0s4

4. ) Delete and re-create the partition so that we have the free space for 1st partition.

# gpart show da0
=>      63  18874305  da0  MBR  (9.0G)
        63  1930257    1  freebsd  [active]  (942M)
  1930320   1930257    2  freebsd  (942M)
  3860577      3024    3  freebsd  (1.5M)
  3863601     41328    4  freebsd  (20M)
  3904929       14969376       - free -  (7.1G)

# gpart delete -i 4 da0

you need calculate the start index of your last partition, your last partition index should be 18874305 - 128 - 41328.

# gpart add -t freebsd -b 18832849 -s 41328 da0

5. ) Repeat step 4. for partition 3 and 2. You should get something like below
# gpart show da0
=>      63  18874305  da0  MBR  (9.0G)
        63  1930320    1  freebsd  [active]  (942M)
  1930383       14969241       - free -  (7.1G)
  16899624   1930257    2  freebsd  (942M)
  18829881      3024    3  freebsd  (1.5M)
  18832905     41328    4  freebsd  (20M)

6. ) Restore the partition 2,3 and 4.
# dd of=/dev/da0s2 if=<new disk path>/da0s2
# dd of=/dev/da0s3 if=<new disk path>/da0s3
# dd of=/dev/da0s4 if=<new disk path>/da0s4

7. )  Resize root partition
# gpart resize -i 1 da0

8. ) Correct the label
# bsdlabel /dev/da0s1
# /dev/da0s1:
8 partitions:
#          size     offset    fstype   [fsize bsize bps/cpg]
  a:   1930241         16    unused        0     0  
  c:   1930257          0    unused        0     0     # "raw" part, don't edit

Edit the label to correct size.
#  gpart show da0
=>      63  18874305  da0  MBR  (9.0G)
        63  16899561    1  freebsd  [active]  (8.1G)
  16899624   1930257    2  freebsd  (942M)
  18829881      3024    3  freebsd  (1.5M)
  18832905     41328    4  freebsd  (20M)
  18874233       135       - free -  (67k)

 Mine da0s1 size is 16899561, I edit my label as below:
# /dev/da0s1:
8 partitions:
#          size     offset    fstype   [fsize bsize bps/cpg]
  a:   16899545         16    unused        0     0   
  c:   16899561          0    unused        0     0     # "raw" part, don't edit


9. ) Now grow the file system
# growfs /dev/da0s1a

10. ) Reboot the machine and you will find that the root / not able to mount
type ufs:/dev/da0s1a to mount root.

11. ) Correct the mount path for root /
# mount -uw /
# vi /conf//base/etc/fstab
change /dev/ufs/FreeNASs1a / ufs ro 1 1
to /dev/da0s1a / ufs ro 1 1

12.) Reboot and done.




Tuesday, July 23, 2013

Android - DBHelper

Android using Sqlite as primary storage for android application, below is the sample code for create, upgrade or delete database.


Usually you will require to create one Helper for 1 database, we create our first helper class name "DBHelper", this class extends SQLiteOpenHelper and you need implement at least 2 methods


  • onCreate()
  • onUpgrade()
Always create only single instance for any DBHelper to avoid open & close connection of DB.


   public static DBHelper getInstance() {
        if(instance == null) {
            instance = new UserDatabaseHelper();
        }
        return instance;
    }



After install and start the app, verify if the db created.

root@android:/data/data/com.androidtutorial/databases # ls
Songs.db
Songs.db-journal
e3 Songs.db                                                                   <
SQLite version 3.7.16 2013-03-18 11:39:23 [www.ptsoft.org] [www.ptdave.com]
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .tables
Songs             android_metadata
sqlite> select * from Songs;
sqlite> select * from Songs;
song1
sqlite> 


The songs.db is created.


One confusing about onUpgrade, if you upgrade the db version from 2~10, don't expect onUpgrade will handle for you, you need do some checking as below.

   @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.d(TAG, "onUpgrade ..." + oldVersion ); 
        oldVersion += 1;
        if(oldVersion < newVersion) {
            onUpgrade(db, oldVersion, newVersion);
        }
    }



Thursday, May 9, 2013

JNI Detaching threads (native thread exited without detaching)


Attached thread must detact before the thread exit, when involved in Android JNI programming plus dealing with multithread usually you will facing problem like "threadid=41: native thread exited without detaching". To solved this problem is possible when use 'pthread_key_create', below is how to implement.


1. We need register a function pointer do detach the thread during JNI_Onload(), function 'detach_current_thread' will called during thread exit.

static void detach_current_thread (void *env) {
  (*java_vm)->DetachCurrentThread (java_vm);
}

jint JNI_OnLoad(JavaVM *vm, void *reserved) {
  JNIEnv *env = NULL;
  java_vm = vm;
  if ((*vm)->GetEnv(vm, (void**) &env, JNI_VERSION_1_4) != JNI_OK) {
    return 0;
  } 
  pthread_key_create (&current_jni_env, detach_current_thread);
  return JNI_VERSION_1_4;
}



2. During callback to Java, we check the current_jni_env if initialized. 

static JNIEnv *get_jni_env (void) {
JNIEnv *env;
if ((env = pthread_getspecific (current_jni_env)) == NULL) {
env = attach_current_thread ();
pthread_setspecific (current_jni_env, env);
}
return env;
}

if current_jni_env is NULL, will attach thread to VM.


That all you need to solved the "thread exited without detaching" because pthread will call detach_current_thread before exit.




Wednesday, April 24, 2013

Configure Time Zone for CentOS

$ yum install ntp -y

find out your timezone, as my case I used SGT. (/usr/share/zoneinfo/Asia/Singapore)
$ ll /usr/share/zoneinfo
$ chkconfig ntpd on
$ /etc/init.d/ntpd start

sync the time manually
$ ntpdate pool.ntp.org

Ubuntu Relaying Postfix SMTP (gmail)


The purpose is to sent mail through my Linux laptop with mailutils...

1. # apt-get install postfix

2. Edit /etc/postfix/main.cf by edit any exist entry as below values:

relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_use_tls = yes

3. Saved your gmail authentication info to  /etc/postfix/sasl_passwd  as below:
[smtp.gmail.com]:587    user.name@gmail.com:password

4. Change permissions 
#sudo chmod 400 /etc/postfix/sasl_passwd
#sudo postmap /etc/postfix/sasl_passwd

5. Tell it where it can validate the certificate.
# cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem | sudo tee -a /etc/postfix/cacert.pem

6. Restart & Test
#sudo service postfix restart
# echo 'test' | mail user.name@gmail.com

end.

[ref :https://help.ubuntu.com/community/Postfix]

Thursday, April 18, 2013

SVN merge between trunk & branch

Branched out 'branch_xxx' for feature AA, after branch out 'trunk' is continue changes, now need all changes on 'trunk' merge to 'branch_xxx'.

1. Find out the version since branch_xxx copy.
    svn log -v --stop-on-copy

<comment>
------------------------------------------------------------------------
r503 | <user> | 2013-03-06 10:56:01 +0800 (Wed, 06 Mar 2013) | 1 line

2. svn merge -r 503:519  svn+ssh://user@svnurl/var/local/svn/proj/trunk
ver 519 is trunk latest ver, you might have some conflicts need to resolve.

3. svn ci -m "comment"

Friday, April 5, 2013

Enable flash player for Chromium on Ubuntu


    1  sudo apt-get install flashplugin-nonfree
    2  sudo cp /usr/lib/flashplugin-installer/libflashplayer.so /usr/lib/chromium-browser/plugins
    3  chromium-browser --enable-plugins

Tuesday, April 2, 2013

SSH to ESXi host with public key

cat ~/.ssh/id_rsa.pub | ssh root@esxi.local 'cat >> /etc/ssh/keys-root/authorized_keys'

Thursday, March 7, 2013

Wednesday, March 6, 2013

Wash machine need maintenance ? YES!

Wash machine need maintenance ? YES!


I buy the wash machine 3 years ago, last month I buy some chlorine bleach to clean it. The result is bad, I can't use the wash machine anymore because there is a lot small piece of dust leak out and attache on my cloths. 

So I decided to disassemble the wash machine to clean up the dust inside, below is some pictures.



Before cleaning


After clean up

So clean you wash machine today or buy a new one. :)

Saturday, January 12, 2013

Network speed test with iPerf

If you have more than 1 wifi adapter, sometime you may curious which is perform better. Below is 1 of most common way to test your adapters.

What you need for test setup :

- 1 or more wifi adapter.
- 1 Linux/Unix machine.


1. Start terminal and run "sudo apt-get install iperf" on both machine.

2. Login to machine A, run "iperf -s -p 50000"
option "-s" : server mode.
option "-p" : listen to port 50000

3. On machine B, run "iperf -c [machine B IP] -p 50000
option "-c" : client mode.

4. Results

# iperf -s -p 50000
------------------------------------------------------------
Server listening on TCP port 50000
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
[  4] local 192.168.10.198 port 50000 connected with 192.168.10.134 port 42691
[ ID] Interval       Transfer     Bandwidth
[  4]  0.0-10.1 sec  48.5 MBytes  40.1 Mbits/sec
[  5] local 192.168.10.198 port 50000 connected with 192.168.10.134 port 42710
[  5]  0.0-10.1 sec  48.4 MBytes  40.1 Mbits/sec
From the both performance is similar, suspect bottleneck is on machine A, I re-test with another machine with LAN, below is the result.
------------------------------------------------------------
Client connecting to 192.168.10.10, TCP port 50000
TCP window size: 22.9 KByte (default)
------------------------------------------------------------
[  3] local 192.168.10.100 port 37808 connected with 192.168.10.10 port 50000
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec  74.5 MBytes  62.3 Mbits/sec
------------------------------------------------------------
Client connecting to 192.168.10.10, TCP port 50000
TCP window size: 22.9 KByte (default)
------------------------------------------------------------
[  3] local 192.168.10.134 port 37344 connected with 192.168.10.10 port 50000
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec  43.6 MBytes  36.5 Mbits/sec