DEV Community

Cover image for How I Installed Ubuntu Touch (Halium) on the Xiaomi Redmi 4A (rolex) — full step-by-step (Ubuntu 22.04)
Artur Linnik
Artur Linnik

Posted on

How I Installed Ubuntu Touch (Halium) on the Xiaomi Redmi 4A (rolex) — full step-by-step (Ubuntu 22.04)

Short version: I installed an unofficial alpha build packaged as a TWRP ZIP (HM4A-UbuntuTouch-UNOFFCIAL-ALPHA). After fixing /data and using the TWRP installer the device boots Ubuntu Touch. On my unit mobile, Wi-Fi, calls and audio output work; camera does not. Below is a detailed, copy-pasteable guide, exact commands for Ubuntu 22.04, and a troubleshooting section covering all pitfalls I ran into.

Forum post I used as primary reference: https://xdaforums.com/t/ubuntu-touch-rolex-redmi4a.4058619/

Screenshot / installer image: https://drive.google.com/file/d/1-1S-fLcEpH56gCvPS4CqhwrfNTa2qJVv/view?usp=drivesdk

1) What you need (prerequisites)

Laptop running Ubuntu 22.04 (commands below assume this).

USB cable and the Redmi 4A.

Unlocked bootloader for the phone (Xiaomi requires a Mi-Account permission step). Unlocking will wipe the phone.

TWRP recovery for rolex (Redmi 4A) — get the build for your device from XDA/twrp.me or the thread above.

HM4A-UbuntuTouch-UNOFFCIAL-ALPHA.zip (or CI build / packaged installer). If you only have images (halium-boot.img, system.img, rootfs.img, META-INF), see the TWRP zip repack step below.

On the PC: install ADB & Fastboot:

sudo apt update
sudo apt install -y adb fastboot unzip zip
Enter fullscreen mode Exit fullscreen mode

(Optional but recommended) keep a stock MIUI fastboot ROM for Redmi 4A ready — useful to restore partitions if things go wrong.

2) High-level plan (what we’ll do)

Unlock bootloader (if not already done).

Flash official TWRP for rolex.

Fix /data (format if needed) so TWRP can mount it.

Use TWRP to install the provided Ubuntu Touch ZIP (recommended).

If ZIP is broken, either repack it correctly or manually flash images in a specific order.

Post-install checks and common fixes.

3) Unlock bootloader (brief)

Xiaomi requires account authorization; follow Xiaomi’s official unlock procedure. If you prefer fastboot command (older devices may accept this):

fastboot devices                # confirm device in fastboot
# either:
fastboot oem unlock
# or on newer bootloaders:
fastboot flashing unlock
Enter fullscreen mode Exit fullscreen mode

Warning: unlocking wipes userdata. If you haven’t backed up, do so now.

4) Flash TWRP (fastboot method)

Download twrp-rolex.img (the twrp build for rolex). Then:

# place twrp img in current folder
fastboot devices
fastboot flash recovery twrp-rolex.img
# IMPORTANT: boot into TWRP immediately (don't reboot normally)
fastboot boot twrp-rolex.img
Enter fullscreen mode Exit fullscreen mode

If you used fastboot flash recovery, some MIUI builds will overwrite custom recovery on first boot — that’s why fastboot boot (or immediately entering recovery) is recommended.

5) Fix /data and prepare TWRP

If TWRP shows errors like Could not mount /data or Failed to mount /data (Invalid argument):

A — Preferred (from TWRP):

In TWRP: Wipe → Format Data → type yes.

This removes encryption and recreates a clean /data. This deletes internal storage content.

Then: Wipe → Advanced Wipe → select Data and Cache → Repair or Change File System → Change File System → ext4 (swipe to confirm).

Back to TWRP main → Mount → tick Data and Cache. Confirm they mount.

B — If TWRP “invalid partition selection” or format fails:

The partition table may be damaged. Recommended fix: restore userdata.img and cache.img from the official MIUI fastboot ROM:

