Chroot Ubuntu 12.10 on Android (Asus Padfone, Nexus 10)

Updated: Oct 2013 – Non-root users can now use the network, and as a result the VNC server doesn’t need to be run as root anymore.

Updated: Feb 2013 – Made a bunch of corrections and added a few steps

Updated: May 2013 – I bought a Nexus 10, and I’ve moved my Lubuntu chroot over to the Nexus 10. No issues, I’d expect the same steps to work.

This tutorial documents the steps I went through to get a working Ubuntu system (Lubuntu) on my Android device, an Asus Padfone. I decided to use the ARM hard-float port (armhf) instead of armle in order to try to extract better performance from the processor.

The tutorial was written based on the notes I made during the process. This tutorial is not for the faint of heart, and it’s best if you have some familiarity with Linux and aren’t afraid of the terminal. I’m not sure if I missed our anything in my notes, so let me know in the comments if anything doesn’t work.

In this first post, I’ll only cover getting the command line chroot working. In the next post, I’ll cover getting the GUI working.

Update: The steps for getting a GUI are now given in part 3, below.

Also, I believe there’s an app that does exactly what I’m trying to do here, but I don’t know if it supports the Padfone yet. If you’re not so comfortable with the terminal, this is probably the way to go.

References
The following were webpages that I found useful. Some even have almost all the steps you need to do this.

Requirements

  • A rooted padfone
  • Terminal Emulator – I like this app because the hardware keyboard on the Padfone dock functions like a PC keyboard, with the back button functioning as escape. Very useful, especially when using Vim.
  • At least 2GB of space on your SD card or internal storage. (Following this tutorial exactly will use 3.5GB)
  • An Ubuntu/Lubuntu environment (Might work even on a live CD)

I also have busybox on my Padfone, but I’m not sure if it’s necessary.

Part 1 – Creating the bootstrap image
We are going to create a filesystem image to contain the entire Lubuntu installation. Then we will copy it to the Padfone.

On your Linux desktop (or server!) ensure you have debootstrap installed:

sudo apt-get install debootstrap

Change directory to a partition with enough space. (3.5G in this tutorial, 2GB minimum) For example:

cd /media/BigDisk

Create the empty disk image file:

dd if=/dev/zero of=img.lubuntu-armhf.root bs=8k count=458752
sudo mkfs.ext4 -L chroot -c img.lubuntu-armhf.root
sudo tune2fs -c 0 img.lubuntu-armhf.root

This creates a 3.5GB filesystem. If you want something smaller, like 2GB, substitute 458752 with 262144. Bear in mind that if you make your filesystem only 2GB, you’ll only have about 200MB free after installing the Lubuntu GUI.

Now, loop mount the newly created filesystem:

mkdir chroot
sudo mount -o loop img.lubuntu-armhf.root chroot

Now begin downloading the core system files.

sudo debootstrap --arch armhf --foreign quantal chroot http://ports.ubuntu.com/

Take a break while it downloads the core files. Once that is done, unmount the filesystem:

cd ../../
sudo umount chroot

Then copy img.lubuntu-armhf.root to your phone.

Part 2 – Setting up the system
Now that we have the bootstrapped filesystem on the phone, we’re going to set it up and install some software packages.

First, open Terminal Emulator, become root, and navigate to the where the image is. In my case, I copied the image into my SD card, which is mounted at /Removable/MicroSD on the phone. If you copied your image elsewhere, you should change directory there instead.

su
cd /Removable/MicroSD

Now, mount the filesystem, setup a minimal environment, and chroot into it. You will need busybox in order to chroot. In my phone, busybox is installed in /system/bin-busybox.

export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/system/bin-busybox"
export TERM=linux
export HOME=/root
export USER=root
export UID=0
mount -o loop img.lubuntu-armhf.root lubuntu
mount -t proc proc lubuntu/proc
mount -t sysfs sysfs lubuntu/sys
mkdir lubuntu/dev/pts
mount -t devpts devpts lubuntu/dev/pts
chroot lubuntu /bin/bash

