Debian on Android
a guide by FuyuKitsune
This is guide about putting Debian on an Android phone. Most of the info I got from this old tutorial
this slightly newer one
dead link but I tweaked the procedure a bit so that it would work from a partition and run on Android 2.2. This will run a bootstrapped Debian in a chroot environment within Android. Debian and Android will be run side-by-side. Rather than a loopback filesystem like most guide have, this guide uses a partition on the phone's SD card because that runs faster and is more accessible than a loopback filesystem.
1) stuff you need
2) initial installation
4) useful stuff
Stuff you need
What you need:
-rooted Android device
-a ROM with Busybox and support for whatever filesystem you want
-Linux with the android SDK installed
-a partition on the SD card for Linux
What I used:
-HTC Dream (G1)
-Debian in a VM
-an 8GB microSD card formatted with a FAT32 partition (for Android apps and junk) and an ext3 partition for LinuxInitial Installation
This whole setup works by preparing an installable Debian for the phone. Debootstrap makes a tiny base system that will install itself when run.
Get on Linux and install debootstrap
apt-get install debootstrap
Prepare the first part of your bootstrapped Debian
debootstrap --arch armel --foreign squeeze debian --verbose http://ftp.us.debian.org/debian
"--arch armel" sets the CPU architecture to armel
"--foreign" tells debootstrap not to start/configure (we can't configure because we're on a different CPU architecture)
"squeeze" is the current version of Debian
"debian" is the download/unpacking path. Make this directory whatever you want
"--verbose" is because we are badass
" is our distro mirror
Copy the install directory that was created ("debian" for me) onto the partition of your SD card. This partition is sd-ext. Check the notes at the bottom for sd-ext auto-mounting.
I have my sd-ext partition with a "debian" directory and a "scripts" directory for a little bit of organization.Configuration
At this point you no longer need a computer although I prefer a real keyboard. If you're running from a VM then feel free to go back to your native OS.
Now jump into Android. Either get on a terminal emulator app or use the "adb shell" command from your computer (assuming you have USB debugging enabled). If you're running from a terminal emulator then go into su before using these commands. sd-ext mounts with permissions that prevent non-root apps.
busybox chroot /sd-ext/debian /bin/bash
This puts us in Debian and gives us a nice bash shell. If you try to use Linux you'll notice that NOTHING works. Well that's because it's bootstrapped, there is almost nothing running at all, no environmental variables either. Let's fix that now.
Paths need to be set, and so do some other variables that a bootstrapped Debian doesn't seem to set.
Type them in this time, we can make them autostart later.
Now for some required mounts
mount -t devpts devpts /dev/pts
mount -t proc proc /proc
mount -t sysfs sysfs /sys
These will also be set to autostart later.
Finalize the bootstrapped installation (get some snacks, this takes a long time)
Set up the DNS servers and add localhost to the host file
echo "nameserver 126.96.36.199" > $mnt/etc/resolv.conf
echo "nameserver 188.8.131.52" >> $mnt/etc/resolv.conf
echo "nameserver 184.108.40.206" >> $mnt/etc/resolv.conf
echo "127.0.0.1 localhost" > $mnt/etc/hosts
And don't forget to set your root password
Don't do any apt upgrades yet, graphical installers don't display properly over adb shell and text is too small to read on terminal apps. Install SSH and get out of this debugging shell / terminal emulator.
apt-get install openssh-server
KABOOM! Your phone just crashed, didn't it? Mine did. The newest versions of OpenSSH have IPv6 enabled by default and Android just can't handle that. Wait for you phone to boot up, chroot in, then add the following line to /etc/ssh/ssh_config and /etc/ssh/sshd_config.
Make sure to delete any other "AddressFamily" lines in the config files
Now you'll be able to start the SSH daemon
SSH into the phone for a much nicer terminal. Now you can "apt-get upgrade" to get fresh versions of all Debian's software. A few installations in the batch require input so don't leave while it's running. If apt complains about ssh not being configured simply run the command it tells you to
dpkg --configure -a
which will finish the ssh configuration that got cut off when the phone rebooted.Useful stuff
Woo, Debian on Android! Linux within almost-Linux! Time to do some cool stuff.
First things first- make a script to chroot in. Environmental variables need to be set, mounts need to be mounted, and display should be set for good measure. Put the starting script somewhere handy on your SD card, you'll need to call it from a terminal emulator app.
I like putting everything in a "chroot-start" file in Debian's /etc/init.d and then running it from the chroot command. The chroot-start file would be:
mount -t devpts devpts /dev/pts
mount -t proc proc /proc
mount -t sysfs sysfs /sys
The starting script goes somewhere on Android. I use /sd-ext/scripts/startdeb.sh (doesn't have to end in sh). If you want to run the script without writing any paths then put the script in /system/bin. Don't forget to change file permissions if you wanna call it directly, else run "sh scriptfile"
Here's my script:
busybox chroot /sd-ext/debian /etc/init.d/chroot_start
-busybox contains all our important binaries
-/sd-ext/debian is the path that I'm chrooting to
-/etc/init.d/chroot_start is the file being run once chrooted
Check the chroot man pages here, you could do a few things like chroot'ing into a different username or chroot'ing as root but using su to run a command as a different user. If you want SSH to start automatically then just add it to the chroot-start script. I'd suggest making a few set of scripts, just in case you want to start Debian without SSH or go into the chroot from the terminal app.
You won't be able to show off if you just have shell access, that's not cool enough. Install your favorite window manager or desktop environment, then get some VNC running
apt-get install lxde tightvnc-server
I use Openbox myself but LXDE doesn't require any configuration or extra tools. Remember: this is a phone, it's probably a single core running less than a GHz. We won't have Compiz on an ARM device until someone on XDA puts Linux/Android on the PS Vita
Start TightVNC, it will automatically start the default window manager
vncserver -geometry 640x480
Now simply connect to localhost from a VNC viewer app. Tada! Linux that you can show off. If you connect from a remote computer then you still have the SSH available to tunnel through.
If you want feel even cooler at the risk of people asking "why the hell would you do that?" then do some X11 forwarding over SSH. This G1 is as slow as molasses so the only thing I can get forwarded is xclock.Notes
-I get sd-ext auto-mounting from FireRat's all-in-one script. If you want sd-ext auto-mounting without using FireRat's script, just save this script
as "05mountsd" and put it in Android's /system/etc/init.d/
-you could grab OpenSSH config files from a different computer and put them in instead of letting OpenSSH config itself and crash. I didn't have anything with OpenSSH handy so I edited the files on the phone.
-no, it doesn't have monitor mode
It has promiscuous but not monitor. I'm still screwing around with wifi drivers. Some other phones can go into monitor mode or have drivers available. Google around for that.
-a custom ROM isn't necessary if you have busybox and filesystem kernel modules but using a custom ROM (like CyanogenMod) is a lot easier than finding/making busybox and kernel modules
-there are ways to use unionfs to merge Debian and Android. You would be able to run Debian commands from Android's terminal (after the initial chroot) without going into ssh/chroot. I haven't tried any of it yet. Saurik (the guy who did Debian on the G1) uses unionfs but his is compiled for an older Android firmware. I don't know if unionfs or aufs is in the current CyanogenMod but the same technique may work using bind. I'll post if I get that working.
I did all of this once, although very out of order. I'm going to do it all over just to make sure it works the way I wrote it once I get this Debian VM up again.
Feedback is appreciated. There are probably a few ways to improve the way Debian is set up. Please tell me if I made any spelling or grammar mistakes, I'm kinda picky about that in guides.edit 1:
forgot to add title and credsedit 2:
fixed a few little bits