{"id":979,"date":"2020-09-09T00:51:00","date_gmt":"2020-09-08T21:51:00","guid":{"rendered":"https:\/\/blog.andresgomez.org\/?p=979"},"modified":"2020-09-07T23:09:56","modified_gmt":"2020-09-07T20:09:56","slug":"installing-lineageos-in-the-sony-xperia-xz2-compact-dual-in-gnu-linux-3-5-installing-lineageos","status":"publish","type":"post","link":"https:\/\/blog.andresgomez.org\/es\/2020\/09\/09\/installing-lineageos-in-the-sony-xperia-xz2-compact-dual-in-gnu-linux-3-5-installing-lineageos\/","title":{"rendered":"Installing LineageOS in the Sony Xperia XZ2 Compact Dual (in GNU\/Linux) 3\/5: Installing LineageOS"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">WARNING<\/h2>\n\n\n\n<p>I have no responsibility whatsoever if this guideline causes any harm to your device. The intention of these posts are solely as personal notes for myself. Follow them at your own risk.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">WARNING<\/h2>\n\n\n\n<p>Through these steps I will unlock the phone&#8217;s bootloader, erasing all data. This includes the DRM keys stored in the Trim Area (TA) partition. I&#8217;ll attempt backing them up but, as of today, there is no way of restoring them to the previous state nor knowing if the actual backup is usable at all.<\/p>\n\n\n\n<p>Without these DRM keys, several audio and video proprietary functionality provided by Sony <a rel=\"noreferrer noopener\" href=\"https:\/\/developer.sony.com\/develop\/open-devices\/get-started\/unlock-bootloader\" data-type=\"URL\" data-id=\"https:\/\/developer.sony.com\/develop\/open-devices\/get-started\/unlock-bootloader\" target=\"_blank\">won&#8217;t be available<\/a> <strong>including some camera post-processing features<\/strong>, color gamut profiles, white balance, noise reduction, X-Reality Video Enhancement, DSEE HX, ClearAudio+, and Widevine L1 support for HD Netflix.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Upgrading to latest stock firmware<\/h2>\n\n\n\n<p>In the previous posts we have <a href=\"https:\/\/blog.andresgomez.org\/2020\/09\/07\/installing-lineageos-in-the-sony-xperia-xz2-compact-dual-in-gnu-linux-1-5-downgrading-sonys-stock-firmware\" data-type=\"URL\" data-id=\"https:\/\/blog.andresgomez.org\/2020\/09\/07\/installing-lineageos-in-the-sony-xperia-xz2-compact-dual-in-gnu-linux-1-5-downgrading-sonys-stock-firmware\" target=\"_blank\" rel=\"noreferrer noopener\">downgraded the stock firmware from Sony<\/a> and <a href=\"https:\/\/blog.andresgomez.org\/2020\/09\/08\/installing-lineageos-in-the-sony-xperia-xz2-compact-dual-in-gnu-linux-2-5-backing-up-the-trim-area-ta-partition\/\" data-type=\"URL\" data-id=\"https:\/\/blog.andresgomez.org\/2020\/09\/08\/installing-lineageos-in-the-sony-xperia-xz2-compact-dual-in-gnu-linux-2-5-backing-up-the-trim-area-ta-partition\/\" target=\"_blank\" rel=\"noreferrer noopener\">backed up the Trim Area (TA) partition<\/a>.<\/p>\n\n\n\n<p>Since the guideline to install LineageOS mandates that we have the latest stock firmware from Sony running in the phone, I upgraded now from the downgraded exploitable version.<\/p>\n\n\n\n<p>Using the built-in updater doesn&#8217;t seem to work any more (?!) so I had to flash the latest stock firmware in a similar fashion as I did for downgrading.<\/p>\n\n\n\n<p>I already downloaded the firmware and it is already properly extracted so, in this case, I won&#8217;t need to use <em>flashtool<\/em>, only <em>newflasher<\/em>.<\/p>\n\n\n\n<p>These would be steps to follow once I connected the phone to the USB cable in <em>flashable mode<\/em>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">root$ rm \"H8324_Customized NOBA_1313-6167_52.1.A.3.49_R4C\"\/*ta\nroot$ rm \"H8324_Customized NOBA_1313-6167_52.1.A.3.49_R4C\"\/boot\/*ta\nroot$ cp -a newflasher.x64 \"H8324_Customized NOBA_1313-6167_52.1.A.3.49_R4C\"\nroot$ cd \"H8324_Customized NOBA_1313-6167_52.1.A.3.49_R4C\"\nroot$ chmod +x newflasher.x64\nroot$ .\/newflasher.x64\n\n[...]\n\nReboot mode at the end of flashing:\ntypa 'a' for reboot to android, type 'f' for reboot to fastboot, type 's' for reboot to same mode, type 'p' for poweroff, and press ENTER.\na\n\n[...]\n\nOptional step! Type 'y' and press ENTER if you want dump trim area, or type 'n' and press ENTER to skip.\nDo in mind this doesn't dump drm key since sake authentifiction is need for that! But it is recommend to have dump in case hard brick!\nn\n\n[...]\n\nRecommended step to skip this! Type 'y' and press ENTER if you want flash persist partition, or type 'n' and press ENTER to skip.\nMore info https:\/\/forum.xda-developers.com\/xperia-xz1-compact\/help\/android-attest-key-lost-bootloader-t3829945\nn\n\n[...]\n\nDevice is put now out of flash mode.\nSent command: Sync\nWaiting sync to finish\u2026\n\u2026\u2026\u2026\u2026\u2026\u2026 done\nSent command: continue.\nDone.\nClosing device.<\/pre>\n\n\n\n<p>Notice the questions and the answers. After a while, the phone will complete its reboot and we will be able to verify that the running firmware is the one flashed.<\/p>\n\n\n\n<p>As explained in the previous posts, enable once again developer mode and USB debugging in the phone. For the next steps, enable also <em>OEM unlocking<\/em> in the developer options.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Installing LineageOS<\/h2>\n\n\n\n<p>We&#8217;ll follow the <a rel=\"noreferrer noopener\" href=\"https:\/\/wiki.lineageos.org\/devices\/xz2c\/install\" data-type=\"URL\" data-id=\"https:\/\/wiki.lineageos.org\/devices\/xz2c\/install\" target=\"_blank\">official guide<\/a>.<\/p>\n\n\n\n<p>First, we&#8217;ll unlock the bootloader. <strong>This will finally wipe out the TA partition losing the DRM keys. This is a point of no return.<\/strong><\/p>\n\n\n\n<p>I checked that my phone&#8217;s bootloader can be unlocked. I opened the phone application and dialed <em><code>*#*#7378423#*#*<\/code><\/em>. The service menu is now open. Go to <em>Service info -&gt; Configuration<\/em> and checked that the <em>Rooting status:<\/em> states <em>Bootloader unlock allowed: Yes<\/em>. Also, <strong>noted down the IMEI<\/strong>.<\/p>\n\n\n\n<p>Now, I connected the device to my PC with the USB cable and continued to set it in <em>flashable mode<\/em>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">root$ adb reboot bootloader\nroot$ fastboot devices\n[...] fastboot\nroot$ fastboot oem unlock 0x&lt;insert your unlock code&gt;\n\u2026\nOKAY [ 16.947s]\nfinished. total time: 16.947s<\/pre>\n\n\n\n<p>Unplug and start the phone. As explained in the previous posts, enable once again developer mode and USB debugging in the phone.<\/p>\n\n\n\n<p>At this point, I decided not to keep following the LineageOS guideline since it explains how to use the Lineage Recovery. Instead, I used the TWRP recovery tool just because I have experience with it and like it better. However, I don&#8217;t recommend it as I&#8217;ve explained in the <a href=\"https:\/\/blog.andresgomez.org\/2020\/09\/11\/installing-lineageos-in-the-sony-xperia-xz2-compact-dual-in-gnu-linux-5-5-appendixes\/\" data-type=\"URL\" data-id=\"https:\/\/blog.andresgomez.org\/2020\/09\/11\/installing-lineageos-in-the-sony-xperia-xz2-compact-dual-in-gnu-linux-5-5-appendixes\/\" target=\"_blank\" rel=\"noreferrer noopener\">Appendixes<\/a>.<\/p>\n\n\n\n<p>Therefore, I explain here the same steps than the official guide. Download the latest <a rel=\"noreferrer noopener\" href=\"https:\/\/download.lineageos.org\/xz2c\" data-type=\"URL\" data-id=\"https:\/\/download.lineageos.org\/xz2c\" target=\"_blank\">Lineage Recovery and LineageOS installation package<\/a> and connect the device to your PC with the USB cable and continued to set it in <em>flashable mode<\/em>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">root$ adb reboot bootloader\nroot$ fastboot devices\n[...] fastboot\nroot$ fastboot flash boot &lt;lineage_recovery&gt;.img<\/pre>\n\n\n\n<p>Power off the device and now turn it on into Recovery mode by pressing <kbd>Volume Down<\/kbd> + <kbd>Power<\/kbd>.<\/p>\n\n\n\n<p>Now, being booted into the Recovery mode, I downloaded a pre-install <a rel=\"noreferrer noopener\" href=\"https:\/\/androidfilehost.com\/?fid=8889791610682929240\" data-type=\"URL\" data-id=\"https:\/\/androidfilehost.com\/?fid=8889791610682929240\" target=\"_blank\">copy-partitions-20200903_1329.zip<\/a> tool and selected <em>Apply Update<\/em> -&gt; <em>Apply from ADB<\/em>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">root$ adb sideload copy-partitions-20200903_1329.zip<\/pre>\n\n\n\n<p>Once finished, reboot again into Recovery mode: <em>Go back <\/em>-&gt; <em>Advanced<\/em> -&gt; <em>Reboot to recovery<\/em>. Once back, <em>Factory reset<\/em> -&gt; <em>Format data\/factory reset<\/em>. Once finished, let&#8217;s install LineageOS: <em>Go back<\/em> -&gt; <em>Apply Update<\/em> -&gt; <em>Apply from ADB<\/em>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">root$ adb sideload lineage-17.1-&lt;date&gt;-xz2c-signed.zip<\/pre>\n\n\n\n<p>Now, before booting into the system, we want to add some more stuff: <a rel=\"noreferrer noopener\" href=\"https:\/\/opengapps.org\/\" data-type=\"URL\" data-id=\"https:\/\/opengapps.org\/\" target=\"_blank\">Open GApps<\/a> and <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/topjohnwu\/Magisk\" data-type=\"URL\" data-id=\"https:\/\/github.com\/topjohnwu\/Magisk\" target=\"_blank\">Magisk<\/a>.<\/p>\n\n\n\n<p>Magisk is a suite for customizing Android. Most importantly, it provides root access to the device, which I wanted to have in order to create backups of the installed applications and restore them, among other things.<\/p>\n\n\n\n<p>Open GApps will provided us the core functionality provided by Google for Android. Most importantly, it will provide us Google Play. <strong>It is critical to install this before booting for the first time into the system<\/strong>. Otherwise, we would have to repeat the <em>Factory reset <\/em>step and wipe out all our personal data before attempting to install it.<\/p>\n\n\n\n<p>Open GApps provides different size packages. The recommended for LineageOS are the <em>pico<\/em> or <em>nano<\/em>, but nothing bigger. Since I&#8217;m a troublemaker, I also wanted to <a href=\"https:\/\/github.com\/opengapps\/opengapps\/wiki\/Package-Comparison\" data-type=\"URL\" data-id=\"https:\/\/github.com\/opengapps\/opengapps\/wiki\/Package-Comparison\" target=\"_blank\" rel=\"noreferrer noopener\">customize the package<\/a> to include the <em>Android System Webview<\/em> and remove even further packages from the <em>pico<\/em> and <em>nano<\/em> packages.<\/p>\n\n\n\n<p>Hence, I downloaded the <em>stock<\/em> package for the <em>ARM64<\/em> platform and the <em>10.0<\/em> Android version.<\/p>\n\n\n\n<p>For reasons that I explain in the <a href=\"https:\/\/blog.andresgomez.org\/2020\/09\/11\/installing-lineageos-in-the-sony-xperia-xz2-compact-dual-in-gnu-linux-5-5-appendixes\/\" data-type=\"URL\" data-id=\"https:\/\/blog.andresgomez.org\/2020\/09\/11\/installing-lineageos-in-the-sony-xperia-xz2-compact-dual-in-gnu-linux-5-5-appendixes\/\" target=\"_blank\" rel=\"noreferrer noopener\">Appendixes<\/a>, I finally didn&#8217;t install the <em>Android System Webview<\/em> but did remove some packages any way. The way of customizing a package is through a <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/opengapps\/opengapps\/wiki\/Advanced-Features-and-Options\" data-type=\"URL\" data-id=\"https:\/\/github.com\/opengapps\/opengapps\/wiki\/Advanced-Features-and-Options\" target=\"_blank\">gapps-config<\/a> file. However, to use this method the installation cannot be done through <code>adb sideload<\/code> and, unfortunately, the Lineage Recovery only offers this way of installing packages into the system.<\/p>\n\n\n\n<p>Luckily enough, the Open GApps package is no more than a zip file so I could embed my options directly into the installer. So, after installing the LineageOS system, I rebooted again into Recovery mode: <em>Go back <\/em>-&gt; <em>Advanced<\/em> -&gt; <em>Reboot to recovery<\/em> and, back in Recovery, let&#8217;s install Open GApps: <em>Apply Update<\/em> -&gt; <em>Apply from ADB<\/em>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">root$ mkdir my_gapps\nroot$ cd my_gapps\nroot$ unzip ..\/open_gapps-arm64-10.0-stock-&lt;date&gt;.zip\nroot$ cat installer.sh # Added the following <strong>lines in bold<\/strong>\n\n[...]\n\n<strong>echo \"Include\" &gt; \"$TMP\/my_config.txt\"\necho \"\" &gt;&gt; \"$TMP\/my_config.txt\"\necho \"CalSync\" &gt;&gt; \"$TMP\/my_config.txt\"\necho \"DialerFramework\" &gt;&gt; \"$TMP\/my_config.txt\"\necho \"GoogleTTS\" &gt;&gt; \"$TMP\/my_config.txt\"\necho \"PackageInstallerGoogle\" &gt;&gt; \"$TMP\/my_config.txt\"\necho \"BatteryUsage\" &gt;&gt; \"$TMP\/my_config.txt\"\necho \"Speech\" &gt;&gt; \"$TMP\/my_config.txt\"\necho \"#GooglePay\" &gt;&gt; \"$TMP\/my_config.txt\"\necho \"Translate\" &gt;&gt; \"$TMP\/my_config.txt\"<\/strong>\n\n# Locate gapps-config (if used)\nfor i in \"$TMP\/aroma\/.gapps-config\"\\\n<strong>\"$TMP\/my_config.txt\"\\\n<\/strong>\"$zip_folder\/.gapps-config\"\\\n\n[...]\n\nroot$ zip -0 -r ..\/my_gapps *\nroot$ cd ..\nroot$ adb sideload my_gapps.zip<\/pre>\n\n\n\n<p>And, now, let&#8217;s install <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/topjohnwu\/Magisk\/releases\" data-type=\"URL\" data-id=\"https:\/\/github.com\/topjohnwu\/Magisk\/releases\" target=\"_blank\">Magisk<\/a>: <em>Apply from ADB<\/em>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">root$ adb sideload Magisk-v20.4.zip<\/pre>\n\n\n\n<p>Once finished we can finally <em>Go back<\/em> -&gt; <em>Reboot system now<\/em>.<\/p>\n\n\n\n<p>Congratulations, your Sony Xperia XZ2 Compact Dual is now running LineageOS 17.1!!!<\/p>\n\n\n\n<p>I have to say that, so far, I&#8217;m quite happy with the phone. It is a huge improvement for me, coming from a Xiaomi Redmi 2.<\/p>\n\n\n\n<p>However, the camera has lost some enhanced functionality so let&#8217;s continue to <a href=\"https:\/\/blog.andresgomez.org\/2020\/09\/10\/installing-lineageos-in-the-sony-xperia-xz2-compact-dual-in-gnu-linux-4-5-bringing-back-sonys-stock-camera-app\/\" data-type=\"URL\" data-id=\"https:\/\/blog.andresgomez.org\/2020\/09\/10\/installing-lineageos-in-the-sony-xperia-xz2-compact-dual-in-gnu-linux-4-5-bringing-back-sonys-stock-camera-app\/\" target=\"_blank\" rel=\"noreferrer noopener\">bring back Sony&#8217;s stock camera app<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>WARNING I have no responsibility whatsoever if this guideline causes any harm to your device. The intention of these posts are solely as personal notes for myself. Follow them at your own risk. WARNING Through these steps I will unlock &hellip; <a href=\"https:\/\/blog.andresgomez.org\/es\/2020\/09\/09\/installing-lineageos-in-the-sony-xperia-xz2-compact-dual-in-gnu-linux-3-5-installing-lineageos\/\">Sigue leyendo <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,6,7,20],"tags":[],"class_list":["post-979","post","type-post","status-publish","format-standard","hentry","category-english","category-free-software","category-general","category-mobile"],"_links":{"self":[{"href":"https:\/\/blog.andresgomez.org\/es\/wp-json\/wp\/v2\/posts\/979"}],"collection":[{"href":"https:\/\/blog.andresgomez.org\/es\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.andresgomez.org\/es\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.andresgomez.org\/es\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.andresgomez.org\/es\/wp-json\/wp\/v2\/comments?post=979"}],"version-history":[{"count":7,"href":"https:\/\/blog.andresgomez.org\/es\/wp-json\/wp\/v2\/posts\/979\/revisions"}],"predecessor-version":[{"id":1006,"href":"https:\/\/blog.andresgomez.org\/es\/wp-json\/wp\/v2\/posts\/979\/revisions\/1006"}],"wp:attachment":[{"href":"https:\/\/blog.andresgomez.org\/es\/wp-json\/wp\/v2\/media?parent=979"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.andresgomez.org\/es\/wp-json\/wp\/v2\/categories?post=979"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.andresgomez.org\/es\/wp-json\/wp\/v2\/tags?post=979"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}