RSS Feed

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).


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.


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!

tcplay script

Posted on

Recently, when I was using TrueCrypt in Arch Linux to mount a truecrypt container file, it was very slow to mount the container. Furthermore, I also read that the TrueCrypt is discontinued.

Therefore, I decided to use the tcplay. However, it is a command-line. Arch Linux wiki page shows a good tutorial on how to use tcplay.

When using tcplay in Linux, unlike mounting the folder like encfs, tcplay requires losetup for loop device. Thus, it involves 3 steps to mount a truecrypt container: i) setup loop device, ii) setup device-mapper with tcplay, and iii) mount. Consequently, to unmount the truecrypt containter need to reverse these 3 steps.

In order to make my life easier, I wrote a simple script as following. Feel free to modify it.

# @author Allen Choong
# @date    2014-06-29
# @version    1.0.1
# Easy mount the truecrypt encryptinog by using tcplay.
# Assuming the truecrypt mounting name does not have whitespace.
# Changelog:
# 2014-06-29    1.0.1    Add display help if there is no argument
# 2014-06-02    1.0    Initial

tc_mount() {
  lo=`losetup -f`
  losetup "$lo" "$1"
  tcplay -m "`basename "$1"`" -d "$lo"
  mount "/dev/mapper/`basename "$1"`" "$2"

tc_unmount() {
  echo -en "Unmount ... "
  umount "/dev/mapper/$1"
  lo=`losetup -l | grep "$1" | cut -d ' ' -f 1`
  dmsetup remove "$1"
  losetup -d "$lo"
  echo "OK!"

mklist() {
  for ((i=1;$i<=$num;i++)) ; do
    ret+=$(echo " `expr $start + $i`")
  echo $ret

show_mount() {
  mount|grep '/dev/mapper' |while read l ; do num=`echo "$l" | tr ' ' '\n' | wc -l`;
    cutnum=$(mklist 3 `expr $num - 6`)
    echo "$l" | cut -d ' ' -f "1 $cutnum" | sed -e 's/\s/ => /'

#Get arguments
for ((i=0;i<=$#;i++)) ; do


#Print help
if [ $# == "0" ] ; then
  echo "This command requires root privilege."
  echo "Usage:"
  echo ""
  echo "To list the mounted container:"
  echo "`basename $0` -l"
  echo ""
  echo "To unmount (requires root):"
  echo "`basename $0` -u CONTAINER_FILENAME"
  echo "where CONTAINER_FILENAME is the device mapper name"
  echo ""

for ((i=1;i<=$#;i++)) ; do
  case ${args[$i]} in
      unmnt=`echo ${args[$i+1]}`

if [[ "$action" == "mount" ]] ; then
  tc_mount "$1" "$2"
elif [[ "$action" == "unmount" ]] ; then
  tc_unmount "$unmnt"

Update (2014-06-29):
In order to use this script, if you have a file called (already make file system),

sudo /path/to/mnt

After this, you can list the mounted point as, -l

To unmount the container,

sudo -u #where the is the device mapper name, not the path to the file

Experience of installing CyanogenMod to old phone

Posted on

Recently, my phone (3 years old) is slower and slower. This causes me frustrated, especially if I want to use it to call urgently. Interface changed slowly, the contacts listed slowly, and my urgency becomes meaningless. So, the phone is either to be replaced with a new phone, or hack it!

My old phone, namely Samsung Galaxy S (i9000), to make it reborn, I decided to install CyanogenMod. CyanogenMod is well-known of its performance and reliability. The installation steps can be found in the wiki page.


Whatever it is, data is always the most precious. So, I backup’ed all the data in the /sdcard, which is the only partition that can be accessed in a non-rooted Android. I also used Super Backup to backup the installed apps, SMS, contacts, and others. However, the backup of the apps does not include the apps setting. Sorry to say that, all the saved states of the games will be no more. Unless I root the Android first.

Since the apps data can not be backup’ed, but only the data stored in the /sdcard can be backup’ed, thus I used other ways to backup some important data. For instance, WeChat and WhatsApp. Because the conversations are precious to me, so, I used the built-in backup function of these apps.


Before start flashing the ROM to the phone, I downloaded all the necessary files: CyanogenMod stable version for Samsung Galaxy S, Google Apps, Heimdall suite, and ClockworkMod Recovery. Because I am using Linux, I installed android-sdk-platform-tools which contains the adb command.

Take risk

Once prepared everything, and read the whole wiki several times, so that I know what are the possible problems and issues. Then I just followed the steps from the wiki. (However, anyone who is doing this must take the risk that, you may need to throw your phone away.)


I faced many problems. Firstly, there was no “disclaimer message” for me to accept as written in the wiki. Besides that, there was no screenshot available from the wiki. Thus, when first time I entered the download mode, I am waiting for the disclaimer message.

I ignored it, so I continued to follow the steps. The next problem was the message in the console after I flash the zImage downloaded from the wiki.

ERROR: Partition “kernel” does not exist in the specified PIT.

Immediately I searched for the information, then a user from a forum mentioned to use uppercase of --KERNEL parameter. Actually it was written in the wiki, yet the wiki didn’t mention the error message as above.

After flashed the “zImage” which was downloaded from the wiki, I came to a serious problem. My phone was stuck at the pre-boot screen. There was a Samsung logo, but the phone could not boot. The “zImage” came from the Semaphore.tar in the wiki. I immediately visited to ClockworkMod webpage to search for the “recovery image“. Yet I found none of them looks like “zImage” (they are .zip files which contain some scripts and programs). Thus, I searched “Semaphore.tar” then I came to the official page. I tried other files from the official site, yet none of them works.

Then, I found some forums mentioned they have the same problem that stuck at the pre-boot screen. Finally, I read the Discussion of the wiki. It is very useful. Other users had the same problem, and they provided some information in the discussion. Consequently, I downloaded another recovery image from the discussion page of the wiki.

Then I flashed it, and the other things worked fine (some issues were mentioned in the discussion page).


After installation, booted it, and I saw something totally different: new theme, Android 4.3, superuser, etc. Yeah!!!

So, the next thing I did was installing the Super Backup, so that I can restore all the other apps. Then restored SMS and contacts. WeChat and WhatsApp conversations were also restored. Luckily, the flashing of a ROM does not destroy the data in the /sdcard, else I need to copy the things to the phone again.

Next, I setup the Google Account and also the emails.

Then I tried to install Facebook app. Seriously, the app was slow as usual. So, I removed it immediately.

Now, I am still trying it and hopefully it has much better performance then the original ROM.

Learning in Linux community

Posted on

If you are using Linux, then you are involved in the Linux community. As in the Linux community, most of the software are open source software, which is about sharing and distributing the source code among the community.

As a Linux user, I am not just learn to use the free software happily without paying money. Using the Linux is more benefit than just saving the money.

As a Linux user, I know that reading manual/documentations is important. There are a lot of questions are mostly answered in the documentations or manual. In order to find the answers, we should read the manual. If the answers are available in the manual, yet a newbie is asking in the forum, he or she will be asked to RTFM.

Internet is a good resource for the answers. Utilise the search engine and look for the solutions. Look for solutions properly before asking. Only if the solution is not available, then only we ask in the forum, IRC, or question-and-answer websites such as

When using forum, IRC, or question-and-answer websites, we should practice good netiquette. Always ask politely and be grateful to the person who answers your questions. Besides that, wait patiently for the answers. It is community-based, do not expect there is 24 hours 7 days support to your problem. When asking, please provide necessary information so that others will know what is going on. When using the forum, other than netiquette, choose the related forum to post the topic. We do not ask Ubuntu related questions in Fedora forum.

Sometimes, we may see some annoying problems in a Linux distro. The problems may not be solved manually because those are the bugs. If they are bugs, we should file the bugs report properly. However, before file the bugs, please check whether the bugs are not yet reported. After file the bugs, do not expect the bugs will be solved soon or immediately. If you want to solve the problem immediately, sorry to say, you need to solve it by yourself.

Wiki is a good resource in the Linux community. It is a community-based documentation. Read them, search them, follow the instructions if available. Sometimes, the wiki is not updated or there is minor error, contribute to the wiki and update the page. Also, read the “talks” of the wiki page, which may give you some ideas about what is going on.

If you are a programmer or software developer, and if you are able to patch the bugs, then contribute the patch to the community. This will be a wonderful contribution to the community. Because this is also what you need when you found some bugs.

Some Linux distros may have limited packages available. If we need to have other packages, learn about packaging and share the packages.

As a conclusion, become a Linux user is to be involved in the open source community, which will improve your own learning ability, problem solving skills, and communication skills.

Create LiveUSB in a general way

We can produce our own LiveUSB manually. The following are the steps that based on Arch Linux distro.

  1. Build a kernel that supports AUFS, SquashFS, and optionally vfat support. So that we can mount these filesystems. In Arch Linux, we can build linux-pf for these supports. This package can be found from AUR.
  2.  Then we can generate the initramfs. In Arch Linux, we can use mkinitcpio to create an initramfs image. For instance,
    mkinitcpio -k /boot/vmlinuz-linux-pf -c mkinitcpio-custom.conf -g initramfs.img

    (In Arch Linux, it is recommended to add in some modules in the mkinitcpio configuration file: zram, squashfs, loop, fuse, aufs, vfat)

  3. Besides that, we also need to prepare a squashfs so that it will act as a read only filesystem with workable programs. In order to create the squashfs, we can prepare it by using the existing filesystem.
    The important folders are: bin, etc, home, lib, mnt, opt, root, sbin, srv, usr, var.
    The important folders but let them empty are: dev, media, proc, run, sys, tmp.
    And also need to comment the lines in the /etc/fstab, so that after boot, there is no automount.
  4. Then we can prepare a USB pendrive so that it can boot by using syslinux. syslinux will run the syslinux.cfg, which can be located at /syslinux or /boot/syslinux. The simplest way to make the syslinux.cfg to boot is something like
    DEFAULT myliveusb
    LABEL myliveusb
    KERNEL vmlinuz-linux-pf
    APPEND initrd=initramfs.img

    By this, it will use the kernel vmlinuz-linux-pf which is built at the beginning (in step 1), and initrd with the initramfs.img that is generated (in step 2). These files need to be put at the same path with syslinux.cfg.

  5. In order to boot properly, we need to modify the “init” file in the initramfs.img. This image is actually compressed cpio. We can extract the data by
    zcat ../initramfs.img | cpio -i

    The extracted data contains some scripts, kernel modules, and libraries that are required to boot up. So, we just modify the init script.
    In the init script, we may need to disable the fsck_root (in Arch Linux) so that it will not fsck the root file.
    Then, we need to add in the statements to mount the USB pendrive and created squashfs.
    Therefore, we add in the following statements to somewhere before the initramfs switch the root.

    #The statements are based on
    mkdir -p /mnt/usb /squashfs /tmpfs
    mount -t vfat -o ro /dev/disk/by-label/MYPENDRIVE /mnt/usb
    mount -t squashfs -o ro,loop /mnt/usb/path-to/root.sfs /squashfs
    mount -t tmpfs none /tmpfs
    #cd /tmpfs ; mkdir -p tmp var/log ; chmod 1777 tmp ; cd / #This step is optional
    mount -t aufs -o br=/tmpfs:/squashfs none /new_root #where the new_root is the root which will be switched according to Arch Linux

    Finally we need to re-compress by

    find . | cpio -o -H newc | gzip > ../initramfs.img

    If we read through the init script, at the end there is a statement that calls “switch_root” which will switch to the /new_root. Then, the system will boot successfully.

The AUFS is required because SquashFS is read-only. The following is the explanation of the statements above,

mount -t vfat -o ro /dev/disk/by-label/MYPENDRIVE /mnt/usb

is to mount the current USB pendrive to the /mnt/usb. We use the /dev/disk/by-label because it is the easiest way by referring the pendrive based on the label. /dev/sd{a,b,c} and so on are not applicable because different computer may have different number of storages. After this,

mount -t squashfs -o ro,loop /mnt/usb/path-to/root.sfs /squashfs

we mount the root.sfs which is created by mksquashfs. Then,

mount -t tmpfs none /tmpfs

we mount the tmpfs to a new folder /tmpfs. So that we use the memory for read-write operation. We do not use the default /tmp because it is used by initramfs.

cd /tmpfs ; mkdir -p tmp var/log ; chmod 1777 tmp

This is to create a tmp folder with the 1777 ownership as /tmp in the root. Finally,

mount -t aufs -o br=/tmpfs:/squashfs none /new_root

we mount the tmpfs and squashfs unionly to the /new_root

Because tmpfs is writable, squashfs is read-only, but they are mounted unionly in the new_root, as a result after switch_root, then it can boot and write to the new_root file system, as all the data are actually stored in the memory (as tmpfs occupies the memory).

By this, we can also create our own filesystem as a file (formated with ext4), and mount it unionly to the /new_root. So, that we can “save” the data and restore it during the next boot. (I have not yet tested this step by editing the init script.)

AlphaOS a really great LiveUSB

These days, want to compile old projects. Firstly, I compiled all my code using Arch Linux. Then I decided to install my project to a LiveUSB, so that I need not to partition or use virtual machine on the target computer.

So I planned to use KNOPPIX.  I tried Linux Mint in VirtualBox, since it is based Debian, but failed to compile my code due to the CEGUI version is not the latest as Arch Linux.

As a result, I decided to use ArchPup (Puppy Linux). But ArchPup is superseded by AlphaOS. And, it solved my problem.

However, there are some limitations. Firstly, the latest version only support 64-bit computer. Secondly, problem of hardware driver. I wanted to install the broadcom-wl, but I cannot get the linux-headers. And the linux-headers of AlphaOS is different from Arch (because of different built). AlphaOS lacks of documentation on how can we produce or customise it. As a result, I can only use the default kernel and run my project without network connection.

Since the official site mentioned about Linux Live Kit. So, I tried to create my “dream LiveUSB” from the Arch Linux in the VirtualBox by this Linux Live Kit. However, I failed. I tried to compile the kernel with linux-pf (because it supports AUFS), then build the image using Linux Live Kit. But the OS was freeze in VirtualBox if I use the linux-pf kernel. This may be the caused by virtualbox-guest-modules.

Now, I am still trying to build my dream LiveUSB.

Traditional Chinese (BIG5) in the LANG=zh_CN.UTF8 locale

Recently, I tried to play Tecmo Koei Sangokushi 12 PK Traditional Chinese version (三國志12威力加強版繁體中文) on WINE using PlayOnLinux. It works fine, but there is a problem that is the game can only be run in LANG=zh_CN.UTF-8 locale instead of zh_TW.UTF-8 locale (there are some reasons behind). As a result, if I enter some Chinese characters using fcitx, the output will be converted. Such as 一 becomes 珨. This is because when using fcitx in the zh_CN.UTF-8 locale, the character will be encoded as zh_CN.UTF-8. However, because the game itself is Traditional Chinese, the output will be encoded as possibly BIG5. This can be proved by using iconv with the following command,

echo "一" |iconv -f utf8 -t gb18030|iconv -f big5 -t utf8 #results 珨

Therefore, I need to convert this faulty character back to the character I intended. Thus, the iconv can be used to reverse the result by following command,

echo "珨" |iconv -f utf8 -t big5|iconv -f gb18030 -t utf8 #results 一

Because the game does not allow copy-paste, I can only solve this problem programmatically by creating a(n) fcitx module with the iconv. The module is available here.

The fcitx module I created works partially satisfying. It still has a problem which I cannot solve. I am not sure what is the root problem, either iconv, fcitx, WINE, the game itself, or other reason. That is, some of the Chinese characters such as 自 and 何 are not able to be entered and result question marks (?). (This is solved, read UPDATE below.)

Note: In order to use the module, that is to convert the GB18030 to BIG5 (yet still UTF8), because BIG5 is Traditional Chinese, that means we need to enable the “Simplified Chinese To Traditional Chinese” module in fcitx. Then only input the Traditional Chinese characters will work. Such as entering 會 instead of 会. Because BIG5 does not have the character for 会, but 會.

Sangokushi 12 PK Traditional Chinese in WINE problem with zh_CN.UTF-8 locale

Sangokushi 12 PK Traditional Chinese in WINE problem with zh_CN.UTF-8 locale

Because of the question mark problem as mentioned above, I can only give up playing the game with WINE. There is no choice but only to play the game with Windows in the VirtualBox which works fine in the Chinese (Taiwan) locale.

Update (2014-06-18): With the latest version of Wine 1.7.20 and fcitx 4.2.8, after using the module, all the words can be encoded as BIG5.


Get every new post delivered to your Inbox.

Join 145 other followers