Flash Android 10 GSI on an Original Google Pixel

A generic system image (GSI) is a system image with adjusted configurations for Android devices. One Single GSI could run on devices with different configuration without modification or re-compling theoretically.

· 3 min read
Flash Android 10 GSI on an Original Google Pixel

A generic system image (GSI) is a system image with adjusted configurations for Android devices. One Single GSI could run on devices with different configuration without modification or re-compling theoretically. For example, we can repack Lineage OS, One UI or any other AOSP-based modifications into GSI and let it run on any devices.

Yet it is designed to run any where, some devices even like Pixel OG (codename marlin) still has trick when flashing GSI.

Resize System Partition

While the original size of system_a and system_b partition is only 2147MB,

Model: SAMSUNG KLUBG4G1CE-B0B1 (scsi)
Disk /dev/block/sda: 31.9GB
Sector size (logical/physical): 4096B/4096B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name          Flags
 1      24.6kB  549kB   524kB                bootlocker_a
 2      549kB   1073kB  524kB                bootlocker_b
 3      1073kB  1597kB  524kB                keymaster_a
 4      1597kB  2122kB  524kB                keymaster_b
 5      2122kB  4219kB  2097kB               tz_a
 6      4219kB  6316kB  2097kB               tz_b
 7      6316kB  6840kB  524kB                rpm_a
 8      6840kB  7365kB  524kB                rpm_b
 9      7365kB  7889kB  524kB                pmic_a
10      7889kB  8413kB  524kB                pmic_b
11      8413kB  8937kB  524kB                hyp_a
12      8937kB  9462kB  524kB                hyp_b
13      9462kB  9724kB  262kB                cmnlib32_a
14      9724kB  9986kB  262kB                cmnlib32_b
15      9986kB  10.2MB  262kB                cmnlib64_a
16      10.2MB  10.5MB  262kB                cmnlib64_b
17      10.5MB  14.7MB  4194kB               aboot_a
18      14.7MB  18.9MB  4194kB               aboot_b
19      18.9MB  52.5MB  33.6MB               boot_a
20      52.5MB  86.0MB  33.6MB               boot_b
21      86.0MB  120MB   33.6MB               hosd_a
22      120MB   153MB   33.6MB               hosd_b
23      153MB   153MB   131kB                devcfg_a
24      153MB   153MB   131kB                devcfg_b
25      153MB   227MB   73.4MB               modem_a       msftdata
26      227MB   300MB   73.4MB               modem_b
27      300MB   300MB   262kB                msadp_a
28      300MB   301MB   262kB                msadp_b
29      301MB   301MB   262kB                apdp_a
30      301MB   301MB   262kB                apdp_b
31      301MB   616MB   315MB   ext2         vendor_a      msftdata
32      616MB   930MB   315MB   ext2         vendor_b
33      930MB   3078MB  2147MB               system_a      msftdata
34      3078MB  5225MB  2147MB  ext2         system_b
35      5225MB  31.9GB  26.7GB  ext4         userdata      msftdata
36      31.9GB  31.9GB  4936kB               reserve0      msftdata
The original partition table

To resize the partition, firstly download parted. We will use that later within TWRP.

$ adb push parted /sbin/parted
$ adb shell
# chmod 777 /sbin/parted
# /sbin/parted /dev/block/sda
rm 33
rm 34
rm 35
rm 36
Remove system_a, system_b, userdata and all unrelated partitions in parted
# For system_a
mkpart
Partition name? system_a
File system type? ext4
Start? 930
End? 4030
# For system_b
mkpart
Partition name? system_b
File system type? ext2
Start? 4030
End? 7130
# For userdata
mkpart
Partition name? userdata
File system type? ext4
Start? 7130
End? 24870
name 33
Name? system_a
name 34
Name? system_b
name 35
Name? userdata
Rename partitions in parted
set 33 msftdata on
set 35 msftdata on

Get GSI Image Installed

fastboot erase system
fastboot flash system <system image>

For example, flashing a Havoc OS GSI should be successful:

Sending sparse 'system_a' 1/6 (524284 KB)          OKAY [ 15.015s]
Writing 'system_a'                                 OKAY [  3.536s]
Sending sparse 'system_a' 2/6 (524284 KB)          OKAY [ 14.823s]
Writing 'system_a'                                 OKAY [  3.502s]
Sending sparse 'system_a' 3/6 (524284 KB)          OKAY [ 15.007s]
Writing 'system_a'                                 OKAY [  3.539s]
Sending sparse 'system_a' 4/6 (524284 KB)          OKAY [ 14.670s]
Writing 'system_a'                                 OKAY [  3.498s]
Sending sparse 'system_a' 5/6 (524284 KB)          OKAY [ 14.711s]
Writing 'system_a'                                 OKAY [  3.489s]
Sending sparse 'system_a' 6/6 (247960 KB)          OKAY [  7.016s]
Writing 'system_a'                                 OKAY [  1.738s]
Finished. Total time: 101.027s

Push Missing Libraries

Unfortunately GSI builds for Pixel (and Pixel XL) are missing some (mainly audio-related) libraries and will fail on booting. For Android 10 (Q), the following files should be extracted from factory images to /system/lib/vndk-29:

/system/system/lib/android.hardware.audio.common-util.so
/system/system/lib/[email protected]
/system/system/lib/libeffectsconfig.so
Thiese libraries is needed to get RIL up

And the following file to /system/lib64/vndk-29:

/system/system/lib64/[email protected]

Set a correct permission:

chcon u:object_r:system_lib_file:s0 /system/lib/vndk-29/android.hardware.audio.common-util.so

Finally, flash Permissiver to fix SELinux permission on boot partition and we are go for launch.


References