Consolidated Guide: Installing and Configuring a Custom Android Environment for Daily + Advanced Use
This document consolidates the entire discussion into a single, fully detailed setup plan for running a custom Android OS (e.g., LineageOS) with strong isolation, full customization, and advanced tooling. It prioritizes daily usability while enabling advanced usage (pentesting, Linux tools, etc.). Every step is explicitly spelled out with explanations, not just mentions. It now also includes an alternative path for Jolla Community / Sony Xperia devices, and a conceptual guide to dual-booting Sailfish OS and LineageOS.
- LineageOS is an open-source Android distribution maintained by a large community.
- It is based on the Android Open Source Project (AOSP) but strips away Google’s proprietary services, tracking, and pre-installed bloatware.
- It provides a clean, stable, and flexible foundation for customization.
- You can still add Google Apps (via GApps) if you need them, but you control whether they are present and how isolated they are.
- LineageOS accepts rooting via Magisk easily, which allows modules like AFWall+, LSPosed, or BusyBox.
- Daily-driver stability is a core design goal.
- Stable and actively maintained for many modern phones (Pixel, Xiaomi, Samsung Galaxy, OnePlus, etc.).
- Maintains Android app (APK) compatibility.
- Gives you privacy control: no Google Play Services by default, unless you flash them.
- Community-driven with many device-specific maintainers.
- Camera drivers and biometrics may be less polished than stock firmware (depends on device).
- May require unofficial builds if your device is not officially supported.
- Google apps and services are optional add-ons but must be flashed separately.
You’ll be working in Linux for flashing. Ensure you have the necessary tools:
sudo apt update
sudo apt install android-tools-adb android-tools-fastbootadb= Android Debug Bridge (manage device, install packages, enable debugging).fastboot= tool for flashing partitions while in bootloader mode.- Custom Recovery (e.g., TWRP or OrangeFox) must be downloaded.
- ROM: LineageOS build for your device.
- Optional packages:
- GApps (NikGApps, MindTheGApps) → install only if you want Play Store.
- Magisk ZIP + APK → for rooting and module support.
- On the phone, go to Settings → About Phone → tap Build Number 7 times to enable Developer Options.
- In Developer Options: enable OEM Unlocking and USB Debugging.
- Connect device to PC, verify with:
adb devicesadb reboot bootloader
fastboot flashing unlock- Confirm on the phone screen.
- Unlocking wipes all data, so back up first.
- Reboot into bootloader:
adb reboot bootloader- Flash recovery image:
fastboot flash recovery twrp.img- Reboot into recovery:
fastboot reboot recovery-
In recovery (TWRP/OrangeFox): Wipe partitions (Dalvik/ART Cache, System, Data, Cache).
-
Sideload LineageOS:
adb sideload lineageos.zip- (Optional) Sideload GApps:
adb sideload gapps.zip- Reboot into LineageOS system.
- From recovery, sideload Magisk ZIP.
- Reboot system.
- Install Magisk Manager APK on the phone.
- Open app → verify root status.
- Riru – backend framework used by LSPosed.
- LSPosed – Xposed framework for modifying apps.
- Shizuku – allows apps to request elevated permissions.
- BusyBox – standard Linux utilities missing on Android.
- AFWall+ – firewall that controls which apps use WiFi/Mobile.
- AdAway – system-wide ad blocker.
- Kernel tools (EX Kernel Manager, SmartPack) – optional if tweaking CPU/GPU.
- Install Island or Shelter from F-Droid.
- Create a Work Profile → isolated container.
- Inside Work Profile, install Google Drive, Microsoft Teams, Outlook, OneDrive.
- Apply AFWall+ and VPN rules to separate their traffic.
- Install Proton apps (Mail, VPN), Ente Auth, Discord with Vencord, Firefox.
- Keep Google/MS apps out of personal profile.
- Work profile = Google/Microsoft only.
- Personal profile = Proton/Ente/Discord.
- Firefox PWAs = third instance of Google/MS apps (see section 8).
- Open AFWall+, grant root.
- Enable per-profile control.
- Configure rules:
- Work profile: allow Google/Microsoft apps → block Proton apps.
- Personal profile: allow Proton/Discord apps → block Google/MS.
- Enable IPv4 and IPv6 support.
- Enable firewall logging to verify activity.
- Install ProtonVPN.
- Assign:
- Work profile → ProtonVPN limited to Google/MS apps.
- Personal profile → ProtonVPN for Proton/Discord traffic.
- In Android Settings: enable Always-on VPN + Block connections without VPN.
- AdAway blocks ads/trackers at system level.
- LSPosed modules can spoof device info, block analytics.
- Shizuku automation enforces firewall/VPN rules on boot.
- Download via F-Droid.
- Install Firefox Containers Add-on.
- Add uBlock Origin, HTTPS Everywhere, Cookie AutoDelete.
- Install Discord APK.
- Install Vencord Installer APK.
- Patch Discord.
- Open Discord → verify Vencord enabled.
- Configure plugins/themes for usability.
- Install ProtonMail, ProtonVPN, Proton Bridge.
- ProtonVPN set to Always-on in personal profile.
- Install APK, migrate/import 2FA codes.
- Use as 2FA replacement instead of Google Authenticator.
- Install Google Drive, OneDrive, Outlook, Teams inside work profile.
- Hide root for these apps via Magisk DenyList.
- If apps fail, spoof device fingerprint with LSPosed.
Instead of three installs of the same app, use PWAs (Progressive Web Apps):
- Open Firefox/IceRaven.
- Navigate to Google Drive.
- Use browser menu → “Install Site as App”.
- Repeat for Outlook, OneDrive, Teams.
Result:
- Personal Google Drive = APK in personal profile.
- Work Google Drive = APK in work profile.
- Secondary Google Drive = Firefox PWA.
This provides 3 isolated instances without juggling multiple OS profiles.
- Install Termux via F-Droid.
- Install add-ons: Termux:API, Termux:Boot.
- Update system and install tools:
pkg update && pkg upgrade
pkg install nmap hashcat aircrack-ng python git- Download Nethunter rootfs.
- Import into Termux with
proot-distro. - Launch Nethunter shell for a full Kali environment.
- Run standard tools (nmap, hydra, metasploit, hashcat).
- Use VPN split tunneling to keep pentesting traffic isolated from personal apps.
Sony’s Open Devices Program provides full kernel sources, device trees, and flashing documentation. Xperia models are fully AOSP-compatible with fastboot flashing, making them ideal for experimentation.
Advantages:
- Official bootloader unlocking.
- Kernel source access on Sony’s GitHub.
- Active developer community (LineageOS, Sailfish, Ubuntu Touch, postmarketOS).
- Predictable partition layout and easy recovery.
- Xperia 10 / 10 II / 10 III (Jolla’s main community phones)
- Xperia XA2 / XA2 Ultra (older but stable)
- Xperia X / XZ1 Compact (compact, budget)
- Xperia 1 II / 5 II (flagships with long-term support)
- Unlock the bootloader via Sony’s official site using IMEI.
- Flash TWRP or Lineage recovery.
- Wipe system/data/cache.
- Flash ROM (LineageOS, /e/OS, Ubuntu Touch, or Sailfish).
- Flash Magisk if rooting.
- Reboot and configure profiles as above.
While not officially supported, a dual-boot setup is technically possible because Sailfish OS and LineageOS share the same kernel base (Sony AOSP). Methods:
- Shared Bootloader Chain: Use a multiboot recovery like TWRP Multiboot or BootMenu to alternate system partitions.
- Partition Duplication: Create an additional
system_bpartition, flash Sailfish on one, LineageOS on the other. - Boot Script Control: Modify init scripts or use
bootctl set-active-boot-slotto toggle active systems. - Waydroid or Chroot Approach: Alternatively, run one OS within the other (Sailfish with Waydroid or LineageOS with a Sailfish container).
Limitations: Dual-booting requires manual control of partitions and recovery; automatic switching is rare. Backup partitions before experimentation.
Benefit: You can maintain a full Linux (Sailfish) environment while retaining an Android-focused OS (Lineage) for app compatibility.
┌─────────────────────────────────────────────────┐
│ Android Device │
│ │
│ ┌──────────────┐ ┌──────────────┐ │
│ │ Work Profile │ │ Personal Prof│ │
│ │--------------│ │--------------│ │
│ │ Google Suite │ │ ProtonMail │ │
│ │ MS Office │ │ Ente Auth │ │
│ │ Outlook │ │ Discord+Venc │ │
│ │ Teams │ │ Firefox+PWAs │ │
│ │ VPN (Proton) │ │ ProtonVPN │ │
│ └──────────────┘ └──────────────┘ │
│ ↑ ↑ │
│ │ │ │
│ AFWall+ / NetGuard Firewall Rules │
│ (Per-profile isolation) │
│ │
│ LineageOS + Magisk │
│ ┌────────────────────────────────────────────┐ │
│ │ Modules: LSPosed, Riru, Shizuku, BusyBox, │ │
│ │ AFWall+, AdAway, Kernel Auditor optional │ │
│ └────────────────────────────────────────────┘ │
│ │
│ Termux / Kali / Nethunter │
│ (Pentesting / CLI tools) │
└─────────────────────────────────────────────────┘
Sony Xperia devices (especially those in Jolla’s Community Device lineup) are among the most developer-friendly phones available today. Through the Sony Open Devices Program (ODP), you get:
- Official kernel source and vendor binaries for AOSP builds.
- Official fastboot unlocking via Sony’s site.
- Legal, fully documented methods for flashing and modifying the OS.
- Active support for LineageOS, SailfishOS, Ubuntu Touch, /e/OS, and even postmarketOS.
This means you can replace or dual-boot operating systems with almost no proprietary lock-in or hidden risk.
| Model | ODP Support | Notes |
|---|---|---|
| Xperia 10 / 10 II / 10 III | ✅ | Official Jolla community phones, Sailfish preinstalled |
| Xperia XA2 / XA2 Ultra | ✅ | Great LineageOS and Ubuntu Touch support |
| Xperia X / XZ1 Compact | ✅ | Small form factor, mature ROMs |
| Xperia 1 II / 5 II | ✅ | Flagships with long-term kernel updates |
-
Unlock Bootloader
-
Obtain unlock code from Sony’s developer site.
-
Enable OEM Unlocking and USB Debugging.
-
Connect via USB and execute:
adb reboot bootloader fastboot oem unlock 0x<unlock_code>
-
-
Flash Recovery
-
Download TWRP or Lineage Recovery for your Xperia model.
fastboot flash recovery twrp.img
-
-
Wipe Partitions
- In recovery, wipe System, Data, Cache, and Dalvik.
-
Install LineageOS
adb sideload lineageos.zip
-
Optional: Reinstall SailfishOS later
- Jolla provides flashable Sailfish images with scripts for fastboot.
- You can swap back and forth by re-flashing system partitions.
-
Obtain a Sailfish image for your device from Jolla’s developer portal.
-
Boot to fastboot mode.
-
Execute the provided
flash.shscript:./flash.sh
-
The script wipes LineageOS partitions and flashes Sailfish system + userdata.
Dual-booting Sailfish and Lineage is possible via careful partition management and the use of multi-boot recovery or boot managers.
-
Resize userdata partition using
partedfrom recovery to create ~4–6 GB of free space. -
Create an extra ext4 partition (e.g.,
/dev/block/sda64) for the secondary OS. -
Flash:
- LineageOS to
/system_a. - SailfishOS to
/system_b(or the new partition).
- LineageOS to
-
Use TWRP’s “Install Image” function to write each OS to its own slot.
-
Configure boot control via:
fastboot --set-active=a fastboot --set-active=b
or install MultiROM (legacy) or a custom recovery script that lets you pick an OS on boot.
-
Keep
/datashared or separate (recommended: separate for stability).
Instead of dual-booting:
-
Keep SailfishOS as the host.
-
Use Waydroid (Android container) to run LineageOS-based Android inside it. This grants:
- Full APK compatibility.
- Seamless switch between Linux and Android sessions.
- Fewer flashing risks.
-
Always back up the entire
userdataandsystempartitions before experimenting. -
Boot slots (
_a/_b) differ by model; confirm partition maps with:fastboot getvar all
-
Jolla’s init scripts assume control over
/system; modifying them can break OTA updates. -
Ideal for tinkering or multi-environment setups, not for mission-critical daily use.
| Feature | Benefit |
|---|---|
| Official Bootloader Unlock | No shady exploits, fully reversible |
| Kernel Source | Build and modify yourself |
| AOSP & Lineage Support | Seamless porting between OSes |
| SailfishOS Base | Linux-native stack with Waydroid |
| PostmarketOS Compatibility | True Linux phone potential |
| Excellent Documentation | Sony publishes flashing & recovery guides |
| Layer | OS/Tool | Purpose |
|---|---|---|
| Host OS | LineageOS or Sailfish | Base platform |
| Root Framework | Magisk | Control + modules |
| Isolation | Island/Shelter + PWAs | Sandbox for work/personal |
| Pentesting | Termux + Nethunter | Advanced tools |
| Privacy | AFWall+, AdAway, LSPosed | Network & tracking control |
| Dual-boot or Waydroid | Optional | Switch or embed other OS |
| Apps | Firefox, Discord+Vencord, Proton, Ente | Daily driver suite |
- You gain a fully open hardware stack, rare among modern smartphones.
- Dual-booting or hybrid OS usage becomes realistic.
- You can test or use Android, Sailfish, or Ubuntu Touch interchangeably.
- Hardware (Snapdragon, modem, camera) is well-supported by the open community.
- Long-term: this is the most modder-friendly and privacy-respecting hardware route for advanced mobile Linux/Android experimentation.
This appendix details optional but powerful configurations for Sony Xperia and other Treble-compliant phones that allow true OS switching or hybridization between Android (LineageOS) and Linux (Sailfish, Ubuntu Touch, etc.). Proceed only if you’re comfortable manipulating partitions and bootloaders.
Before attempting any partitioning or flashing, inspect your layout and back up everything.
adb reboot bootloader
fastboot getvar all | grep partitionYou’ll see something like:
(boot_a), (boot_b)
(system_a), (system_b)
(vendor_a), (vendor_b)
(userdata)
fastboot flash recovery twrp.img
adb reboot recovery
adb pull /dev/block/bootdevice/by-name/system_a system_a.img
adb pull /dev/block/bootdevice/by-name/userdata userdata.imgKeep these images safe—they allow a full rollback.
Use TWRP’s terminal or an attached Linux host to resize the userdata partition:
-
Identify your block device (e.g.,
/dev/block/sda). -
Launch
parted:parted /dev/block/sda
-
Print and note partitions:
print
-
Resize userdata:
resizepart <partition_number> <new_end_value> mkpart ext4 secondos <new_start_value> <new_end_value>
-
Format the new partition:
mkfs.ext4 /dev/block/sda64
Now /dev/block/sda64 will be your second OS slot (for Sailfish, Ubuntu Touch, or another Android ROM).
-
Extract Sailfish image from
flash.shpackage. -
Identify the system image file (
sailfish.img). -
Flash manually:
fastboot flash system_b sailfish.img fastboot --set-active=b fastboot reboot
To switch back:
fastboot --set-active=a
fastboot rebootModern Xperia devices use A/B partitioning for seamless updates. You can exploit this for dual-booting.
-
Flash LineageOS to slot a and SailfishOS to slot b.
-
Use fastboot to switch between them:
fastboot getvar current-slot fastboot --set-active=a # Switch to Lineage fastboot --set-active=b # Switch to Sailfish
-
Boot normally—the chosen slot determines which OS loads.
🧠 Tip: Keep /data common only if both OSes use Android’s encryption schema; otherwise, keep separate partitions for stability.
The legacy MultiROM boot manager can be ported to some Xperia devices, or you can use TWRP’s “Install Image” to maintain multiple system images and flash them dynamically.
-
Push both OS images (
system_lineage.img,system_sailfish.img) to/sdcard. -
Use TWRP’s terminal:
dd if=/sdcard/system_lineage.img of=/dev/block/bootdevice/by-name/system_a dd if=/sdcard/system_sailfish.img of=/dev/block/bootdevice/by-name/system_b
-
Reboot into desired slot.
For more automation, you can flash a small bootmenu binary that lists slots and runs the corresponding fastboot command—several examples exist on XDA.
If you prefer one OS hosting another instead of dual-booting, Waydroid gives you Android within Sailfish or Ubuntu Touch.
-
Connect to your device shell (SSH or terminal).
-
Add Waydroid repositories:
sudo zypper ar https://repo.waydroid.org/ waydroid sudo zypper refresh sudo zypper install waydroid
-
Initialize the container:
sudo waydroid init -s GAPPS
-
Start the Android container:
sudo systemctl start waydroid-container waydroid session start
You’ll now have a Lineage-based Android session running side-by-side with Sailfish Linux, complete with GUI apps, root control, and networking.
| Component | Location | Notes |
|---|---|---|
| VPN (Proton/OpenVPN) | Per-OS | Keep independent configs for each OS to prevent leak crossover |
| AFWall+ / iptables | Android side | Handles app-level firewall |
| UFW / nftables | Sailfish/Linux side | Manages global networking |
| Termux / chroot tools | Android side | Full CLI control |
| SSH between OSes | Both | Use to exchange scripts and logs securely |
To recover from errors:
adb reboot bootloader
fastboot --set-active=a
fastboot flash recovery twrp.img
fastboot reboot recoveryIn TWRP, restore your backups of system_a, system_b, and userdata. Always verify slot activation before OTA or manual updates.
Initial: LineageOS → slot_a
Add: Sailfish → slot_b
Switch: fastboot --set-active=b
Work: Sailfish + Waydroid container
Switch: fastboot --set-active=a
Daily: Lineage + Magisk + Island
- Dual-booting is experimental but reliable when done with caution on Xperia devices.
- Waydroid offers a safer, containerized alternative with nearly the same flexibility.
- Always maintain full images and understand the implications of shared encryption keys.
- Combined with your Lineage/Magisk stack, Xperia hardware can become a truly modular, privacy-centric mobile workstation.
⚠️ Note: Always verify exact names on your device usingfastboot getvar allorls /dev/block/bootdevice/by-name/— firmware updates can slightly alter naming or add new partitions.
| Partition | Function | Notes |
|---|---|---|
boot_a, boot_b |
Boot image (kernel + ramdisk) | Dual-slot (A/B) for seamless updates |
system_a, system_b |
Main OS (LineageOS, Sailfish, etc.) | Each slot can hold one OS image |
vendor_a, vendor_b |
Vendor blobs (drivers, HALs) | Usually identical between slots |
userdata |
/data partition | Shared between OSes unless split manually |
recovery |
TWRP / Lineage recovery | May be absent if boot.img contains recovery |
dtbo_a, dtbo_b |
Device tree overlays | Rarely modified manually |
modem_a, modem_b |
Baseband firmware | Never flash unless using official images |
persist |
Calibrations, camera, fingerprint | Always back up before flashing |
misc |
Boot flags | Controls active slot state |
| Partition | Function | Notes |
|---|---|---|
boot_a, boot_b |
Boot image | Same as XA2 |
system_a, system_b |
OS partitions | Primary location for ROM flashing |
vendor_a, vendor_b |
Vendor partition | Required for hardware functionality |
userdata |
User data | Encrypted, shared by default |
super |
Logical volume container (Android 10+) | Contains dynamic partitions (system, vendor) |
recovery |
Optional standalone recovery | Usually embedded |
dtbo_a, dtbo_b |
Device tree overlays | Leave untouched |
modem_a, modem_b |
Modem firmware | Flash only from official firmware |
persist |
Fingerprint, calibration | Must preserve when dual-booting |
metadata |
Encryption keys / FBE | Do not mix between OSes |
💡 These models often use Dynamic Partitions, meaning
system,vendor, and others live inside a sharedsuperpartition. Uselpdumporfastboot getvar super-partition-nameto inspect subvolumes before resizing.
| Partition | Function | Notes |
|---|---|---|
boot |
Boot image | Single-slot (non-A/B) layout |
system |
OS image | Flash custom ROMs here |
vendor |
Hardware abstraction layer | Matches OS version |
userdata |
User data | Can be split manually |
recovery |
Recovery partition | Required for TWRP |
modem |
Radio firmware | Leave untouched |
persist |
Calibration data | Always back up |
cache |
Legacy system cache | Can be repurposed for second OS |
🧠 Tip: These older models are simpler for dual-boot experiments — you can repurpose the
cacheor create a newsystem2partition for a secondary OS.
| Action | Command | |
|---|---|---|
| Check current slot | fastboot getvar current-slot |
|
| Set active slot A | fastboot --set-active=a |
|
| Set active slot B | fastboot --set-active=b |
|
| Verify partitions | `fastboot getvar all | grep slot` |
| Reboot into recovery | fastboot reboot recovery |
|
| List partitions | adb shell ls /dev/block/bootdevice/by-name/ |
for part in boot_a system_a vendor_a persist modem_a; do
fastboot getvar $part 2>&1 | grep OKAY
fastboot flash $part backup/${part}.img
donefor part in boot_a system_a vendor_a; do
fastboot flash $part backup/${part}.img
done🧩 Best Practice: Always back up
persistandmodempartitions before experimenting. Losing them can permanently break fingerprint or connectivity.
Modern Xperias use Dynamic Partitions (super.img):
-
system,vendor,product, andodmexist as subpartitions inside a single logicalsuper. -
You can manipulate them using lpunpack/lpmake tools:
lpunpack super.img ./super_parts/ lpmake --metadata-size 65536 --super-name super_new.img ... fastboot flash super super_new.img
-
This allows building custom split or merged system layouts for Lineage + Sailfish coexistence.
✅ Bootloader unlocked
✅ TWRP or Lineage Recovery functional
✅ Full backup of system/vendor/persist/modem
✅ Verified slot map (fastboot getvar all)
✅ Battery ≥ 60%
✅ USB 3.0 cable / stable connection
✅ ROM images verified with sha256sum
| Slot | OS | Kernel | Status |
|---|---|---|---|
| A | LineageOS 21 (Android 13) | Magisk + AFWall+ | Daily driver |
| B | SailfishOS 4.x | Stock kernel | Experimental |
| Shared | userdata, persist |
VPN configs / calibration | Backed up separately |
Switch with:
fastboot --set-active=a # LineageOS
fastboot --set-active=b # SailfishThese scripts are designed to run from your Linux workstation and streamline common flashing and verification tasks for Xperia or Treble-based phones.
💡 All commands assume you’ve installed
android-tools-adbandandroid-tools-fastboot. Usechmod +x scriptname.shto make them executable.
File: switch_os.sh
#!/bin/bash
# Simple slot toggler for Xperia dual-slot devices
set -e
current=$(fastboot getvar current-slot 2>&1 | grep -oE "[ab]")
echo "Current active slot: $current"
if [ "$current" == "a" ]; then
echo "Switching to slot B (e.g., SailfishOS)..."
fastboot --set-active=b
else
echo "Switching to slot A (e.g., LineageOS)..."
fastboot --set-active=a
fi
fastboot getvar current-slot
echo "Rebooting..."
fastboot rebootUsage:
adb reboot bootloader
./switch_os.shThis will toggle between slot A (LineageOS) and slot B (SailfishOS) automatically.
File: verify_partitions.sh
#!/bin/bash
# Checks hashes for critical partitions and compares with stored references
mkdir -p hashes
parts=("boot_a" "system_a" "vendor_a" "boot_b" "system_b" "vendor_b" "persist" "modem_a")
for part in "${parts[@]}"; do
echo "Dumping and hashing $part..."
fastboot get_staged $part || fastboot flash $part /dev/null 2>/dev/null || true
fastboot getvar $part >/dev/null 2>&1 || continue
fastboot flash $part /dev/null 2>/dev/null || true
fastboot dump $part > /tmp/$part.img 2>/dev/null || echo "Skipped $part"
sha256sum /tmp/$part.img | tee hashes/${part}.sha256
doneYou can later re-run it to verify no unexpected modifications:
sha256sum -c hashes/*.sha256File: backup_all.sh
#!/bin/bash
# Creates a complete backup of essential partitions
mkdir -p backup
for part in boot_a boot_b system_a system_b vendor_a vendor_b persist modem_a; do
echo "Backing up $part..."
fastboot getvar $part 2>&1 | grep OKAY || true
fastboot flash $part backup/${part}.img 2>/dev/null || fastboot get_staged $part > backup/${part}.img
done
echo "Backup complete: $(ls backup)"You can restore using:
for part in boot_a system_a vendor_a; do fastboot flash $part backup/${part}.img; doneFile: device_status.sh
#!/bin/bash
# Summarizes slot, partition health, and current OS version
echo "=== DEVICE STATUS ==="
fastboot getvar product
fastboot getvar current-slot
fastboot getvar is-userspace
fastboot getvar version-baseband
fastboot getvar version-bootloader
fastboot getvar unlocked
fastboot getvar secure
echo "Partition list:"
fastboot getvar all | grep "partition"Run this before and after flashing for full sanity checks.
These ASCII diagrams map your entire system build process, linking back to earlier sections for clarity.
┌───────────────────────────────────────────────┐
│ Linux Workstation (Section 2) │
│ ├─ adb / fastboot │
│ ├─ TWRP / Recovery Images │
│ ├─ LineageOS + GApps + Magisk packages │
│ │
│ Flash Process (Section 3): │
│ adb reboot bootloader → fastboot flash recov │
│ adb sideload lineageos.zip │
│ │
│ Rooting (Section 4): │
│ adb sideload Magisk.zip → Reboot → Verify │
└───────────────────────────────────────────────┘
┌────────────────────────────────────────────────────────────┐
│ LineageOS (Base OS) │
│ ├─ Magisk + Modules (AFWall+, LSPosed, Shizuku) │
│ ├─ Work Profile (Google/MS Apps) → AFWall+ + VPN rules │
│ ├─ Personal Profile (Proton, Ente, Discord+Vencord) │
│ └─ PWA Instances (Firefox) for isolated extra accounts │
│ │
│ Isolation & Privacy Layers: │
│ AFWall+ → Section 6 │
│ Shelter/Island → Section 5 │
│ Magisk DenyList → Section 7 │
└────────────────────────────────────────────────────────────┘
┌──────────────────────────────────────────────┐
│ Termux (Android App) │
│ ├─ nmap, hashcat, aircrack-ng, git, python │
│ └─ proot-distro import Kali Nethunter │
│ │
│ Optional: Nethunter RootFS → Full Kali Env │
│ Network isolation via VPN split tunneling │
└──────────────────────────────────────────────┘
┌──────────────────────────────────────────────┐
│ Xperia or Jolla Community Device │
│ ├─ Bootloader Unlocked (Sony ODP) │
│ ├─ Slot A: LineageOS (rooted, daily use) │
│ ├─ Slot B: SailfishOS (Linux-native, test) │
│ ├─ fastboot --set-active=a/b toggles OS │
│ └─ Backup scripts maintain parity │
│ │
│ Alt: Sailfish Host + Waydroid (Android-in-Lin)│
└──────────────────────────────────────────────┘
[Linux Host]
↓
(Section 2–3) → Flash LineageOS via adb/fastboot
↓
(Section 4–6) → Root with Magisk + configure privacy layers
↓
(Section 7–8) → Install apps & PWAs with sandboxed profiles
↓
(Section 9) → Deploy Termux/Kali for pentesting tools
↓
(Section 12) → Optional switch to Xperia path
↓
(Section A12–A13) → Automate slot switching & integrity checks
┌──────────────┐
│ VPN Tunnel 1 │ (Proton, Personal)
└──────────────┘
↑
[Personal Profile] ---- AFWall+ Rules ---- Firefox / Proton / Discord+Vencord
↓
┌──────────────┐
│ VPN Tunnel 2 │ (Work, Google/MS)
└──────────────┘
↑
[Work Profile] ------- AFWall+ Rules ---- Drive / Outlook / Teams
↓
[Waydroid Container or Slot B OS]
↓
Linux Tools / Sailfish Integration
| Section | Focus | Summary |
|---|---|---|
| 1–4 | Base OS Install | Flash LineageOS, Magisk root |
| 5–6 | Privacy & Isolation | Shelter, AFWall+, VPN |
| 7–8 | App Ecosystem | PWAs, Discord+Vencord, Proton/Ente |
| 9 | Pentesting Tools | Termux + Nethunter setup |
| 10–11 | System Diagram & Summary | Recap of build |
| 12 | Xperia/Jolla Alternative | Hardware path, Sailfish integration |
| A1–A10 | Dual-Boot Mechanics | Partition, flashing, Waydroid |
| A11 | Partition Reference | Safe flashing tables |
| A12 | Automation Scripts | Slot, verification, backup |
| A13 | Visual Overview | System architecture diagrams |
This appendix covers repair, rescue, and diagnostic routines for your dual-system Android environment. All procedures assume you’re operating from a Linux host with ADB + Fastboot installed and that critical partitions are already backed up (see Appendix A12).
- Device stuck at boot logo or endless animation
- Can enter fastboot or recovery, but OS won’t start
- Magisk module caused crash after flashing
-
Force reboot into bootloader
adb reboot bootloader -
Temporarily boot into recovery without flashing:
fastboot boot twrp.img -
Mount and remove problem modules (if rooted):
adb shell su mount /data cd /data/adb/modules mv <problem-module> /data/adb/modules_disabled/ exit -
Wipe Dalvik / Cache in recovery → reboot.
-
If the system slot itself is corrupted:
fastboot flash system_a lineageos.zip fastboot reboot -
If you have a second slot intact, switch:
fastboot --set-active=b fastboot reboot
- TWRP/OrangeFox prompts for password but cannot decrypt
/data - Boot hangs after enabling File-Based Encryption (FBE)
-
Backup any recoverable data via
adb pull /sdcard/. -
Format
/data(not just wipe):adb reboot recovery → Wipe → Format Data → type “yes” -
Re-flash ROM and Magisk.
-
Avoid incompatible kernels; verify your device’s
fstabentries allowfileencryption=aes-256-xts. -
Optional: disable forced encryption (advanced users only):
- Patch
/vendor/etc/fstab.*via Magisk module (use FBE Disabler).
- Patch
If Google-dependent apps refuse to run after root:
-
In Magisk, enable:
- Zygisk
- Enforce DenyList
-
Add the following to DenyList:
com.google.android.gmscom.android.vending- All Google Pay / Banking apps
-
Install Magisk module:
Universal SafetyNet Fix v2.x. -
Clear Play Store + Play Services data:
adb shell pm clear com.android.vending adb shell pm clear com.google.android.gms -
Reboot and check SafetyNet in Magisk’s “Check Integrity” section.
- AFWall+ blocks all traffic
- VPN fails to tunnel specific profile
-
Reset AFWall+ rules:
su iptables -F ip6tables -FThen reopen AFWall+ → Menu → Reset rules → Apply.
-
Verify UID separation:
adb shell dumpsys userEnsure Work/Profile UIDs are different.
-
In Proton VPN:
- Disable “Always-on”
- Connect manually, verify logs
- Re-enable “Always-on + Block Without VPN” afterwards.
Booting Sailfish (slot B) overwrites recovery or vendor image needed for Lineage (slot A).
-
Before flashing Sailfish:
fastboot --set-active=b fastboot flash system_b sailfish.img -
Lock vendor partitions:
fastboot erase vendor_b fastboot flash vendor_b vendor_sailfish.img fastboot --set-active=a -
If Sailfish overwrites shared partitions:
-
Boot to Linux host
-
Re-flash TWRP to both slots:
fastboot flash recovery_a twrp.img fastboot flash recovery_b twrp.img
-
waydroid status= “container stopped”- GUI app not opening under Sailfish OS
sudo systemctl enable --now waydroid-container
sudo waydroid init -s GAPPS
sudo waydroid session startIf device manager error appears:
sudo rm -rf /var/lib/waydroid/*
sudo waydroid initThen re-import your Android image and relink user permissions.
If apt or pkg fails inside Termux:
rm -rf $PREFIX/var/lib/apt/lists/*
pkg update
pkg upgrade
pkg install termux-toolsTo repair broken Nethunter environment:
proot-distro remove kali
proot-distro install kali-
Disable thermal-blocking Magisk modules.
-
Install EX Kernel Manager → set:
- Scheduler = cfq or noop
- Governor = interactive
-
Re-calibrate battery:
adb shell dumpsys battery reset -
Wipe
batterystats.bin:adb shell rm /data/system/batterystats.bin -
Reboot and charge fully.
-
Confirm vendor image version matches your ROM base (check release notes).
-
Flash original vendor:
fastboot flash vendor vendor_stock.img -
Reboot → test camera and fingerprint.
-
Optionally flash Open Camera or ANX Camera port.
-
For biometrics, enable proprietary blobs via Magisk module
miui-fp-service(device-specific).
If fastboot no longer works and device shows only a black screen:
-
Enter EDL mode (hold Vol+ + Vol– while plugging in USB).
-
On host:
sudo apt install python3-serial sudo python3 edl.py info -
Flash raw firmware package (from manufacturer or XDA).
-
Boot → relock bootloader if required.
After each recovery, verify with:
adb shell getprop ro.build.display.id
adb shell getprop ro.boot.slot_suffix
adb shell getprop ro.boot.verifiedbootstate
adb shell getprop ro.product.deviceExpected:
ro.boot.verifiedbootstate=orange # (unlocked)
Slot suffix matches intended OS
Run integrity script from A12 to confirm SHA-256 matches.
| Tool | Purpose | Notes |
|---|---|---|
| TWRP / OrangeFox | Flashing, backup, restore | Keep both slot copies |
| ADB & Fastboot | Device control | Use latest Android SDK platform-tools |
| Magisk Manager | Root management | Disable modules in Safe Mode if needed |
| AFWall+ & AdAway | Firewall / DNS control | Reset via Safe Mode if bootloop |
| Heimdall / Odin | Samsung rescue flashing | Non-fastboot devices |
| Xperia FlashTool | Sony firmware repair | For unbootable slots |
| EDL Tools | Deep recovery (Xiaomi/Huawei) | Requires USB debugging off |
- Always back up
/persistand/modembefore any cross-flashing. - Use Appendix A12 scripts after every major change.
- Keep one known-good bootable slot untouched.
- Avoid OTA updates unless you re-sign with Magisk’s “Preserve Force Encryption / Preserve AVB”.
- Document each flash and store logs in
/mnt/data/device-logs/.
With these repair strategies and verification routines, your LineageOS + Sailfish dual-environment can be maintained indefinitely, even through experimental Magisk, LSPosed, or kernel tweaks. Treat the process like managing two Linux distros on shared hardware: verify, snapshot, test, and roll back.
| Task / Problem | Command / Action | Notes / Section Reference |
|---|---|---|
| Reboot to bootloader | adb reboot bootloader |
Sections 2, A14.1 |
| Unlock bootloader | fastboot oem unlock 0x<unlock_code> |
Section 2, 12 |
| Flash recovery | fastboot flash recovery twrp.img |
Sections 3, 12 |
| Boot recovery temporarily | fastboot boot twrp.img |
Section A14.1 |
| Sideload ROM | adb sideload lineageos.zip |
Sections 3, 12 |
| Flash GApps | adb sideload gapps.zip |
Section 3 |
| Flash Magisk | adb sideload Magisk.zip |
Section 4 |
| Toggle dual-slot OS | fastboot --set-active=a/b |
Section 12, A12.1 |
| Check current slot | fastboot getvar current-slot |
Sections 12, A12.4 |
| Backup system partition | fastboot flash <part> backup/<part>.img |
Section A12.3 |
| Restore partition from backup | fastboot flash <part> backup/<part>.img |
Section A12.3 |
| List all partitions | adb shell ls /dev/block/bootdevice/by-name/ |
Sections A11, A13 |
| Reset AFWall+ rules | su → iptables -F; ip6tables -F |
Section A14.4 |
| Verify SHA-256 integrity | sha256sum -c hashes/*.sha256 |
Section A12.2 |
| Reboot recovery from fastboot | fastboot reboot recovery |
Sections 3, A14.1 |
| Check device properties | adb shell getprop ro.build.display.idadb shell getprop ro.boot.slot_suffixadb shell getprop ro.boot.verifiedbootstate |
Section A14.11 |
| Format /data (fix decryption) | Recovery → Wipe → Format Data | Section A14.2 |
| Re-flash system (slot-specific) | fastboot flash system_a lineageos.zip |
Sections 3, A14.1, 12 |
| Backup persist/modem | fastboot flash <part> backup/<part>.img |
Sections A12.3, A14.14 |
| Reset Termux/Nethunter environment | rm -rf $PREFIX/var/lib/apt/lists/*proot-distro remove kaliproot-distro install kali |
Section A14.9 |
| Start Waydroid container | sudo systemctl start waydroid-containerwaydroid session start |
Section A14.7 |
| Check VPN / Network status | AFWall+ logsadb shell dumpsys user |
Section A14.4 |
| Reboot device | fastboot reboot or adb reboot |
General |
- Keep this table open on your Linux workstation during flashing or experimentation.
- Always verify active slot before flashing any system image.
- Use backup and hash verification commands after every major change to prevent accidental bricking.
- Combine these with the automation scripts in Appendix A12 for semi-automated maintenance.