Debian Packages on Android Phones

Sunday, October 17, 2010

Well, almost. While one could theoretically install Debian packages on Android phones, it is generally a bad idea to install software designed for one system onto a different system. However, the Debian package manager is excellent for keeping track of software, and it would be nice if it could be used on Android as well. iPhone users already have access to this mechanism in the form of Cydia, so why not put it on Android too?

For user applications, we already have APK’s.

These are self-contained blocks that may be easily installed and removed. The APK system is great for running untrusted software that needs to be sandboxed, but it is not flexible or efficient enough to manage the operating system itself. Android users typically do not update their systems very often, and when they do so, they update the whole setup at once. This presents two problems: firstly, users don’t receive updated software as it becomes available and secondly, each update is a resource-intensive and time-consuming task. It would be great if system software could be updated piecemeal, just like a real Linux setup.

The Debian packaging system solves this problem very well, but its size makes it unsuitable for mobile devices. Nevermind that Cydia users use Debian packages — it’s still good to be frugal. Since we’re not going to install Debian software onto our phones (which would probably break many things), we don’t have to stick strictly to the Debian format; on the other hand, Debian provides a very nice model for us to emulate.

Enter Opkg.

Here is a package manager and format that very closely resemble the Debian package manager and format. In fact, Opkg is capable of working with Debian packages. The difference is that it’s tiny and it’s designed for mobile devices.

For starters, I have compiled a statically-linked build of Opkg. It is able to install local (and http-hosted) packages as dpkg does. It can also maintain a list of software sourcesĀ a la apt-get. Its small size (745KB) makes it easily-integrable into almost any Android system.

If you’re feeling adventurous and would like to try this on your rooted Android phone, the files are currently hosted on my Dropbox account. You do need root access, so if you use a cooked ROM such as CyanogenMod, you should be good to go. Please keep in mind that there is only one package at the moment (the example), but it’s not difficult to make more.

