Friday, 2018-02-23, 3:21 AM
Welcome Guest

Sec_rity without U

Main | Debian on Android | Golden Dragon - Forum | Registration | Login | RSS
[ New messages · Members · Forum rules · Search · RSS ]
Page 1 of 11
Forum » Mobile Hacking & Phreakings » Android » Debian on Android | Golden Dragon (Debian on Android)
Debian on Android | Golden Dragon
goldendragonDate: Sunday, 2011-11-27, 11:05 AM | Message # 1
Sergeant
Group: Moderators
Messages: 23
Awards: 0
Reputation: 1
Status: Offline
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

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/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.
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 start

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
Code: [Select]

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:
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-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 wink
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.
 
Forum » Mobile Hacking & Phreakings » Android » Debian on Android | Golden Dragon (Debian on Android)
Page 1 of 11
Search: