Lollipop on the Galaxy S2 – Stage 4/4 Installing Google Apps

Finally we have enough space in /system install the full Google Apps package, download the latest full package from the official thread.

I had a slight problem getting this on to the phone as adb sideload uses /tmp which is only 400MB so the transfer fails and I didn’t have an SD card handy. To fix this I mounted /data, pushed the zip file to /data and then used a bind mount to mount /data to the SD card location of /storage/sdcard0

adb shell mount /data
adb push /path/to/ /data
adb shell mkdir /storage/sdcard0
adb shell mount -o bind /data /storage/sdcard0

Now choose install from SD card in the CWM menu and select the Google Apps zip file.

After another slow reboot later and I have CyanogenMod 12 and the latest Paranoid Android Google Apps on my Galaxy S2. I’ve included the obligatory screen shots of the home page and the device status.


Lollipop on the Galaxy S2 – Stage 3/4 resizing /system

I had a freshly installed phone running pure CyanogenMod 12, but I also wanted the standard Google Apps so now what? Back to the forums to read about how Google Apps work on 3rd party ROMs. The main complication is the default flash layout in the Galaxy S2 only has 537MB for the /system partition, not enough for full Google Apps. There is also a fairly small /data partition which holds other apps but not user data.

More reading about this and I found out about PIT files (or Partition Information Table), which are a file containing information about how the flash should be laid out. I’m capable of using a partition table editor so messing about with PIT files and heimdall all looks a bit complex and unnecessary to me, granted I might have misunderstood what they do but there we go.

To change the flash layout I rebooted back into recovery and opened an adb shell and repartitioned the flash by hand, I also used a trick to make sure I had a record. I ran adb from screen with the -L flag so that screen records a log file to screenlog.0 by default.

screen -L adb shell

The next sections are picked out from my log of repartitioning, first of all print the current partitions before changing anything. You can see that /system which is labelled as FACTORYFS is only 512MiB

(parted) p
Model: MMC V3U00M (sd/mmc)
Disk /dev/block/mmcblk0: 15.8GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number  Start   End     Size    File system  Name       Flags
 1      4194kB  25.2MB  21.0MB  ext4         EFS
 2      25.2MB  26.5MB  1311kB               SBL1
 3      27.3MB  28.6MB  1311kB               SBL2
 4      29.4MB  37.7MB  8389kB               PARAM
 5      37.7MB  46.1MB  8389kB               KERNEL
 6      46.1MB  54.5MB  8389kB               RECOVERY
 7      54.5MB  159MB   105MB   ext4         CACHE
 8      159MB   176MB   16.8MB               MODEM
 9      176MB   713MB   537MB   ext4         FACTORYFS
10      713MB   5008MB  4295MB  ext4         DATAFS
11      5008MB  15.2GB  10.2GB               UMS
12      15.2GB  15.8GB  537MB   ext4         HIDDEN

Now to start making changes, delete the FACTORYFS, DATAFS and UMS partitions to clear space, this will remove all data you did a backup first right?

(parted) rm 9
(parted) rm 10
(parted) rm 11

Look again at the partitions, you can see that there is now empty space from 176MB to 15.2GB in the flash.

(parted) p
Model: MMC V3U00M (sd/mmc)
Disk /dev/block/mmcblk0: 15.8GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number  Start   End     Size    File system  Name       Flags
 1      4194kB  25.2MB  21.0MB  ext4         EFS
 2      25.2MB  26.5MB  1311kB               SBL1
 3      27.3MB  28.6MB  1311kB               SBL2
 4      29.4MB  37.7MB  8389kB               PARAM
 5      37.7MB  46.1MB  8389kB               KERNEL
 6      46.1MB  54.5MB  8389kB               RECOVERY
 7      54.5MB  159MB   105MB   ext4         CACHE
 8      159MB   176MB   16.8MB               MODEM
12      15.2GB  15.8GB  537MB   ext4         HIDDEN

Switch to units of bytes to make sure the layout is as exact as possible and create the new partitions, create the same 3 partitions but with 1GB for /system, 12.8GB for /data and a minimal 512MB for UMS or internal SD.

(parted) unit b

(parted) mkpart primary 176160768   1249902591
(parted) mkpart primary 1249902592  14680064511
(parted) mkpart primary 14680064512 15216934911