19 Comments

  1. Ulti says:

    lol using dropbox as a webhost. It’s great lol.
    Also good job, and I want an android.

  2. Jiang says:

    Dropbox is great, but I’ll probably need something more when I set up my repository.

  3. Nore says:

    I’m receiving the following when trying to install opkg.bin:

    “tar: can’t create symlink from system/bin/opkg to /system/bin/opkg-cl: cannot allocate memory”

    what could be the reason ?

  4. Jiang says:

    Nore, did it output anything else? Also, did you do `adb shell sh /sdcard/opkg.bin` or did you do `adb shell` first and then `sh /sdcard/opkg.bin`, or did you do it directly on the phone using some terminal app? My preferred method is `adb shell` then `sh /sdcard/opkg.bin`, because the first method hangs the installer and the third might use a bit more memory and result in this error.

    Alternatively:

    1. put http://dl.dropbox.com/u/1213413/android-opkg/opkg-cl on your sd card
    2. run, on your phone as root,

      mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system
      mv /sdcard/opkg-cl /system/bin/
      ln -s /system/bin/opkg-cl /system/bin/opkg
      mkdir -p /cache/usr/lib/opkg
      mkdir -p /cache/usr/tmp
      mkdir -p /cache/etc/opkg

    It’s okay if the ln -s step fails — this just means you need to call opkg-cl instead of opkg.

    Also, I have added some more information to the download page, but this should get you going for now. If you want to try the automatic installer again, please use the new opkg.basic.bin file. Thanks for testing!

  5. Nore says:

    Hello,
    Thanks for the reply, and sorry for the delay
    this is the result after trying your latest bin file,
    http://77.42.157.134/~nore/snapshot.png

    I haven’t tried the manual method yet.

  6. Jiang says:

    No, thank you for helping me debug this thing. Would you mind telling me what “distro” of Android you’re using (i.e. who cooked your ROM) and what device you’re using?

    It just looks like you’re running out of memory, but that’s interesting because it looks like you’re running on a better phone than I am. At any rate, doing this using ADB or going manual should use less memory.

  7. unclear says:

    ok I’m confused.

    From what I read: opkg is a container that allows installation of system binaries,libraries,settings directly.

    correct?

  8. Jiang says:

    This is correct. An Opkg package is basically an archive of files that should be unpacked into the system, plus some additional information about what to do before/after installation/removal, and information about how it’s related to other packages.

  9. Nore says:

    This was on my HTC Desire running LeeDroid 2.2a, so plenty of RAM I got there… :)

  10. Nore says:

    I just tried it on the OpenDesire 4.0.36 ROM, and the issue is still the same.

    1. Jiang says:

      It -may- have something to do with an incompatible version of sh, tar, or wget. I just uploaded a version that does not create a symlink (instead, it includes a shell script of the same name), which might help…

  11. 8ut8f8rder says:

    Hi, great idea with opkg…

    I have a HTC Tattoo here thats waiting for his first real package manager.

    …but could you give me some intel, how you compiled opkg from source for your device? Dont like this ready steady binarys from the internetz. :-)

  12. Jiang says:

    That’s not too hard, 8ut8f8rder. Pull the latest revision off SVN and it should build cleanly. The problem is static linking — I do not rely on the original Makefile for this, and I have an extra step to make sure I get everything linked. For example, the following gives me the opkg-basic build:

    LDFLAGS=-static ./autogen.sh --enable-sha256=no --enable-openssl=no --enable-ssl-curl=no --enable-gpg=no --enable-curl=no --with-opkglibdir=/cache/usr/lib --with-opkgetcdir=/cache/etc && make clean && make
    gcc -Ilibopkg -g -O2 -static -o opkg-cl src/opkg-cl.o libopkg/.libs/libopkg.a libbb/.libs/libbb.a

    Yes, it’s quick & dirty; but it works. Of course, depending on your build options, you may have to specify other libraries to be linked. :)

    If you were wondering how to set up a build environment — I decided to use a debootstrap’d armel Debian chroot with qemu-arm-static instead of a cross-compiler because it made more sense for me. Alternatively, you could just run the armel chroot directly on your phone, but it might take a bit longer to build things.

  13. 8ut8f8rder says:

    Finally I compiled opkg :-) Thanks for your help. But I run in the same error like Nore. The problem is /dev/mdt/mtdblock3 runs out of free memory. But I found a bunch of apk and odex files in /system/app. Google means they are there because of autokiller – what ever that is. I think a quick solution would be, to move these files over to a new folder in /data and create some symlinks to /system/app. I post again if I found a workaround for this problem, and could test opkg.

  14. 8ut8f8rder says:

    I found a solution, the files in /system/app and /system/framework should be deodexed. That gives some extra space. Sorry, Im realy new to this android stuff, and have a lot to learn. :-)

  15. 8ut8f8rder says:

    Ok, that was a nice try, but not the reason. Its a nand lock thats restricts writing to /system. In my case I have to load a kernel modul called tattoo-hack.ko

  16. Jiang says:

    Thanks for posting your progress, 8ut8f8rder. The NAND lock does sound like a pretty annoying stumbling block. If it works for you now, I suppose we can move onto more fun things, such as making packages and repositories :D

    (Oh, and if anyone has a pressing desire to chat about this stuff, there’s always #inportb on freenode.)

  17. Quan Siji says:

    Hey, great idea about opkg ~~

    I’m working with Android-x86 and trying to use opkg on Android-x86 with VirtualBox, but I’ve got to specify tmp-dir every time using
    opkg -t TEMPDIR install xxx
    I’ve tried to add “–with-opkgtmpdir=TEMPDIR” while configuring, but it does not work. May I know how do you specify tmp-dir while configuring? Thank you.

  18. Jiang says:

    Yeah… there’s no option for that, but there are two ways around it:

    • set tmp_dir in the config file while deploying
    • set OPKG_CONF_DEFAULT_TMP_DIR_BASE in libopkg/opkg_conf.h while compiling

    The first method is apparently the “right” way to go, but the second way works if you want to hardcode the default (makes sense to me).
    I’ve also resurrected the wiki page if you need more information.