If the mount or chroot fails, it’s possible then that busybox is actually required to work. In that case, install busybox and try those commands again.

Now that we’re in, let’s finish up the installation:

/debootstrap/debootstrap --second-stage

Symlink initctl to true so that the fact that upstart doesn’t work does not give us lots of warnings.

dpkg-divert --local --rename --add /sbin/initctl
cp /bin/true /sbin/initctl

Now do some additional basic configuration. (These settings are for my locale, which is English, Singapore. Modify the commands as necessary to match your actual locale.)

locale-gen en_SG en_SG.UTF-8
dpkg-reconfigure tzdata

Set the hostname and DNS server:

echo localhost > /etc/hostname
echo 'nameserver 8.8.8.8' > /etc/resolv.conf

Next, open /etc/apt/sources.list in an editor and replace the contents with this:

deb http://ports.ubuntu.com/ quantal main universe multiverse restricted

deb http://ports.ubuntu.com/ quantal-updates main universe multiverse restricted

deb http://ports.ubuntu.com/ quantal-security main universe multiverse restricted

Ok, let’s get the rest of the software. These are all optional, of course, but I like to have SSH, vim and tmux.

apt-get update
apt-get install ubuntu-standard vim tmux openssh-client openssh-server
apt-get clean
rm /var/run/reboot-required*

Ok, now let’s create a non-root user and disable the root password. Of course, replace jack with a user name of your choosing.

passwd -l root
adduser jack
usermod -a -G sudo jack

On Android, users which aren’t part of the AID_INET group (Group ID 3003) will not be able to use IP sockets at all. To get around this problem, we’ll create a group called aid_inet in the chroot with the correct group ID and make the non-root user (“jack”) a member of this group.

groupadd --gid 3003 aid_inet
usermod -a -G aid_inet jack

One last thing, it’s convenient to have a script to be able to get into the chroot quickly. Create a file called enter_chrootand place the following script in it:

#!/system/bin/sh

PREFIX=/Removable/MicroSD
ROOTFS=$PREFIX/lubuntu

if [ ! -d $ROOTFS/etc ]; then
    echo "Mounting lubuntu chroot..."
    mount -o loop $PREFIX/img.lubuntu-armhf.root $ROOTFS
    mount -t proc proc $ROOTFS/proc
    mount -t sysfs sysfs $ROOTFS/sys
    mount -t devpts devpts $ROOTFS/dev/pts
    mount --bind /sdcard $ROOTFS/mnt/sdcard
    mount --bind $PREFIX $ROOTFS/mnt/MicroSD
fi

echo "Setting environment vars"
export TERM=linux
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
export USER=jack
export SHELL=/bin/bash
export HOME=/root
export LANG=C

echo "Starting shell as user $USER"
/system/bin/chroot $ROOTFS sudo -u $USER -i

This script mounts the filesystems (if they haven’t been mounted) sets up the environment, then enters the chroot properly. Now, to enter the chroot:

sh enter_chroot

The “sh” is necessary because files are not allowed to be executable on the sdcard.

Ok, the command line environment is all done!

Part 3 – Setting up a desktop environment
There is an X11 server for Android, but as far as I know, there isn’t any window manager for Android yet. So, to get around this little problem, we’ll be running X11 in a framebuffer and use VNC to access this framebuffer.

First, we install the necessary packages. I’m using LXDE, but you could conceivably use something else lightweight like xfce.

apt-get install xvfb x11vnc lxde
apt-get --reinstall install xfonts-base

Next, we’re going to disable the logout feature, as it doesn’t work correctly:

dpkg-divert --local --rename --add /usr/bin/lxde-logout
cp /bin/true /usr/bin/lxde-logout

Now we need to configure startup files for our X11 session. The following listing shows the script used to start the GUI. This script should be run as the non-root user.

#!/bin/bash

