Author Topic: Debian on Android  (Read 19709 times)

0 Members and 4 Guests are viewing this topic.

Offline FuyuKitsune

  • Knight
  • **
  • Posts: 297
  • Cookies: 21
    • View Profile
Debian on Android
« on: April 10, 2011, 05:19:43 am »
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 and 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
3) configuration
4) useful stuff
5) notes


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)
-CyanogenMod 6.1
-Debian in a VM
-an 8GB microSD card formatted with a FAT32 partition (for Android apps and junk) and an ext3 partition for Linux



Initial 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
Code: [Select]
apt-get install debootstrap
Prepare the first part of your bootstrapped Debian
Code: [Select]
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
"http://ftp.us.debian.org/debian" 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.

Code: [Select]
busybox chroot /sd-ext/debian /bin/bashThis 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.
Code: [Select]
export PATH=/usr/bin:/usr/sbin:/bin:$PATH
export TERM=linux
export HOME=/root
export USER=root
Type them in this time, we can make them autostart later.

Now for some required mounts
Code: [Select]
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)
Code: [Select]
/debootstrap/debootstrap --second-stage
Set up the DNS servers and add localhost to the host file
Code: [Select]
echo "nameserver 4.2.2.2" > $mnt/etc/resolv.conf
echo "nameserver 8.8.8.8" >> $mnt/etc/resolv.conf
echo "nameserver 8.8.4.4" >> $mnt/etc/resolv.conf
echo "127.0.0.1 localhost" > $mnt/etc/hosts

And don't forget to set your root password
Code: [Select]
passwd root

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.
Code: [Select]
apt-get update
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.
Quote
AddressFamily inet
Make sure to delete any other "AddressFamily" lines in the config files

Now you'll be able to start the SSH daemon
Code: [Select]
/etc/init.d/ssh startSSH 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
Code: [Select]
dpkg --configure -awhich 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:
Code: [Select]
export PATH=/usr/bin:/usr/sbin:/bin:$PATH
export TERM=linux
export HOME=/root
export USER=root
export DISPLAY=:0.0
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:
Code: [Select]
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
Code: [Select]
apt-get install lxde tightvnc-serverI 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
Code: [Select]
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 creds
edit 2: fixed a few little bits
« Last Edit: October 24, 2011, 02:32:40 pm by FuyuKitsune »

Online DeepCopy

  • VIP
  • Legend
  • *
  • Posts: 1766
  • Cookies: 115
  • Gender: Male
  • Le Olde Fag
    • View Profile
    • EvilZone
Try to imagine life without time. You probably can't. You worry about time, get driven by time. However look all around you, a bird does not worry if he will be late for a meeting, a deer does not fret over passing birthdays. Only man tracks time. This makes man the only creature to fear running out of time.

Offline eighthave

  • NULL
  • Posts: 1
  • Cookies: 0
    • View Profile
Re: Debian on Android
« Reply #2 on: May 16, 2012, 06:21:02 pm »
If you want an app to actually build and run the whole install on your phone using official Debian repos, check out Lil' Debi.  Its a Debian debootstrap chroot builder and manager:

https://github.com/guardianproject/lildebi

It is a completely open source app, everything used by the app is built from source that is included in the app, except for one optional util: gpgv.  That you can build yourself using https://github.com/guardianproject/gnupg-for-android


Online techb

  • Evilzone Love Spreader
  • Global Moderator
  • King
  • *
  • Posts: 2017
  • Cookies: 256
  • Gender: Male
  • Aliens do in fact wear hats.
    • View Profile
    • Tech B. Blog
Re: Debian on Android
« Reply #3 on: May 16, 2012, 09:45:21 pm »
I have a rooted android 2.1, with a stock ROM not CyanogenMod. I have verified root in the terminal via "su". Will it still work?

Online Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 5148
  • Cookies: 405
  • Gender: Male
  • Motherflipper
    • View Profile
    • My blog
Re: Debian on Android
« Reply #4 on: May 16, 2012, 10:29:32 pm »
Why would one need an actual OS running on android-capable phone? I just don't get it, you would only get the command line at best, so no multitasking. I suppose installing busybox on rooted android is kinda the same as having debian on your phone.

Online DeepCopy

  • VIP
  • Legend
  • *
  • Posts: 1766
  • Cookies: 115
  • Gender: Male
  • Le Olde Fag
    • View Profile
    • EvilZone
Re: Debian on Android
« Reply #5 on: May 16, 2012, 11:06:12 pm »
Why would one need an actual OS running on android-capable phone? I just don't get it, you would only get the command line at best, so no multitasking. I suppose installing busybox on rooted android is kinda the same as having debian on your phone.

Not really... This is just a chrooted environment which is cool. I'd rather get it Natively on my Iconia which is possible I just haven't figured out how to do it yet lol. (http://evilzone.org/android/(wip)hacking-with-a-acer-iconia-a500/)
Try to imagine life without time. You probably can't. You worry about time, get driven by time. However look all around you, a bird does not worry if he will be late for a meeting, a deer does not fret over passing birthdays. Only man tracks time. This makes man the only creature to fear running out of time.

Offline FuyuKitsune

  • Knight
  • **
  • Posts: 297
  • Cookies: 21
    • View Profile
Re: Debian on Android
« Reply #6 on: July 11, 2012, 06:56:09 am »
Why would one need an actual OS running on android-capable phone? I just don't get it, you would only get the command line at best, so no multitasking. I suppose installing busybox on rooted android is kinda the same as having debian on your phone.
So you can have Linux tools and cool stuff like an N900 or whatever people think of when they hear "Linux phone". I love having apt on there. I just got monitor-mode working on my G1 through Debian also so it's really kickass now.

 



Intern0t SoldierX SecurityOverride programisiai
Want to be here? Contact Ande, Bluechill or Kulverstukas on the forum or at IRC.