Friday, June 19, 2015

Putting Linux on your Android device using debootstrap and chroot

Are you ready for this? lol

Ok, so first thing first. You will need a few things done BEFORE you attempt this tutorial:

  1. A rooted android device of sorts with debugging enabled and busybox installed
  2. An sdcard to store the debian image on
  3. A Linux machine (or live cd) to prepare the debian system image
  4. ADB for remounting the system partition and pushing startup scripts
  5. A terminal application installed on your droid
  6. and about an hour of free time
Lets get right into it

open up a terminal, and make a directory that you will be storing all of the files and things we create for easy cleanup later. I called mine linux_on_android. change to that directory, all instructions from here on out will be relative to whatever directory you are currently residing in after this step.

Next, we create an empty raw disk image, make a directory to mount it under, create a filesystem on the image, and mount it under our new mount point.
Now lets change into our mnt directory, install debootstrap, and use it to install a base system into our mounted image for the architecture of our android device, in this case it is i386, in most cases this will actually be armhf especially if this is being done on a phone.

Once this has finished, we now need to push the debian system image to the sdcard, go get some coffee lol, or mount your sdcard and transfer it using the file manager, this just makes it easier for me, because I was doing this to a VM lol.
Now that we have that bit done, we move onto the fun bits. lets start adb shell, setup a chroot environment, and chroot into our new debian image :D

the long haul is almost done :D make sure you are somehow connected to the internet on your device, and lets install some packages.
Update package lists
install ssh server
build utilities and nmap

The following are an example startup, and shutdown script for debian. start_debian:

Now you can open up your terminal, and start and stop debian at will. to log into your new debian image, connect using your ssh client of choice, I kinda like connectbot, so that is what i will use in the screenshots: