Outline
In this blog, you will know how to install Debian for an Android device with root privileges.
No Termux. No Linux Deploy. No Black Box.
Only Debian offical installer. Everything is under your control.
Prerequisites
root privileges
busybox
With Magisk installed, you can get both root privileges and busybox.
Install Debian with debootstrap
Switch to root user
Most commands should be executed with root privileges.
With adb, you can type:1
2adb shell
su
Prepare necessary commands
debootstrap
requires several basic commands to run.
1 | # The most important program is busybox, and we can use busybox binary from Magisk |
Setup debian system image path and mount point
1 | # Set the debian inst directory |
Create a img file as rootfs
1 | dd if=/dev/zero of=$DEBIMG bs=1G count=10 |
Build pkgdetail (on your pc/server)
1 | wget -O pkgdetails.c https://salsa.debian.org/installer-team/base-installer/-/raw/master/pkgdetails.c?inline=false |
Transfer pkgdetail
to Android device
Take adb as an example.1
adb push pkgdetail /sdcard
Install debootstrap
Download debootstrap
and prepare pkgdetails
for it.
Note: the dest file is pkgdetails, not pkgdetail
1 | # Download debootstrap |
Install Debian with debootstrap
1 | # Install Debian |
Configure Debian
Chroot to Debian: chroot-debian.sh
1 | BUSYBOX=/data/adb/magisk/busybox |
Fix network error inside Debian
1 | # Add network related groups required by Android kernel |
Configure DNS resolution
1 | cat >/etc/resolv.conf <<EOL |
Enjoy your Debian!
1 | apt update && apt install neovim |
Troubles
Android kernel does not support System V IPC
Applications that rely on System V IPC, such as PostgreSQL, cannot be run directly in Debian on Android.
Possible solutions: Termux emulates System V IPC.
Refer to:
- Android Doc - SYS-IPC
- Termux - libandroid-shmem
- Termux - libandroid-sysv-semaphore
- Termux - postgresql
Android kernel allows only specific groups to access the network
That’s why we add root
to some groups and modify gid of _apt
to aid_inet
Refer to:
If your application fail to run, check if it’s a network issue!
For example, mysqld run as user mysql
, and its default group is mysql
.1
mysql:x:104:104:MySQL Server,,,:/nonexistent:/bin/false
Without modifying its group to aid_inet, service start mysql
/ mysqld
would fail.
If you do not change the group of user mysql
to aid_inet
, command service start mysql
/ mysqld
will fail.
Optional Steps
Modern bashrc
1 | # ~/.bashrc: executed by bash(1) for non-login shells. |
Update apt source list
Refer to Tsinghua Mirrors - Debian
Install sysvinit-core
to run daemons
1 | apt update && apt install sysvinit-core |
Configure timezone
1 | dpkg-reconfigure tzdata |
Configure locales
1 | apt install locales |
Install and configure mariadb
Install mariadb with proper apt source1
apt install mariadb-server
You must change group of user mysql
to aid_inet
1
usermod -g aid_inet mysql
If package sysvinit-core
is installed, start mysqld with1
service mysql start
Without sysvinit-core
, you can run1
mysqld
Configure bash completion
1 | apt install bash-completion |