Extract stock MIUI fastboot ROM (on PC), find userdata.img and cache.img.

Boot phone to fastboot and flash those:

fastboot flash userdata userdata.img
fastboot flash cache cache.img
Enter fullscreen mode Exit fullscreen mode

Note: fastboot format userdata sometimes fails on Xiaomi (error about block size). Use TWRP format or stock images instead.

6) Try the TWRP ZIP installer (recommended)

If you have HM4A-UbuntuTouch-UNOFFCIAL-ALPHA.zip:

Copy ZIP to phone (if /data is mounted):

adb push HM4A-UbuntuTouch-UNOFFCIAL-ALPHA.zip /sdcard/
Enter fullscreen mode Exit fullscreen mode

In TWRP: Install → select the zip → Swipe to confirm.

The META-INF/com/google/android/updater-script in the ZIP will extract rootfs.img into /data and set up loop mounts properly (this is why the ZIP method is preferred).

When install finishes: Reboot → System (first boot can take 5–10 minutes).

If TWRP complains “Invalid zip file format” (common), see section Zip is invalid / repack below.

7) If the ZIP method fails — manual fastboot flashing (advanced)

Only use this if the ZIP refuses to install and you know how to recover with TWRP/stock ROM:

Boot phone to fastboot.

Flash kernel/boot (halium):

fastboot flash boot halium-boot.img
Enter fullscreen mode Exit fullscreen mode

Flash system (system.img may be sparse — that’s ok; fastboot handles sparse files):

fastboot flash system system.img
Enter fullscreen mode Exit fullscreen mode

Do NOT necessarily flash rootfs.img with fastboot unless the port expects that. If you must:

fastboot erase userdata
fastboot flash userdata rootfs.img
Enter fullscreen mode Exit fullscreen mode

(If fastboot flash userdata fails or creates a black screen, undo and use the TWRP zip method — many ports expect rootfs copied by the installer script.)

Reboot:

fastboot reboot
Enter fullscreen mode Exit fullscreen mode

Important: If after flashing everything you get a black screen (no logo, blank), that usually means halium-boot.img is the wrong kernel/initramfs for your device or the rootfs isn't mounted the way the kernel expects. Try the TWRP zip installer first.

8) How to repack the files into a proper TWRP ZIP (if original ZIP is invalid)

If you have a folder structure (META-INF, halium-boot.img, data/system.img, data/rootfs.img) but TWRP rejects the ZIP as invalid, repack on Ubuntu:

cd HM4A-UbuntuTouch-UNOFFCIAL-ALPHA   # your folder
# from inside the folder:
zip -r9 ../HM4A-UbuntuTouch-UNOFFICIAL-ALPHA-fixed.zip *
# test the zip:
unzip -t ../HM4A-UbuntuTouch-UNOFFICIAL-ALPHA-fixed.zip
Enter fullscreen mode Exit fullscreen mode

Push the -fixed.zip to phone and flash via TWRP.

9) Useful ADB / Fastboot commands (logging & diagnostics)

Check fastboot connection:

fastboot devices
fastboot getvar all > fastboot_vars.txt

Enter fullscreen mode Exit fullscreen mode

When in TWRP (adb works there), pull logs:

adb devices
adb shell dmesg > dmesg.txt
adb shell cat /proc/last_kmsg > last_kmsg.txt    # may not exist on all kernels
adb pull /tmp/recovery.log
Enter fullscreen mode Exit fullscreen mode

If TWRP can't mount /data, check it in shell:

adb shell
ls -al /data
mount | grep data

Enter fullscreen mode Exit fullscreen mode

If you see Invalid sparse file format at header magic during fastboot system flash, that is usually a warning — fastboot will still send sparse chunks and succeed. You can ignore the header warning if fastboot completed.

10) Pitfalls & troubleshooting (collected from my run)

Keep this as your quick checklist.

Could not mount /data / unable to find crypto footer

Why: userdata was encrypted or corrupted.

Fix: In TWRP Wipe → Format Data → yes, then Repair/Change FS → ext4. If that fails, restore userdata.img from stock MIUI.

Invalid erase-block-size when fastboot format userdata

Why: fastboot’s mke2fs parameters wrong for Xiaomi partition geometry.

Fix: Use TWRP Format Data or restore userdata.img from stock fastboot ROM.
Invalid zip file format when flashing zip in TWRP

Why: zip was not packaged correctly (renamed folder or wrong compression).

Fix: Repack with zip -r9 from inside the folder, test with unzip -t.

error opening: '/data/dev/loop7' (not a directory) when wiping

Why: leftover files from a previous loop-mounted rootfs.

Fix: Format /data or delete stale files in /data (rm -rf /data/*) from TWRP terminal after formatting.

Black screen / no boot logo after flashing

Why A: wrong halium-boot.img (kernel/device tree mismatch).

Why B: rootfs.img was installed incorrectly (fastboot vs installer script).

Fix: Reflash using the TWRP ZIP installer (preferred), or re-obtain the correct halium-boot for your device. If needed, restore stock MIUI and start over.

adb logcat not found / empty

adb only shows up when Android or recovery (TWRP) runs adbd. If you are in fastboot mode, use fastboot commands; boot into TWRP to use adb shell and adb pull.

fastboot flash system shows sparse warning

Usually harmless if fastboot completes with OKAY. Confirm by checking /system content in TWRP or boot.
Permissions / account issues unlocking bootloader

Xiaomi requires an unlock authorization. Use the official Mi Unlock process; it may require a Windows tool and waiting period for some accounts.

11) If you want to revert to stock (MIUI)

Use MiFlash (Windows) with the official fastboot ROM and select clean all or flash_all. That restores stock partition layout and firmware.

12) What works / what doesn’t (my test)

Works: mobile (calls), Wi-Fi, voice/audio output.

Broken: camera (not working).

Expect other hardware (GPS, sensors) to be hit/miss depending on the build.

13) Quick recovery checklist (if you get stuck)

Can you enter fastboot? If yes — you are not hard-bricked.

Can you enter TWRP? If yes — pull logs (dmesg, recovery.log) and reattempt installer zip.

If /data is irrecoverable: restore userdata.img from stock MIUI or use TWRP Format Data.

If system doesn’t boot after correct TWRP zip install — the port itself might be unstable; try a different CI artifact or ask the port maintainer.

14) Appendix — sample full session (copy/paste)

This is the sequence that worked for me (replace filenames as needed):

# (on Ubuntu 22.04)
sudo apt update
sudo apt install -y adb fastboot unzip zip

# put device into fastboot (power + vol down)
fastboot devices

# flash or boot TWRP
fastboot boot twrp-rolex.img

# in TWRP: Wipe -> Format Data -> yes
# back on PC, push installer zip (if /data mounted)
adb push HM4A-UbuntuTouch-UNOFFCIAL-ALPHA-fixed.zip /sdcard/

# in TWRP: Install -> select the zip -> swipe to flash

# after successful install:
adb shell sleep 1
fastboot reboot

# if system doesn't boot, use TWRP to collect logs:
# boot recovery, then on PC:
adb shell dmesg > dmesg.txt
adb pull /tmp/recovery.log

Enter fullscreen mode Exit fullscreen mode

15) Final notes & disclaimers

This entire installation journey wouldn’t have been possible without a lot of trial, error, and guidance from ChatGPT (OpenAI GPT-5, 2025).
I leaned on ChatGPT heavily for:

debugging TWRP errors (/data mount failures, sparse image warnings, loop device issues),

understanding Halium’s boot sequence,

repacking the installer zip correctly,

fastboot and adb command sequences,

and even writing the draft for this article.

If you attempt this yourself, expect setbacks — but also know that with good logs, patience, and the right questions, it’s very doable.

Big thanks to the original porter(s) of Ubuntu Touch for Redmi 4A, the UBports community, and ChatGPT GPT-5 for helping breathe new life into old hardware.

Top comments (0)