# Check if the frame buffer is already running
pgrep Xvfb > /dev/null
if [ $? -eq 0 ]; then
    echo "Xvfb is already running. If you want to kill it, use:"
    echo "pkill -15 Xvfb"
    exit
fi

# Launch the X11 frame buffer
# This geometry is about half the usable resolution on the Nexus 10
# I choose to half it and zoom, because at full resolution, the UI 
# elements are way to small to be usable.
geometry='1280x750x24'

Xvfb -screen 0 $geometry -ac > /dev/null 2>&1 &
export DISPLAY=:0

# Give the server a chance to start up
sleep 1

# Now start the LXDE session
startlxde > /dev/null 2>&1 &

echo "Launched LXDE session"

# Launch the VNC server
x11vnc -localhost -display :0 -forever -usepw > /dev/null

Run this script whenever you want to use the GUI, and use an Android VNC client to open the display at localhost:5900. To kill the GUI, use the following command:

pkill -15 Xvfb

Or just type Ctrl-C in the terminal where it’s running.

30 thoughts on “Chroot Ubuntu 12.10 on Android (Asus Padfone, Nexus 10)

  1. StellarX

    Sounds really cool that you did this on an Android Phone?

    Compared to the Linux-on-Android APP Project that are more user-friendly than this, what’s the difference in the outcome? I am fairly new to Linux hence any advice would be helpful.

    Apart from that, may I know what’s the advantage of having a desktop OS over Android? One immediate pros I can think of is how intuitive is it to use when the padfone is docked just like any other netbook, the other is it’s multitasking capability (Running music player and several other instances of program at once)

    Totally intrigued by this!

    Reply
  2. tan-ce Post author

    Yes, the Asus Padfone is an Android phone. Currently it’s running Android 4.0.4 (Ice Cream Sandwich)

    Well, other than the obvious (easier to install), the only thing I can think off that is really better is that you get to control exactly how and what is installed. For example, my own script that mounts Lubuntu and chroots in also bind mounts other parts of Android inside the chroot, so I can access the SD card and internal flash memory or any other part of the Android filesystem as well. I have a feeling you might be able to do things like this with those apps too, but I’m not sure whether it’s a automatic process or manual (ie. modify scripts/config files manually).

    Most people would really just want to use the app, though. There’s also more than one, apparently, so you do have a few choices there. Then only people I really see who will prefer this method are Linux enthusiasts and those familiar with the GNU/Linux terminal.

    The biggest advantage of having a desktop userspace (the kernel is still Android!) is that you can run “PC” apps – as in it opens another whole new range of applications which you can run on the phone. I wouldn’t recommend anything more than light multitasking, though – there may not be enough memory and there is no swap enable in Android by default.

    Reply
    1. tan-ce Post author

      I can, but I’m currently away from home. It’ll probably take me 2 weeks or so before I’m able to do record a video.

      Reply
  3. suchy

    it looks awesome! Did you try make some photos or video with smartphone (or padfone station) ? i have linux from 2 years on my pc and fully usefull smartphone with ubuntu is my dream.:)

    Reply
  4. quill

    Thanks for this! I’ve been looking for instructions at about this level for generating an armhf based chroot image and this does the job. I’ve been playing around with various chroot methods, including LinuxonAndroid, but none quite work for me, so I guess I need to make it myself. I have a Galaxy Note 2 and want to use it as alternative linux desktop when I’m traveling.

    I look forward to your next post describing how you got the desktop GUI installed and working!

    Reply
  5. tan-ce Post author

    @suchy, If you want a clean install of Ubuntu on a tablet (not a phone, though), you should take a look at the Nexus 10. Last I heard Canonical has ported Ubuntu to that device and will officially support it in future releases. But if you want it in a smartphone, then yeah… that’s different =). I didn’t take any pictures of my devices, but I’m sure you can find many such videos and photos by searching the web.

    @quill, I’ll admit that I’ve nearly forgotten about writing instructions for the GUI, so I’ll try to get to it soon. However, some things has changed, and I’ll probably update these instructions for Ubuntu 12.10. I’m also hoping the GUI installation will be smoother for 12.10.

    Reply
  6. Brian

    Does anyone know if you can install Wine and Windows programs on this or does the architecture of the unit prohibit this? I would really like to know if I can run Photoshop CS6 in Ubuntu on the Padfone. Please someone try it and let me know!

    Reply
    1. tan-ce Post author

      I doubt it. Wine only emulates the Win32 API. The binaries are still run on the CPU directly, so it’s not like a VM. (Windows programs use x86 instructions, while the Padfone uses an ARM CPU.) Even if you could, I doubt it’ll be usable, as the Padfone only has 1GB of RAM and no swap. Even 2GB is not likely to be enough.

      If you want to try using wine in Android, you should consider getting an Intel Atom based tablet. (eg. The Fonepad) But again, ARM CPUs and Intel Atoms are really anemic for something like CS6, not to say anything about memory requirements…

      Reply
      1. Brian

        I kind of figured. But android always has Photoshop touch 😀 … I’m just trying to find out if it could be used as a full fledged desktop or if it would be always a “Android Device”. What about native Ubuntu Apps like the Gimp and OpenOffice? How do they fair?

        Has anyone installed Ubuntu using this method to the Padfone 2?

        I was also wondering – Has anyone tried the XBMC build for android on the Padfone yet? I would be interested to know how well it works! Please let me know. FYI I am pretty sure I am going to buy the Padfone 2 with the tablet and a HDMI cable for my television. I want it to be seamless and work something like what Ubuntu is proposing (Phone to tablet to desktop to media center).

        Any suggestions would be appreciated!

        Reply
        1. tan-ce Post author

          Actually, because of Ubuntu’s phone efforts, they’ve ported (I think) almost everything in main, universe, and multiverse to ARM hard float. So, for example, apt-cache search in my chroot tells me that Gimp and LibreOffice are in the repository, along with their numerous plugins and modules. (I think most distros have abandoned OpenOffice for LibreOffice.)

          Although to run apps that big you’ll really want something like the PadFone 2 or Infinity, for the CPU power, as well as the RAM. I would imagine the steps should be exactly the same for any device, so long as it’s rooted and has chroot and mount – those are the only commands required outside the chroot.

          Something like XBMC is going to be more tricky, as you’re gonna to want a setup that is essentially Ubuntu for Android so that the X11 server has direct access to the GPU. In my setup, we’re really using a “faux” X11 server drawing to a memory only “framebuffer”. Therefore, even the most basic acceleration functions are unavailable. Video playback would be unbearable.

          I came across a forum post where some one figured out how to get Ubuntu’s chrooted X11 to take over the HDMI frame buffer, but I don’t remember where that thread was. In any case, you might be better off taking a look at the Ubuntu for Android for any media related functions.

          Reply
          1. Brian

            Android (and iOS) has a native XBMC app now actually so I was wondering how that would fair on the Padfone 2 (not installing via ubuntu). Everything else you said is what I was thinking and hoping to hear so thank you for that!

            Any other suggestions / info on the Padfone 2 that I should know about?

            Reply
          2. Brian

            I have looked all over for Ubuntu for Android and I cannot seem to find any build information on it nor can I find any way to install it on any devices. I did see the dev preview of ubuntu touch but that is only available for the Nexus line as of right now (a few others are unsupported but not worth it from what I can tell). Any idea where I can get ubuntu for android for the Padfone 2?

            Reply
          3. tan-ce Post author

            Ah, I didn’t know XBMC is available as an Android app. One gotcha I can imagine is that the HDMI out on the PadFone is fixed to the resolution of the Phone itself – 960 x 540, which isn’t really that good. The PadFone two uses 720p, which should be not too bad. The Infinity goes straight for 1080p HD even while in handset form.

            Actually, I’m not going to buy the PadFone 2. I’ll likely save money and wait for the PadFone Infinity to reach my country.

            As for Ubuntu for Android, yeah, I think they never really released anything we can use. And with Canonical pushing Ubuntu Phones, it’s possible that project may not go anywhere. If you want Ubuntu Phone, though, your best bet is gonna be a Nexus device.

            Reply
  7. Brian

    I am thinking about waiting for the padfone infinity but the only real problem is that it doesn’t look likely that there will be a U.S. release of any of the Padfones :-/ … I would have to get a Taiwanese or European version and settle for 2G 🙁 … Kind of sucks but my area really doesn’t have 3G anyways and I get WiFi everywhere so I think I can deal with that.

    When is the Infinity slated for a release? I know it is soon.

    Reply
    1. tan-ce Post author

      The Padfone Infinity will be released in April, in Europe. So, I’m actually not sure when it will be coming to my country either. (I reside in Singapore.) If it doesn’t actually come to Singapore, then I’m hoping that the Europe LTE modem works with my local carriers.

      The RikoMagic looks spiffy, and small enough to be carried around in a pocket too. And cheap!

      Reply
      1. Brian

        That’s one thing I am facing now. I reside in the U.S. and have AT&T as my only option as a carrier. From what I have read I will only be able to use 2G and Edge in the U.S. on the Padfone. If this is the case, sadly I will probably have to get a different device 🙁

        Reply
        1. Brian

          We use GSM and CDMA. We actually have 4G LTE with Verizon and will be getting 4G with AT&T but the problem lies in the hardware of the phone. The GSM portion of the phone only supports our 2G GSM networks (from what I have read) and we cannot get verizon (or any of our other CDMA networks) on the Padfone 2 at all. So I am torn between the Awesomeness of the device and what my network would be like 🙁

          Reply
          1. Brian

            I also just read that AT&T will be completely dropping the entire 2G/EDGE network within the next few years… So as for now – No Padfone for me! I will have to pray they come out with a U.S. release. Why is it that all of the cool gadgets never come here? Because our stupid companies control our government and are in fear of losing out on their $$ so they don’t want it. I hope Asus is able to bring us something soon!

            Reply
        2. tan-ce Post author

          Don’t forget the multitude of patent lawsuits… =P

          But yeah, I heard recently that Qualcomm announced a baseband/modem which can handle all networks and someone else (I don’t remember who) made a mobile antenna which can be tuned in/by software.

          Hopefully the time will come that we don’t need separate hardware for the multitude of bands in the world today.

          Reply
      1. tan-ce Post author

        I thought about that, but it’s rather pricey. In the end, I went with a new phone and a Nexus 10. And it was still cheaper than the Infinity…

        Reply
  8. Keyboard & Gitarrenschule Münster Jan Gryz

    Usually I don’t learn article on blogs, however I would like to say that this write-up very forced me to try and do it! Your writing style has been surprised me. Thanks, very great article.

    Reply
  9. cairns oficial facebook page

    Hello! Quick question that’s totally off topic. Do you know how
    to make your site mobile friendly? My blog looks weird wen browsing fropm myy
    iphone4. I’m trying to find a theme or plugin that might be able to resole this
    issue. If you have any recommendations, please share.
    Many thanks!

    Reply
  10. delhi university 2014 fourth cut off list

    Whats up this is somewhat of off topic but I was wondering if blogs use WYSIWYG editors or
    if you have to manually code with HTML. I’m starting
    a blog soon but have no coding expertise so I wanted to get guidance from someone with experience.
    Any help would be enormously appreciated!

    Reply
  11. More information about tigers

    Hey there, I think your blog might be having browser compatibility issues.
    When I look at your website in Ie, it looks fine but when opening in Internet Explorer,
    it has some overlapping. I just wanted to give you a quick heads
    up! Other then that, fantastic blog!

    Reply
  12. wewqe efsfdsf

    Hi, I log on to youг blog regularly. Υoսr writing style іѕ awesome, keeр doping ԝhɑt you’rе doing!

    Reply

Leave a Reply to Brian Cancel reply

Your email address will not be published. Required fields are marked *