(parted) name 9  FACTORYFS
(parted) name 10 DATAFS
(parted) name 11 UMS

And finally a printout of the new layout, with 1G for /system, 12.8GB for /data and a minimal 512MB for the emulated SD card of UMS.

(parted) p
Model: MMC V3U00M (sd/mmc)
Disk /dev/block/mmcblk0: 15758000128B
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags

1 4194304B 25165823B 20971520B ext4 EFS
2 25165824B 26476543B 1310720B SBL1
3 27262976B 28573695B 1310720B SBL2
4 29360128B 37748735B 8388608B PARAM
5 37748736B 46137343B 8388608B KERNEL
6 46137344B 54525951B 8388608B RECOVERY
7 54525952B 159383551B 104857600B ext4 CACHE
8 159383552B 176160767B 16777216B MODEM
9 176160768B 1249902591B 1073741824B ext4 FACTORYFS
10 1249902592B 14680064511B 13430161920B DATAFS
11 14680064512B 15216934911B 536870400B UMS
12 15216934912B 15753805823B 536870912B ext4 HIDDEN

At this stage you need to reboot back to recovery mode and either format all partitions and reinstall or if you are feeling brave use resize2fs to grow /system to fill the partition and just wipe /data. I reinstalled from scratch, and pushed Google Apps at the same time, but that’s the next blog post.

If you want to resize the /system filesystem use:

adb shell resize2fs /dev/block/mmcblk0p9

Lollipop on the Galaxy S2 – Stage 2/4 Installing CyanogenMod

Once I had backups and CWM installing CyanogenMod 12 was easy, download the latest version of the ROM from this XDA thread, I used Beta #8.

Boot into recovery mode using power+volume up+home, wipe everything (cache, data, system), choose install from sideload and then from your computer run.

adb sideload /path/to/

Wait for the install to complete and reboot the phone, the first boot will take a very long time while Android is installed and that various caches rebuilt. I now had a Galaxy S2 running Lollipop but without any Google Apps, which is where it got a bit more difficult.

Lollipop on the Galaxy S2 – Stage 1/4 Gathering tools and backups

I recently changed jobs and got a Galaxy SII (i9100) from my new employer, which was running some ancient Samsung’d version of Android 4.1. I now have it running a non-official but for me fully functional version of CyanogenMod 12 (Android 5.0.2), with the full version of Google Apps installed and working.

First of all I should say I’m new to the whole Android and alternative ROMs thing, my personal phone has been an iPhone for a long time. That said I’m very familiar with Linux and embedded systems, I’ve jailbroken iPhones and done data recovery from iPhones too. This isn’t really meant as a fully comprehensive “howto” more just a record of what I did and it all worked for me.

There a standard set of tools for working with Android devices, so lets get them installed before anything else. On modern versions of Debian / Ubuntu the command to install the packages is as simple as:

sudo apt-get install heimdall-flash android-tools-adb android-tools-fastboot

First of all I took a backup of the phone, to do this I installed a CWM enabled kernel zImage using heimdall. The kernel zImage I used was from LysergicAcid the developer on XDA who created the CM12 build for the Galaxy S2. The kernels with CWM or TWRP can be found on Android File Host, I used the file

Get the phone into download mode with power+volume down+home button and then OK (with volume up) the warning that appears. Plug the phone in via USB and run:

sudo heimdall flash --KERNEL zImage --no-reboot

Now reboot the phone and enter recover mode using power+volume up+home together, and you should be in clockwork recovery. Because I know more about Linux than Android I just cloned the entire nand image using good old dd and netcat. To do this open up two terminal windows and run in the first one:

adb forward tcp:5555 tcp:5555
adb shell mount /system
adb shell /system/xbin/busybox nc -l -p 5555 -e /system/xbin/busybox dd if=/dev/block/mmcblk0

In In the second terminal window run:

size=$(adb shell cat /proc/partitions | grep -w mmcblk0| awk '{print $3}')
nc 5555 |  pv -s ${size}k -erp | pigz -c > /path/to/backup/mmcblk0.raw.gz

This will pull a full raw backup out of the onboard flash, transfer it with netcat, compress it and write it to the file /path/to/backup/mmcblk0.raw.gz