Installing Debian GNU/Linux in a chroot on a Samsung Galaxy S II

(Last updated 2011-11-25)

There are numerous how-tos on the web for installing a Debian chroot onto a smartphone running Android, but most of them either give you an image to install on your phone (which doesn't teach you anything) or have you set up the Debian system on your desktop and copy it to the phone. Neither of these options appeal to me, so I've done it my own way and written this document to light the way for others, too.

Assumptions made:

If not all of these assumptions are true, please don't contact me if something doesn't go right for you when following this how-to.

Preparation

The first thing you need to do is install cdebootstrap on your phone. cdebootstrap is a tool for bootstrapping a Debian system, usually from another Debian system, but in this case we'll be doing it from Android.

So, to install cdebootstrap:

Bootstrapping the Debian system

Now that you have a working cdebootstrap on your phone, you can use it to bootstrap Debian. First, however, you will need to create a file system for Debian to live on. It may be possible to create such a file system directly on the SD card, but as I don't really understand Android partitioning, I decided not to try this and risk losing data. (If someone knows of a way to do this, please contact me and let me know!) The reason you need a separate file system for Debian is that Android mounts its own file systems with options like noexec, which would disallow executing all binaries placed on them (thus defeating the purpose of an operating system).

The easiest way to set up a file system is to simply create a file in /mnt/sdcard and format that -- but beware, if you make this file larger than 2 GiB, the FAT file system it lives on will complain and you will lose the image next time you reboot. This happened to me the first time I tried it, and I hadn't made a backup, so I had to do it all over again. :(

So, ssh to your phone, and run the following commands:

# dd if=/dev/zero of=/mnt/sdcard/debian.img bs=1024 count=2000000 # mke2fs -Fj /mnt/sdcard/debian.img # mkdir /debian # mount -t ext3 -o noatime,errors=remount-ro /mnt/sdcard/debian.img /debian