[GUIDE] Build Debian image to run on Tab via chroot

102 posts
Thanks Meter: 12
By maniac3389, Senior Member on 17th July 2011, 04:49 AM
Post Reply Email Thread
I've been experimenting and gathering information all day on how to build a Debian image to run on the Tab (and any other ARM Android devices, for that matter). I've found all the stuff on how to use the Ubuntu images posted, but I really wanted to know how to build a minimal system that I could have complete control over. (I used the latest version of Debian available, Squeeze, when building this, so anything that references "Squeeze" in the commands is because of that. You can easily substitute in a more generic name for files.)

I am going to break this down into a few sections.

  • Debian or Ubuntu machine (I used a VM with Ubuntu 11.04 installed on it)
  • Rooted Tab with BusyBox installed

Create the Image:
On the Linux machine you will need to install debootstrap
sudo apt-get install debootstrap
Create a blank image, format it and then mount it
dd if=/dev/zero of=squeeze.img bs=1M count=512

mkfs.ext4 -F squeeze.img

sudo mkdir /mnt/squeeze/
sudo mount -t ext4 -o loop squeeze.img /mnt/squeeze/
Note: The image file above is for 512MB, change it to "count=1024" for 1GB, I tried 512MB and it was very limited in space once X was installed.

Run debootstrap and install the system into the image
sudo debootstrap --verbose --arch armel --foreign squeeze /mnt/squeeze/
Unmount the image
sudo umount /mnt/squeeze/
Install the Image
Create a folder on the Tab, I used /sdcard/debian/ as my storage for my Debian files. Copy your newly created image over into the folder.

Installation will involve the following:
  • Creating a mount point and mounting the image
  • Chrooting into the Debian system
  • Setting some variables
  • Running the debootstrap installation
Either in a terminal on the device or using adb, do the following to install the system. (The code is commented to better explain how things are working.)
# Gain root access

# Create a mount point and mount the image file into it
#	You can substitute any folder instead /data/local/debian/
mkdir /data/local/debian/
mount -o loop,noatime -t ext4 /sdcard/debian/squeeze.img /data/local/debian/

# Chroot into the Debian system
chroot /data/local/debian/ /bin/sh

# Set some required variables
export PATH=$bin:/usr/bin:/usr/sbin:/bin:$PATH
export TERM=linux
export HOME=/
export USER=root

# Set the shell prompt just in case it got overwritten by something else
export PS1='[email protected]$HOSTNAME:${PWD-?} # '

# Run debootstrap
sh /debootstrap/debootstrap --second-stage

# Start a bash shell

First Boot
Technically the system is running, but if you start to use it you will quickly notice some things just aren't right. There are a few things that I've found that I've needed to do in order to get things running right. You should only need to do these the first time the system is run.

In the Debian shell that is still running on the Tab, do the following
# This is for working DNS
echo "nameserver" > /data/local/debian/etc/resolv.conf
echo "nameserver" >> /data/local/debian/etc/resolv.conf

echo " localhost" > /data/local/debian/etc/hosts

# Needed to install packages from the repository
echo "deb squeeze main contrib non-free" > /etc/apt/sources.list
echo "deb-src squeeze main contrib non-free" > /etc/apt/sources.list

# Do the initial update of the package repository
apt-get update
Once that is complete return to the Android system by running the exit command
So that's a fully running system right there. But we haven't addressed starting and shutting down the system.

Here is what a simple boot script would look like to both run and stop the system:

echo "Mounting Debian Squeeze..."
mount -t ext4 -o loop squeeze.img /mnt/squeeze/

echo "Setting environmental variables..."
export PATH=$bin:/usr/bin:/usr/sbin:/bin:/sbin:$PATH
export TERM=linux
export HOME=/
export USER=root
export PS1='[email protected]:${PWD-?} # '

echo "Mounting devpts/proc/sysfs..."
mount -t devpts devpts /data/local/debian/dev/pts
mount -t proc proc /data/local/debian/proc
mount -t sysfs sysfs /data/local/debian/sys

echo "Chrooting into Debian Squeeze..."
chroot /data/local/debian/ /bin/bash

echo "Unmounting devpts/proc/sysfs..."
umount /data/local/debian/dev/pts
umount /data/local/debian/proc
umount /data/local/debian/sys

echo "Unmounting Debian Squeeze..."
umount /mnt/squeeze/
You will notice that the script also mounts and unmounts additional system filesystems. Also, the script basically pauses right after the chroot command waiting for the process to end, which occurs when you type exit inside of the Debian system. In effect, the script queues up the umount commands for whenever the Debian system is exited.

I use a script similar to that (without the mount/umount because I prefer to do that myself) to start my system. I have it saved to /sdcard/debian/debian and I start the system with the following command:
sh /sdcard/debian/debian
The following issues have been encountered:
  • If the image file is mounted then unmounted, if you try to remount the image again it will error out. (Reboot to solve)

Optional Installation:
Of course the steps above leave you with a working system, but no doubt you will want more functionality.

I've installed TightVNC using the following command:
apt-get install tightvncserver
To start it:
vncserver -geometry 1280×752
After that you can connect to it using any VNC software, either local or over the network. If you connect local, be sure to use
Note: This does not install a window manager, if you VNC into the Tab you will get a blank desktop.

I also found that the less command was missing. Turns out the easy fix was to do the following:
apt-get install less
All of this has just been what I've encountered so far today, haven't done much more than set up the system. Please let me know if I'm missing any key parts of the system or if there are any ways that this could be more streamlined.

Hope this helps someone
The Following 5 Users Say Thank You to maniac3389 For This Useful Post: [ View ] Gift maniac3389 Ad-Free
17th August 2011, 02:11 AM |#2  
roar109's Avatar
Senior Member
Flag Monterrey
Thanks Meter: 6
Thanks man, after rooting my SGT i have been looking for something like this, i'll try it when arrive home.
17th August 2011, 02:23 AM |#3  
Thanks Meter: 2
does touch screen work?
17th August 2011, 05:14 AM |#4  
Senior Member
Thanks Meter: 30
Originally Posted by hardt2788

does touch screen work?

Dear god man read! It runs as a Virtual Machine on your tablet and you use a VNC client to control it. So yes touchscreen works but it is not a duel boot and is "piggy backing" off android.

So if someone emails you can switch to the email app then back to the vnc app.
18th August 2011, 04:39 AM |#5  
Live2Follow's Avatar
Senior Member
Flag Raleigh, NC
Thanks Meter: 15
You need pills.

Sent from my GT-P7510 using XDA Premium App
18th August 2011, 11:45 PM |#6  
jamezelle's Avatar
Retired Forum Moderator / Retired Recognized Developer
Flag Ohio
Thanks Meter: 101
Donate to Me
maniac3389, have you tried running lxde instead of gnome to see if it runs any faster?
19th August 2011, 07:16 PM |#7  
OP Senior Member
Thanks Meter: 12
Originally Posted by hardt2788

does touch screen work?

Sorry, been a few days since I've been on here. Well, the concept is that you run a VNC server in the Debian system and you "remote" into it via a VNC client on the Honeycomb side.
19th August 2011, 07:18 PM |#8  
OP Senior Member
Thanks Meter: 12
Originally Posted by jamezelle

maniac3389, have you tried running lxde instead of gnome to see if it runs any faster?

Been a bit since I've worked with it, it installed and worked but something was quirky about it. (can't recall what it was)
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes