Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

8 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“บ๐Ÿง TVUbuntu โ€” Run a Real Ubuntu on Your Android TV Box

Note

๐Ÿ‡จ๐Ÿ‡ณ ไธญๆ–‡็”จๆˆท็œ‹่ฟ™้‡Œ / For Chinese readers๏ผšๅฎŒๆ•ดไธญๆ–‡ๆ–‡ๆกฃ โ†’ README_zh-CN.md

Turn any Android TV box or Android device into a tiny, always-on Ubuntu server. A Kotlin Android TV app boots a genuine Ubuntu (22.04 / 24.04 / 26.04) via a native chroot, auto-installs OpenSSH, and shows the SSH connection info right on your living-room screen.

Platform Language Min SDK License APK


๐ŸŒŸ Why TVUbuntu?

Most TV boxes are wasted silicon โ€” sitting idle, running ad-riddled launchers. TVUbuntu gives that hardware a second life as a real Linux server:

  • ๐Ÿง A genuine Ubuntu userland, not a container-emulated shell. Run apt, compile code, host services.
  • ๐Ÿ’ป SSH in from your laptop โ€” it behaves like any other headless Ubuntu box on your LAN.
  • ๐Ÿ”Œ Always-on, low-power โ€” a TV box draws ~2โ€“3 W and can stay up 24/7 as a homelab node.
  • ๐Ÿ’ฐ Recycle what you own โ€” no need to buy a Raspberry Pi or a VPS.
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”         SSH (port 22)        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Your Laptop / PC      โ”‚ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ถ โ”‚   Android TV Box (root)  โ”‚
โ”‚   $ ssh root@192.168.x.xโ”‚                              โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚                         โ”‚                              โ”‚  โ”‚ Ubuntu chroot        โ”‚ โ”‚
โ”‚                         โ”‚                              โ”‚  โ”‚  โ”œโ”€ openssh-server   โ”‚ โ”‚
โ”‚                         โ”‚                              โ”‚  โ”‚  โ”œโ”€ nginx / PHP / DB โ”‚ โ”‚
โ”‚                         โ”‚                              โ”‚  โ”‚  โ””โ”€ your services    โ”‚ โ”‚
โ”‚                         โ”‚                              โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                              โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
        โ–ฒ                                                          โ”‚
        โ”‚            TVUbuntu App shows host / user / password     โ”‚
        โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โœจ Features

