
Well, Android came out and even the source code was posted. And we got the first Android-powered device. What we really didn’t have was the change of game in which we would suddenly get control of our phones. You remember what Google promised us last year.
The reality is that even Google cannot influence the world of mobile devices. Those who have already received their G1 and managed to play with it for some time were upset by the fact that we are still just ordinary users on our phone: T-Mobile did not allow us to use the root user, fearing how we would do something .
If you want to try this instruction in action, consider that everything you do, you do at your own peril and risk.
Getting super user permissions (root) / JailbreakingFor me, restrictions of this kind turn the device into nothing more than a toy: those who watched my adventures in the iPhone world know that I consider it a shame to wear a phone with a high-speed ARM processor running a modern operating system, a large screen with numerous ways control / input, just to use it as a regular cell phone.
')
Fortunately, this changed a few days ago, when someone found a serious vulnerability in the Android firmware. You could get privileged rights. Just typing telnetd in the console and connecting using the telnet client you get root.
Unfortunately, it is still difficult to do something worthwhile with the help of Google's replacement of the busybox - toolbox. What we need is a complete unix environment. This phone is powerful enough, even to develop applications directly on it.
Installing Debian ARMELThere have already been several attempts to install busybox on Android. I think that we can go further, and with the help of this instruction, install the full Debian distribution, one of the highly respected Linux distributions that allows you to install everything you want.
To do this, we need to think through several issues related to G1. First, where do we keep it? The phone has built-in flash memory, but there is only 128MB for the operating system and other applications.
Therefore, we drew attention to the more capacious part of the phone - a microSD card, which allows you to store up to 16GB of data. Unfortunately, to be able to read it by all card readers, this card has a FAT file system, which is useless for storing Unix programs and data.
But what we came up with is that we can store a Debian image on a memory card and then just mount it.
After reviewing the contents of / proc / filesystems, we can see all the types of file systems that we can use: vfat, yaffs, yaffs2. On T-Mobile, only the minimum part of the drivers for the file systems necessary for the functioning of Android is installed. This means that we need to load a driver that would allow us to mount our image, since the kernel is built with the support of the modules.
If necessary, I can write a manual, because I collect modules for G1. I encourage people who are committed to discussing G1 development / modification topics. For a discussion, you can subscribe to
the G1-Hackers mailing list that I keep on Telesphoreo.
I also support IRC on irc.saurik.com (the same server that hosts the Phone oriented channels) on the #android channel, along with several other interested people.
Creating a Debian Disk ImageSo, stop talking, let's get started! First, we will need a Debian file system image, which we will place on the phone's memory card. To create it, we can use an existing Debian system. Fortunately, Debian already has
full support for ARM EABI and even has
useful instructions on how to install.
For people who have no desire to mess with the creation of the image, I have already created a 750MB ready, you can download the
full image here (RapidShare). This image was packaged with bzip2 and takes ~ 85MB.
RapidShare is a rather slow server, so the guys from
modmyGphone.com put a mirror of the image on their servers. Details can be read
here .
If you want to create an image yourself (maybe you need a different file system size for debian other than 750MB, or just want to control the whole process), this can be done using the following commands:
apt-get install debootstrap
dd if=/dev/zero of=debian.img seek=749999999 bs=1 count=1
mke2fs -F debian.img
mkdir debian
mount -o loop debian.img debian
debootstrap --verbose --arch armel --foreign lenny debian ftp.de.debian.org/debian
umount debian
Build our tool kit (kit) for debianNow we have the image of the debian, we need to copy it to the memory card. Also there you need to copy additional files. One important point of this step is that you need to install the driver corresponding to the firmware you are using.
* ext2.ko (
RC19 ) (
RC29 / 30 ) - standard Linux file system module
* unionfs.ko (
RC19 ) (
RC29 / 30 ) - allows you to merge folders (advanced)
*
busybox - a set of system utilities
Copy this all (and debian.img) to a folder on a microSD memory card (I used a USB connection, which is simpler and faster than the others). If you downloaded the finished image, it makes sense to rename it to debian.img, so that it would be easier to use it later.
Install and mountWhere is it better for us to put it all? I copied the tool kit (kit) to the root directory of the microSD card and put everything else in / data / local (a very useful folder in which you can normally write).
We export paths in order to not be able to type constantly long paths. It also allows this instruction to look semantically much easier to read.
export kit=/sdcard/kit
export bin=/data/local/bin
export mnt=/data/local/mnt
Next you need to export a few more paths, they will need programs that we will use in the future. This will save time when loading the driver for ext2. It may look strange (at least the HOME variable), but if we don’t ask them later, major problems may arise.
export PATH=$bin:/usr/bin:/usr/sbin:/bin:$PATH
export TERM=linux
export HOME=/root
insmod $kit/ext2.ko
The next step is to copy somewhere to busybox for future use. Since G1 does not contain the cp command, we will use cat for this. Note, the mkdir command does not have the -p option (since the toolbox does not support it), so if you select a directory with a lot of nesting (or an existing one) you will have to ignore some errors or solve them differently.
mkdir $bin #-p
cat $kit/busybox >$bin/busybox
chmod 755 $bin/busybox
busybox is installed, now we can use it to create a device node for the loopback driver. We need busybox, since G1 does not contain the mknod utility, which will be needed to create the node. We will also create aliases (short names) for busybox to make it easier to type commands.
alias _=busybox
_ mknod /dev/loop0 b 7 0
If you get an error at startup: _ not found, just try resetting it:
unalias _
alias _=busybox
Finally that loopback device is created, we can plug in a debian image! Note, as the name of the debian.img image, use the name of your image if it is different.
_ mkdir -p $mnt
_ mount -o loop $kit/debian.img $mnt
There can be several major errors: if the error / etc / fstab, then apparently the $ kit / debian.img file does not exist, or the $ mnt variable may not be set.
Final installation stepAt this stage, we have to finish what debootstrap can't do. First, you need to run several scripts and fix the URLs to the Debian repositories (for some reason, debootstrap confuses them, for some unknown reason). If you have already downloaded the finished image, then you do not need to do these two commands.
_ chroot $mnt /debootstrap/debootstrap --second-stage
echo 'deb ftp.de.debian.org/debian lenny main' >$mnt/etc/apt/sources.list
After these commands are executed (it may take almost 10 minutes), we can change the environment to debian using the chroot command. We get a shell and a complete debian environment, with all the cool things that we can do. This command is performed by everyone, even those who downloaded the finished image.
_ chroot $mnt /bin/bash
Next we connect the file systems devpts, proc and sysfs to our environment.
mount -t devpts devpts /dev/pts
mount -t proc proc /proc
mount -t sysfs sysfs /sys
It is also necessary to set a password for the root user, so that we can remotely connect to the phone.
passwd root
Install OpenSSHThis is where the power of debian is shown: quick installation of new programs on the phone. Well, let's install an SSH server in order to get a full-fledged console.
For this we will use APT (package management system in Debian). The first command to update information about packages in the repositories and install updates. The second will install the actual ssh server itself.
apt-get update
apt-get install openssh-server
If you later want to start OpenSSH again (since the normal debian start is not used), you can do this with the following command (or using “restart” instead of “start”).
/etc/init.d/ssh start
What next?Have fun! The first thing I did was install subversion, gcc and vim so that I could start developing. I repeat, people who want to learn more about the insides of Android (kernel drivers, access to hardware, the process of flashing) can join the
G1-Hackers mailing list .
After you restart the phone you will need to run, if not all, then most of these commands again. For those who used the same ways as me, they can use scripts for reconnection (
script ).
It is also worth mentioning that while the image is mounted, Android will not be available via USB cable. To do this, you need to unmount all that was mounted before
_ umount $mnt/dev/pts $mnt/proc $mnt/sys $mnt
Although Android comes with a umount unmount utility, which works as if normal, but nevertheless it leaves a loopback device that will continue to block the microSD card for USB connection. You can delete it manually using the following command:
_ losetup -d /dev/loop0
Running Debian on /Most of all in this process grieves that we have to choose between android and debian. This is where unionfs comes to the rescue.
Note, all subsequent commands must be executed outside the debian environment. For this you need to dial in the current telnet session:
exit
or open another session. All commands can be downloaded as a
ready-made script .
To run this script, you must already have exported all the standard variables. If you copied the script in $ kit, then you can execute it with the following command.
. $kit/unionfs.sh
You can install this script using wget:
_ chroot $mnt wget -O /tmp/unionfs.sh cache.saurik.com/android/script/unionfs.sh
cat $mnt/tmp/unionfs.sh >$kit/unionfs.sh
rm $mnt/tmp/unionfs.sh
For those who did not use a ready-made script:
insmod $kit/unionfs.ko
mount -t unionfs -o dirs=$mnt/etc=rw:/etc=ro unionfs /etc
Now we have / etc contains files from Android and Debian. When changing / creating files in / etc, all modifications will be stored in the Debian partition - this allows us to get full access to / etc!
The next problem is that Android and Linux use different naming conventions for their dynamic linker. For Android, we have / system / bin / linker, and for Linux, we have /lib/ld-linux.so.3. This means that we get an error file not found when running running programs. This is easy to fix with symbolic links.
_ mount -o remount,rw /
_ ln -s $mnt/lib /
At first glance it may look dangerous, but it is not. When changing the phone's root file system, this will be the change in “rootfs”: a special state of Linux ramfs (file system in memory). This means that any changes that we make, after restarting the phone, will disappear.
Now we can run most Debian programs without chroot, simply by running programs from $ mnt. Unfortunately, not everything will work, since most of the files are not where they should be. Let's fix this with symbolic links.
for x in
bin boot home media mnt
opt selinux srv usr var
do
_ ln -s $mnt/$x /
done
There are still a few directories that need to be fixed. The first: / root is empty, so we can replace it with a link. Since we’ve finished changing the files to /, I strongly recommend that you reinstall the root / to read-only mode.
rmdir /root
_ ln -s $mnt/root /
_ mount -o remount,ro /
There are still two / sbin and / dev. There is no big catch with / dev. Since / dev / pts is mounted inside this folder, it cannot be merged using unionfs. To solve this problem, simply mount / dev / pts over unionfs:
mount -t unionfs -o dirs=$mnt/sbin=rw:/sbin=ro unionfs /sbin
mount -t unionfs -o dirs=$mnt/dev=rw:/dev=rw unionfs /dev
mount -t devpts devpts /dev/pts
Everything is ready for us, even for such programs as openssh to work correctly, restart the service:
/etc/init.d/ssh restart
FinallyIt all looks good, but there are still a few problems to note:
First, it is not yet clear where user names and authentication information are stored. If you look at file owners with ls, which is part of debian, you will notice that they are not there.
The second, using the symlink for /, instead of using chroot (so far it has not been possible to transparently load all services) means that any package attempting to add the directory to / will fail. To install programs via apt-get will have to use chroot.
And lastly, the RC30 update will be released soon, after which jailbreak via Telnetd will no longer work. So while not playing enough, do not install it.
(I hope I understand why the telephone companies love to sell us devices that are purposely limited in functionality. Does this improve their business?)
If you find inconsistencies or any other errors in the article, please report.
The article with the translation is also posted by
ironphone.ru