Compiling tun.ko for Android - OpenVPN

I have a Xoom, and a Galaxy S, and need to be able to compile my own tun.ko for the kernel version I have. As you all know, if the kernel version of the module you are trying to insert isn't the same, it won't insert, and will give you errors like:

<3>[95175.874872] tun: version magic ' SMP preempt mod_unload ARMv7 ' should be ' SMP preempt mod_unload ARMv7 '

in dmesg. We need to compile the module for the right version of the kernel

  1. Download the Kernel source - normally from The Xoom can be found at, and the Galaxy S can be found at Use

    $ pwd
    $ git clone to clone the Xoom kernel source
  2. Copy your old kernel config from your device

    $ pwd
    $ adb pull /proc/config.gz
    $ gunzip config.gz
    $ mv config.gz tegra
  3. Download an ARM crosscompiler from
  4. Untar the crosscompiler, and add the binary directory to the path

    $ pwd
    $ tar -jxvf arm-2010q1-202-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
    $ export PATH=$PATH:/scratch/gnu-eabi/arm-2010q1/bin
  5. Prepare the kernel for compilation
    $ cd /scratch/xoom/tegra
    $ vi scripts/setlocalversion

       Find the following lines
           # If only the short version is requested, don't bother
           # running further git commands
           if $short; then
              echo "+"

       Change the line - echo "+" to echo ""

    $ ARCH=arm make menuconfig

       Go to General setup->Local version - append to kernel release. Make the value of this "-gc2bee64", without the quotes
       Exit, and say Y to saving changes
    $ Edit the file .config, and check for the value CONFIG_TUN
       If there is not a line CONFIG_TUN=m, create it. Save and exit the file
  6. Compile the modules only
    $ ARCH=arm make modules SUBDIRS=drivers/net
  7. If all goes well, there will now be a file tun.ko in drivers/net. Copy it to your device using adb, and place it in /system/lib/modules (create the directory if necessary). To check the version of the module, type "strings drivers/net/tun.ko". It will show you the version of the module.
You now have to install OpenVPN on your device. Grab the OpenVPN Installer and OpenVPN Settings app from the Market, and install. Install OpenVPN to /system/xbin. Then install BusyBox to /system/xbin (or /sbin if you have run out of room) using the Busybox Installer (from the market)

With the latest versions of Android (or if you have push rules in your config), you have to get a newer version of the openvpn binary than what comes with the OpenVPN Installer. So grab and extract it over the top of /system/xbin/openvpn

With that above version of openvpn, it goes looking for ifconfig and route in particular locations. It looks for them in /system/xbin/bb/ifconfig and /system/xbin/bb/route. So

$ mkdir /system/xbin/bb
$ ln -s /system/xbin/busybox /system/xbin/bb/route
$ ln -s /system/xbin/busybox /system/xbin/bb/ifconfig

And that should be that!


  1. Is there anyway you can post the binaries for the Xoom with the kernel version?

  2. Hi! Tried to do my own tun module. Worked so far, but the kernel version from git (tegra) is only 2.6.36 not :-/
    So the resulting tun.ko doesn't work on my Kernel. Any ideas?
    Nevertheless a good article to build custom modules ;-)

  3. ben - that's okay! It adds the .3 when you compile it.

    I will edit the blog post to show you how to change the version... I thought I added it :-)

  4. Ok! Found out that the .3 is appended automatically :) BUT: I think i got closer but unfortunately i cannot load the module, see here:
    <3>[80158.538959] tun: version magic ' SMP preempt mod_unload
    ARMv7 ' should be ' SMP preempt mod_unload ARMv7 '
    Do you recognised the small plus sign in my module? I do not now where it comes from, it's not a string i putted in. Any idea would help.

  5. Ben - I have added a new step above (Step 5). It involves deleting the "+" from the kernel version.

    You may need to run "ARCH=arm make modules" for a little while (until it starts compiling actual .o files) to regenerate the relevant files that hold the KERNELRELEASE

  6. Sean! The hint with the setlocalversion does the trick. I struggled the whole day with
    --force-vermagic and finding some EXTRAVERSION lines, but couldn't locate them.
    It seems that Android does things different :)
    I thank you very much. I will put the
    module for the xoom on my small webpage :)
    Would be nice to stay in touch. Thx, again!

    insmod tun.ko
    # lsmod
    tun 12356 0 - Live 0xbf000000
    bcm4329 203316 0 - Live 0xbf077000

  7. Did you guys get this working on the Xoom 3.2 update?

  8. echang24 - Yep. The local version is now "-gb899528". The rest is identical...

    I have compiled it and placed it on my website -

  9. I'm trying to get this going on my Ubuntu 10.4 box (for my Xoom). I've completed everything up to step 6. Here the whole thing fails on me.

    WARNING: Symbol version dump /scratch/xoom/tegra/Module.symvers
    is missing; modules will have no dependencies and modversions.

    CC [M] drivers/net/mii.o
    cc1: error: unrecognized command line option "-mlittle-endian"
    cc1: error: unrecognized command line option "-mapcs"
    cc1: error: unrecognized command line option "-mno-sched-prolog"
    cc1: error: unrecognized command line option "-mabi=apcs-gnu"
    drivers/net/mii.c:1: error: bad value (armv4t) for -march= switch
    drivers/net/mii.c:1: error: bad value (arm9tdmi) for -mtune= switch
    make[1]: *** [drivers/net/mii.o] Error 1
    make: *** [_module_drivers/net] Error 2

    Any ideas?

  10. Never mind, I didn't see the link on July 19. Thanks for the binary Sean.

  11. Hello Sean,

    thank you for your guide.

    I spend the whole day, trying to compile a fitting module for " SMP preempt mod_unload ARMv7" (without any local version tag) but no success at all.

    Please could you be so kind and compile it for me ? :)

    This would be awesome!

    Cant believe how tricky it is to get OVPN working -.-

  12. Thanks for the post.. I have one error that I'm chasing.
    "FATAL can not allocate TUN/TAP dev dynamically"

    Any thoughts, would appreciate your input.

    Best, Eddie

  13. Eddie,

    That is a a symptom of the tun module not being loaded.

    Try 'modprobe tun' or cd to the modules directory, and insmod tun.ko. If it doesn't load, look at the dmesg output to see why.

  14. For everyone looking for a tun.ko. I found this amazing app for installing tun.ko. They have this tun.ko repository where they collect tun.ko and their app will find the correct tun.ko for your phone. Just search the app in the market it is called "tun.ko installer"

  15. root@HP-2170P:/home/gabriele/android-kernel/android_kernel_samsung_t1# ARCH=arm make modules SUBDIRS=drivers/net
    make: arm-none-linux-gnueabi-gcc: Command not found

    WARNING: Symbol version dump /home/gabriele/android-kernel/android_kernel_samsung_t1/Module.symvers
    is missing; modules will have no dependencies and modversions.

    CC [M] drivers/net/tun.o
    /bin/sh: arm-none-linux-gnueabi-gcc: command not found
    make[1]: *** [drivers/net/tun.o] Error 127
    make: *** [_module_drivers/net] Error 2


Post a Comment

Popular posts from this blog

Renewing Puppet CA and puppet master certificates

Preseeding Ubuntu Natty 11.04