Feature Description
๐Ÿง Native chroot Uses the kernel-native chroot โ€” no proot binary, lighter and faster.
๐Ÿ“ก Auto rootfs download App downloads the minimal ubuntu-base tarball and decodes gzip on-device (avoids the box's toybox tar quirks).
๐Ÿ”‘ Zero-config SSH Installs & launches openssh-server, then displays host / user / password / port on the TV.
๐ŸŽฎ TV-remote UI D-Pad navigation, focus-scaling "cursor" animation, large high-contrast buttons โ€” built for a remote, not a touchscreen.
๐ŸŒ Multi-architecture arm64 (real boxes), amd64 (x86_64 emulators like MuMu), armhf (32-bit ARM).
๐Ÿ”„ Multi-version Ubuntu 22.04 (jammy) / 24.04 (noble) / 26.04 (resolute), isolated per version+arch.
โš™๏ธ Boot auto-start Optional "start Ubuntu on boot" + launch-on-boot receiver.
๐Ÿ›ก๏ธ Robust shell layer ShellExecutor auto-detects su modes (interactive vs su -c), streams live progress, survives large output.
๐Ÿš€ Production web stack One-shot bootstrap_server.sh spins up nginx + PHP-FPM + MariaDB + Redis under supervisor.

๐Ÿ“ธ Screenshots

TVUbuntu main UI: Ubuntu started, SSH info displayed
Main UI โ€” Ubuntu is running and SSH connection details are shown right on the TV.

TVUbuntu settings UI: Ubuntu version and architecture selection
Settings โ€” choose Ubuntu version, CPU architecture, and enable boot auto-start.


๐Ÿงฑ Tech Stack

Layer Choice
Language Kotlin
Build Gradle 8.5 + Android Gradle Plugin 8.2.2
Min / Target SDK 21 (Android 5.0) / 34 (Android 14)
UI Material Components + TV-adapted layouts (ViewBinding)
Concurrency Kotlin Coroutines
Runtime model Root chroot of ubuntu-base (no systemd inside)
Service mgmt supervisor (inside Ubuntu) for the web stack

๐Ÿ“‚ Directory Structure

TVUbuntu/
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ build.gradle.kts                 # App module: minSdk 21, version 1.2.2
โ”‚   โ”œโ”€โ”€ proguard-rules.pro
โ”‚   โ””โ”€โ”€ src/main/
โ”‚       โ”œโ”€โ”€ AndroidManifest.xml          # TV Leanback launcher + boot receiver
โ”‚       โ”œโ”€โ”€ assets/
โ”‚       โ”‚   โ”œโ”€โ”€ start.sh                 # chroot bootstrap: mount, install SSH, run
โ”‚       โ”‚   โ””โ”€โ”€ stop.sh                  # teardown: kill sshd, unmount
โ”‚       โ”œโ”€โ”€ java/com/ubuntucontroller/
โ”‚       โ”‚   โ”œโ”€โ”€ MainActivity.kt          # TV UI: status, start/stop, SSH card
โ”‚       โ”‚   โ”œโ”€โ”€ SettingsActivity.kt      # scripts / SSH / version / arch config
โ”‚       โ”‚   โ”œโ”€โ”€ UbuntuService.kt         # core logic: rootfs, arch, status, SSH info
โ”‚       โ”‚   โ”œโ”€โ”€ ShellExecutor.kt         # root shell executor (su auto-detect)
โ”‚       โ”‚   โ”œโ”€โ”€ BootReceiver.kt          # auto-launch on device boot
โ”‚       โ”‚   โ””โ”€โ”€ TvFocusUtils.kt          # D-Pad focus helpers (TV cursor)
โ”‚       โ””โ”€โ”€ res/                         # layouts, drawables, strings, colors, themes
โ”œโ”€โ”€ bootstrap_server.sh                  # ๐Ÿš€ production LEMP-ish stack in one shot
โ”œโ”€โ”€ build.gradle.kts                     # root project
โ”œโ”€โ”€ settings.gradle.kts
โ”œโ”€โ”€ gradle.properties
โ”œโ”€โ”€ gradlew / gradlew.bat                # Gradle wrapper scripts
โ””โ”€โ”€ AGENTS.md                            # project notes for AI agents

โš™๏ธ How It Works

App (Kotlin, root)
   โ”‚  deployAssets()  โ†’ push start.sh / stop.sh to /data/local/ubuntu
   โ”‚  ensureRootfs()  โ†’ download ubuntu-base-<ver>-<arch>.tar.gz, gzip-decode on device
   โ–ผ
start.sh  (run as root)
   โ”œโ”€ mount proc/sys/dev/pts into rootfs
   โ”œโ”€ fix toybox-tar symlinks / hardlinks / setuid bits
   โ”œโ”€ chroot smoke-test (/bin/bash really runs)
   โ”œโ”€ chroot โ†’ apt install openssh-server (+ curl/git/nano/sudo โ€ฆ)
   โ”œโ”€ init root password once, enable PermitRootLogin + PasswordAuthentication
   โ””โ”€ chroot โ†’ /usr/sbin/sshd -D -p <port>   (+ three-layer boot: /etc/rc.local โ†’ supervisord โ†’ /etc/init.d/*)
   โ–ผ
MainActivity shows:  SSH host (device IP) ยท user ยท password ยท port
   โ–ผ
You:  ssh root@<device-ip>   โ†’ a real Ubuntu shell ๐ŸŽ‰

Engineering highlights (the tricky bits we solved):

  • Architecture detection that isn't fooled (fixed in 1.2.1). Emulators like MuMu fake uname -m as aarch64 while the real kernel is x86_64; TVUbuntu corrects to amd64 only when the true arch is x86_64 yet uname lies. Genuine arm64 / armhf / x86 boxes keep their true arch, so Python/pip inside the chroot resolve the correct platform. Manual override remains available.
  • Three-layer service auto-start (new in 1.2.2). On every boot run_ubuntu.sh launches services in order: (1) your custom /etc/rc.local, (2) supervisord if installed, (3) a generic /etc/init.d/* sweep that auto-discovers and starts any service with an init script โ€” so anything you install (nginx, MySQL, Redis, Baotaโ€ฆ) comes up on reboot without editing anything. Dangerous shutdown/mount scripts are skipped for safety.
  • toybox tar symlink repair. Many boxes ship a tar that drops symlinks/hardlinks/setuid bits. We rebuild them from the tarball listing so /bin/bash and /lib/ld-linux resolve correctly.
  • App-side gzip decode. The box tar often can't handle -z; the App decodes gzip in Java and passes a plain .tar to tar -xf.
  • Live progress over a pipe. start.sh emits UC_PROGRESS|<pct>|<msg> lines that the App renders as a real progress bar.
  • Safe stop fallback. If stop.sh is missing, the App force-stops via pkill + umount.

๐Ÿ“ฅ Installation

Option A โ€” Sideload the APK (easiest)

  1. The box must be rooted (Magisk / SuperSU / AOSP su).
  2. Enable Settings โ†’ Security โ†’ Unknown sources (or the equivalent on your firmware).
  3. Install:
    adb install TVUbuntu.apk
    # or copy the APK to the box and open it from a file manager
  4. Open Ubuntu ๆŽงๅˆถๅ™จ from the TV launcher. Grant root when prompted.

๐Ÿ’ก Grab the latest TVUbuntu.apk from the Releases page.

Option B โ€” Build from source

git clone https://github.com/jiyanlin7113-rgb/TVUbuntu.git
cd TVUbuntu
# Open in Android Studio (recommended), or:
gradle wrapper            # regenerate the Gradle wrapper if needed
./gradlew assembleRelease # โ†’ app/build/outputs/apk/release/app-release.apk

โš ๏ธ The repo ships without the Gradle wrapper JAR (binary, not text-committable here). The release APK is prebuilt, or use Android Studio which supplies its own Gradle.


๐Ÿ•น๏ธ Usage

  1. Launch the app on the TV. It detects root and shows the current status.
  2. Press ๅฏๅŠจ Ubuntu (Start). First launch downloads the rootfs (~28 MB) and installs OpenSSH (~40 MB of packages) โ€” this can take a few minutes. Subsequent starts are instant.
  3. When status turns green, the SSH card shows:
    • Host โ€” the box's LAN IP (WiFi preferred, eth0 fallback)
    • User โ€” root
    • Password โ€” default Aa123456 (change it in Settings)
    • Port โ€” 22 (configurable)
  4. From your computer:
    ssh root@192.168.1.x      # password: Aa123456
  5. To stop: press ๅœๆญข Ubuntu (Stop).

โš™๏ธ Settings

Open ้…็ฝฎ (Settings) on the main screen:

Setting Meaning
Ubuntu ็‰ˆๆœฌ 22.04 / 24.04 / 26.04
CPU ๆžถๆž„ auto / amd64 / arm64 / armhf (override auto-detection)
ๅฏๅŠจ/ๅœๆญข่„šๆœฌ่ทฏๅพ„ default /data/local/ubuntu/start.sh & stop.sh
SSH ็ซฏๅฃ / ็”จๆˆทๅ / ๅฏ†็  connection credentials
ๅผ€ๆœบ่‡ชๅŠจๅฏๅŠจ boot the box straight into Ubuntu

๐Ÿš€ Production Web Stack (optional)

Inside the running Ubuntu, drop in bootstrap_server.sh and run it to stand up a full web stack managed by supervisor (no systemd in chroot):

# from your SSH session inside the box:
bash /root/bootstrap_server.sh

It installs & supervises: nginx (80) ยท PHP-FPM ยท MariaDB (3306) ยท Redis (6379), plus common dev tools. Idempotent โ€” safe to re-run.

supervisorctl status            # see all services
supervisorctl restart nginx     # restart one
mysql -u root                   # MariaDB (unix_socket auth)

๐Ÿ› ๏ธ Troubleshooting

Symptom Fix
"Root ๆœชๆŽˆๆƒ" Grant root to the app in Magisk/SuperSU.
Download fails Confirm the box has internet; the App fetches from cdimage.ubuntu.com.
SSH not ready after start Tap ๅคๅˆถๆ—ฅๅฟ— (Copy Log) and inspect /data/local/ubuntu/ubuntu.log.
chroot smoke-test fails Usually SELinux; the script already tries setenforce 0 + chcon. Check the log.
Emulator shows wrong arch Set CPU ๆžถๆž„ = amd64 in Settings.

๐Ÿ“ Changelog

v1.2.2

  • Three-layer service auto-start. run_ubuntu.sh now runs services in order on every boot: /etc/rc.local (your custom commands, kept for backward compatibility) โ†’ supervisord (if installed) โ†’ a generic /etc/init.d/* sweep that auto-discovers and starts any service exposing an init script. New services boot automatically on reboot with zero config changes; dangerous system scripts (halt/reboot/mount/โ€ฆ) are skipped for safety.

v1.2.1

  • Fixed real-environment architecture detection. rootfsArch() now treats uname -m as the baseline and overrides to amd64 only when the true arch is x86_64 but uname was spoofed (e.g. MuMu emulator masking itself as aarch64). Genuine arm64 / armhf / x86 devices keep their true architecture, so Python/pip inside the chroot read the correct value.

๐Ÿ“œ License

MIT ยฉ 2026 ๅ‰ๅคงๅคงไพ  / jiyanlin7113-rgb. Free for personal and commercial use. Note: running a chroot requires root and is at your own risk โ€” it may void warranties and can brick misconfigured devices.


โ˜• Like it?

If TVUbuntu gave your old TV box a new life, โญ star the repo and share it! Pull requests and issue reports are very welcome. ๐Ÿง

About

๐Ÿ“บ๐Ÿง Run a real Ubuntu (22.04/24.04/26.04) on your Android TV box via native chroot. Kotlin Android TV app with auto OpenSSH, TV-remote UI, multi-arch & multi-version support, plus a one-shot LEMP stack bootstrap.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages