Run Debian On Android
The easiest option is to install DebKit on your phone and go through the steps. However, I had to fix a bunch of things in the script to get it to work on my phone. For starters, it creates a a disk container in external storage, but its mount
command fails and it ends up installing everything in internal storage (which doesn't have enough free space in my case).
Before you proceed, give DebKit a go and if it doesn't work, check back here.
Prerequisites
1. Rooted phone with Android 4.1+
- Note: Only tested with Android 4.4 and 6
2. Busybox installed
3. microSD card with
- At least 700MB capacity
- ext4 or ext2 formatted partition
Creating an ext2/ext4 partition
- Check for kernel support for ext2/ext4 filesystem using
cat /proc/filesystems
Check for ext4 or ext2. - Create two partitions —
First partition will host your SD card files, so use fat32 filesystem (or check what it had earlier before formatting and use the same)
Second partition should be either ext2 or ext4 formatted based on kernel support. Usually ext4 works fine.- If you can access your microSD card with a card reader on your laptop, you can use GParted
- If not, use AParted on your Android phone
- If you can access your microSD card with a card reader on your laptop, you can use GParted
Mounting the ext2/ext4 partition at boot
You can either use the Link2SD app to automatically mount the new partition at boot time
-OR-
Add a script to /etc/init.d. Mounting of SD card partitions are managed by the vold daemon.
Find the vold device for your sdcard with —
mount | grep vold
You should see an entry for your fat32
partition:
/dev/block/vold/179:65 /mnt/media_rw/external_SD vfat ...
Note that 179
and 65
are "major" and "minor" versions that together uniquely identify the partition.
The second partition probably isn't automatically mounted. Enlist all the partitions detected by the kernel:
cat /proc/partitions
You should spot two entries for your partitions:
179 65 30552064 mmcblk1p1
179 66 613376 mmcblk1p2
<-- Replace [mmcblk1p2]
You can tell that 179:66
is the block device for your ext2/ext4 partition by checking the size.
Do a test mount —
mkdir -p /data/sdext2
mount -t ext4 -o rw /dev/block/mmcblk1p2 /data/sdext2
ls -la /data/sdext2
If all looks well, unmount the partition —
umount /data/sdext2
To mount at boot, create a file named 11link2sd
and place in /etc/init.d
(replace mmcblk1p2
) —
#!/system/bin/sh
set +e
mkdir -p /data/sdext2
mount -t ext4 -o rw /dev/block/mmcblk1p2 /data/sdext2 # REPLACE mmcblk1p2
Install Debian 8 (jessie) chroot
- adb shell and su into your device
- Ensure your ext2/ext4 partition is mounted at boot
Restart your phone and check /data/sdext2 - Find a Debian mirror for your location and set DEBIAN_MIRROR env var below
- Download the install script (adapted from DebKit). View Source
cd /data/sdext2 && cd $_ curl -k -o debkit.sh 'https://gist.githubusercontent.com/shirish87/7333dc74b1c491a382c920cb2515e278/raw/d9797e59ab8e16f5353af992fe6f9a5cc09d009a/debkit.sh' chmod +x debkit.sh export DEBIAN_MIRROR=http://debianmirror.nkn.in/debian ./debkit.sh install
- Once installation is completed successfully
i.e. you DO NOT see the command abruptly exit with "1|root@..."
The debkit command should be available on your shell (installed to /system/xbin/debkit).
To start a chroot session —
debkit chroot
- Your external storage is available at /storage
- Configure your timezone
dpkg-reconfigure tzdata
- Install something in Debian!
apt-get update apt-get install htop
openssh-server is preinstalled in this environment. You may start/stop services such as ssh with debkit start-services and debkit stop-services
To unmount stuff (devices, partitions, storage) used from native env run this after exiting the chroot —
debkit umount
There's so much more to explain. More notes on this coming up. For now, use the source, Luke.
There's a LOT more you can do including —
- Run (almost) anything that was ever built for Debian 8 (ARM hard-float arch)
- Set up aria2c and qbittorrent with remote HTTP interfaces enabled...for
downloading Linux ISOs, of course - Install Plex Media Server or Kodi and make it your DLNA server
- Compile and run Go programs!
- Set up gdrive for syncing Google Drive files
- If you are in the business of writing native code for the Android platform, this gives you a devenv consistent with all the GNU/Linux tools BDFL RMS cares about
Out of time for now.