Install requirements (adb and fastboot) on your computer
adb and fastboot are programs used on the command line to access and manipulate an Android phone/device. They exist on multiple OS. I personally use Linux Mint on my desktop computer and both programs can simply be installed using apt:
ckadm@mintp ~ $ sudo apt-cache search ^adb
adb - Android Debug Bridge
ckadm@mintp ~ $ sudo apt-cache search ^fastboot
fastboot - Android fastboot tool
ckadm@mintp ~ $ sudo apt-get install adb fastboot
Enable USB debugging on the tablet
Make sure the "USB debugging" is enabled. Check Settings -> Developer tools -> Enable USB Debugging.
xperia z tablet unlock bootloader |
xperia z tablet unlock bootloader |
In case "Developer options" is not shown in the Settings, open Settings -> About tablet. Tap several times on the "Build number" to enable the developer mode. The "Developer options" should now show up in the settings.
Preparations to unlock the bootloader
Open the Contacts app and open the app's Settings.
xperia z tablet unlock bootloader |
With your finger tap and hold for about 5 seconds just above the navigation menu (at the bottom):
xperia z tablet unlock bootloader |
When you release your finger, a field with "Enter service code" should appear:
xperia z tablet unlock bootloader |
By tapping on this "Enter service code" field, a dialer (num pad) will show up:
xperia z tablet unlock bootloader |
Enter the following code: *#*#7378423#*#* . A service menu will appear.
In this service menu open Service info -> Configuration and check the "Rooting status".
xperia z tablet unlock bootloader |
The value of "Bootloader unlock allowed" should be set to Yes. If this is set to no, you cannot proceed. While you're here, take a picture of this screen or note down the IMEI number - you will need this later to unlock the bootloader.
Now connect the tablet to your computer using a microUSB cable.
The tablet should now be seen using the adb command. Make sure adb is able to detect your tablet:
ckadm@mintp ~ $ adb devices -l
List of devices attached
CB5A1TMNH8 device usb:1-1.6 product:SGP321 model:SGP321 device:SGP321
Note: It may be necessary to disable the "USB Debugging" in Settings -> Developer options and then re-enable them again. I had to do this on my tablet, otherwise adb was not able to detect any device.
Now that adb is able to see the tablet, launch adb reboot bootloader to reboot the tablet and to boot directly into the bootloader:
ckadm@mintp ~ $ adb reboot bootloader
Looking at the tablet, there is no hint that it has booted into the bootloader. The screen is just plain dark. Only the blue LED next to the power button indicates the tablet is running. To verify if the bootloader is correctly loaded, use fastboot to find the device:
ckadm@mintp ~ $ sudo fastboot devices
CB5A1TMNH8 fastboot
Unlock the bootloader
With the tablet still connected to the computer and detectable with fastboot, go to the Unlock Bootloader page on the Sony developer website. At the bottom of the page, select your device (Xperia Z Tablet) and then enter your IMEI code.
xperia z tablet unlock bootloader |
Accept the acknowledgements and submit. You will receive an unlock code:
xperia z tablet unlock bootloader |
This unlock code can now be used with fastboot:
ckadm@mintp ~ $ sudo fastboot oem unlock 0x
...
OKAY [ 24.205s]
finished. total time: 24.205s
Obviously replace
Install a custom recovery (TWRP)
To install a custom recovery, TWRP is recommended. You can download the image from "TWRP for pollux" or "TWRP for pollux_windy" (again: Chose the correct version for your device or it won't boot anymore if you install the wrong version!).
Note: Download the img file in the browser, do not use a command line tool like wget. I did that and only got a ~7KB file, resulting in an invalid file.
Once downloaded, use fastboot to flash the "boot" partition and overwrite it with the just downloaded TWRP image:
ckadm@mintp ~/Downloads/Android $ sudo fastboot flash boot twrp-3.3.1-0-pollux.img
sending 'boot' (11802 KB)...
OKAY [ 0.376s]
writing 'boot'...
OKAY [ 0.576s]
finished. total time: 0.952s
Now reboot the device using fastboot. The tablet should now reboot and launch TWRP:
ckadm@mintp ~/Downloads/Android $ sudo fastboot reboot
rebooting...
finished. total time: 0.101s
xperia z tablet unlock bootloader |
Now booted in TWRP and still connected to the computer, adb should see the device:
ckadm@mintp ~ $ adb devices -l
List of devices attached
CB5A1TMNH8 recovery usb:1-1.6 product:SGP321 model:Xperia_Tablet_Z_LTE device:pollux
Push the recovery image to the tablet's memory:
ckadm@mintp ~ $ adb push Downloads/Android/twrp-3.3.1-0-pollux.img /sdcard
2749 KB/s (12085248 bytes in 4.292s)
Use dd to overwrite the tablet's own internal recovery:
ckadm@mintp ~ $ adb shell
~ # dd if=/sdcard/twrp-3.3.1-0-pollux.img of=/dev/block/platform/msm_sdcc.1/by-name/FOTAKernel
23604+0 records in
23604+0 records out
12085248 bytes (11.5MB) copied, 2.075409 seconds, 5.6MB/s
~ # exit
Download and copy LineageOS using TWRP recovery
The tablet is still booted in the TWRP recovery and still connected to the computer at this point. Now it's time to download the LineageOS for your Sony Xperia Tablet Z!
xperia z tablet custom rom |
As of this writing I downloaded LineageOS 15.1 (= Android 8.1), nightly build from 2019-12-09. It's also a wise idea to download all the Google Apps which include important packages such as Google Play. The bundle can be downloaded in several variants using OpenGapps.
xperia z tablet custom rom |
I selected the ARM platform (important for this tablet device!), Android 8.1 and the mini variant.
Once downloaded, there should be two zip files:
ckadm@mintp ~ $ ls Downloads/Android/*zip
Downloads/Android/lineage-15.1-20191209-nightly-pollux-signed.zip
Downloads/Android/open_gapps-arm-8.1-mini-20191208.zip
These files can now be copied to your tablet's SD card (which should appear in your file explorer):
xperia z tablet custom rom |
In TWRP make sure you are able to see the now copied zip files. Use Advanced -> File Manager and select "external_sd" from the list. The zip files should be shown:
xperia z tablet custom rom |
Data wiping and formatting in TWRP
Back in the main menu of TWRP, select Wipe -> Format Data. This will erase the internal memory including the stock Android version from Sony. Type "yes" to confirm data wiping:
xperia z tablet custom rom |
xperia z tablet custom rom |
Once completed, use "Back" and use the navigation "back" key to return to the "Wipe" menu. This time tap on "Advanced Wipe". Select "Cache" and "System" partitions and then use your finger to swipe the bar "Swipe to Wipe" to the right.
xperia z tablet custom rom |
xperia z tablet custom rom |
Once completed, return to the main menu of TWRP.
Installation of LineageOS and GApps in TWRP
Back in the main menu of TWRP, tap on "Install". To select the external SD card, tap on "Select Storage" and choose the microSD card.
xperia z tablet custom rom |
xperia z tablet custom rom |
The two zip files (LineageOS and GApps) should now be shown:
xperia z tablet custom rom |
Tap on the linage zip file, TWRP will ask if you want to install this file. Swipe the bar to the right to confirm:
xperia z tablet custom rom |
xperia z tablet custom rom |
xperia z tablet custom rom |
After the installation, tap on "Wipe Cache/Dalvik" and confirm. Afterwards use the back button in the navigation menu at the bottom to go back to the file explorer (Install Zip) and this time select the open_gapps zip file. As with the previous zip file, swipe to confirm the installation.
xperia z tablet custom rom |
xperia z tablet custom rom |
xperia z tablet custom rom |
When the installation completes, tap on "Reboot System". TWRP asks if it should be installed as an official app. Swipe to the right to do so.
xperia z tablet custom rom |
The tablet should now reboot and LineageOS should start.
xperia z tablet custom rom |
The first start did not boot LineageOS successfully. The loading animation kept on going for over 30 minutes. I forced a restart of the tablet (see How to force a hard reboot your Sony Xperia tablet or phone) to then start the device again. This time the LineageOS startup worked.
xperia z tablet custom rom |