[SCRIPT]Debian Image Builder (01-22-2012)

Search This thread

gnarlyc

Retired Recognized Developer
Feb 20, 2010
441
57
Raleigh, NC
Debian Image Builder...

So basically, I've been reading several different articles, etc. on running Debian and/or Ubuntu on Android. I did this on my Eris and D1 in the past, and I figured that it would work even better on the Galaxy Nexus. Of course it does... Anyway, it can be run from a loop mounted image or a separate partition on most phones. However, for phones like this one with no sdcard slot, it makes sense to just do the image thing.

After building and rebuilding an image a few times, I decided to do what I normally do and turn those crazy linux commands into a script. It's not really all that complex or fancy, but it works and can be improved. I hope you find it helpful.

NOTE: This is really just the first step in getting Debian running on your phone. This will just create the image. You still have some work to do. There are other ways to do this, but I like having control of the initial image...

1/14/2012 - fixed some typos and added 'apt' as a default package (debootstrap did this by default, but apparently multistrap doesn't)
1/16/2012 - removed multistrap and went back to debootstrap for now
1/21/2012 - added a setup script to do the second stage and updates after booting into Debian on the phone, fixed extra package install code
1/22/2012 - updated variable code per swordrune10's suggestion

Download: https://github.com/gnarlyc/DebianImageBuilder

Currently requires Debian 6, but feel free to fix that for me.

Rock on.
 
Last edited:

ttereve

Member
Jan 6, 2010
49
5
Where do we put the image? Do we have to create a new partition?

Sent from my Galaxy Nexus using XDA App
 

gnarlyc

Retired Recognized Developer
Feb 20, 2010
441
57
Raleigh, NC
Where do we put the image? Do we have to create a new partition?

Sent from my Galaxy Nexus using XDA App

No, you don't have to create a partition. Here's what I do:

I use Connectbot for a terminal emulator, but there are others out there.

One time:
1) 'mkdir /data/local/debian' (don't type the single quotes)
2) copy the image to /sdcard/

Each time I start up (actually, I've made a script for this too):
1) 'su'
2) 'mount -o loop -t ext2 /sdcard/linux.img /data/local/debian'
3) 'chroot /data/local/debian /bin/bash'
4) ta-da!

You should be at a Debian bash prompt. Check /etc/apt/sources.list to make sure it's there and has 'deb http://ftp.us.debian.org/debian squeeze main'. You might also have to do 'dkpg --configure -a'. If it looks like that's needed each time, I'll automate it. If you install a desktop gui like xfce or whatever, you'll probably want to install tightvncserver in Debian and get an Android VNC client from the Market. I'll probably add more options to make these things a little easier in the future.

I'm still going through the entire process over and over until I get things how I want it, so the script will be updated as I get the time.
 
Last edited:

gnarlyc

Retired Recognized Developer
Feb 20, 2010
441
57
Raleigh, NC
Is there any chance that this will work on GSM GN?

Sent from my Galaxy Nexus using xda premium

Yes. This just builds the rootfs in an image. It should work for nearly any arm based Android device. I'm still working out some kinks with getting vnc and SSH servers working though. These worked fine when I used debootstrap to create the rootfs, but multi strap is much more flexible. So, I'm going to keep trying multi strap for a bit.
 

ttereve

Member
Jan 6, 2010
49
5
alright I can get into root@localhost bash but i can't start ssh because well, there is no ssh in/etc/init.d/ how do I get it in there? (i built my own ubuntu rootfs with rootstock)?
 

gnarlyc

Retired Recognized Developer
Feb 20, 2010
441
57
Raleigh, NC
alright I can get into root@localhost bash but i can't start ssh because well, there is no ssh in/etc/init.d/ how do I get it in there? (i built my own ubuntu rootfs with rootstock)?

Did you install openssh-server?

EDIT: Yeah, some things aren't working quite right with installing and updating packages. I might have to re-work it with debootstrap again... Oh well.
 
Last edited:

gnarlyc

Retired Recognized Developer
Feb 20, 2010
441
57
Raleigh, NC
Ok. Give me a day or two. I've re-written the script using debootstrap instead. I'll update the repo as soon as I do my initial test, which should be later tonight.
 

ttereve

Member
Jan 6, 2010
49
5
sweet I got it all to work! I'll try and get a script up for the way I did it.

btw I used a rootstock ubuntu rootfs

now I need to figure out how to setup gnome through command line!
 

gnarlyc

Retired Recognized Developer
Feb 20, 2010
441
57
Raleigh, NC
sweet I got it all to work! I'll try and get a script up for the way I did it.

btw I used a rootstock ubuntu rootfs

now I need to figure out how to setup gnome through command line!

Cool! I read something about rootstock, but never really looked too deep. Yeah, post your code. That would be great. I have used debootstrap before, so I know it works. The thing that I never liked is that you have to run '/debootstrap/debootstrap --second-stage' after you boot into Debian on the phone. With multistrap, the packages are supposed to all be there and ready to go. (At least, that's how I understand it.) Anyway, I'm working out debootstrap again, and will just do a one-shot startup script or something. Or maybe, I'll switch gears and do it your way instead...
 

ttereve

Member
Jan 6, 2010
49
5
from: http://androlinux.com/android-ubuntu-development/how-to-build-chroot-arm-ubuntu-images-for-android/

build rootfs

Code:
sudo rootstock \
--fqdn ubuntu \
--login ubuntu \
--password ubuntu \
--imagesize 4G \
--seed linux-image-omap,build-essential,ssh,tightvnc

then make an image:

Code:
dd if=/dev/zero of=ubuntu.img bs=1MB count=0 seek=4096

format as ext4

Code:
mkfs.ext4 -F ubuntu.img

mount empty image

Code:
sudo mount -o loop ubuntu.img /mnt

extract rootfs inot image

Code:
sudo tar -C /mnt -zxf armel-rootfs-datetag.tgz

and unmount

Code:
sudo umount /mnt

this is my script to get chroot working (but this script fails and idk why so any help would be appreciated) (modified from the script http://burningbroccoli.se/post/949205350/chrootd-ubuntu-on-samsung-galaxy-s-android):


Code:
#!/bin/sh


    echo "mount the image"
    mount -o loop -t ext4 /sdcard/ubuntu.img /data/local/ubuntu

    echo 'Mounting proc,sys and dev'
    busybox mount -t proc proc /data/local/ubuntu/proc
    busybox mount --bind /sys /data/local/ubuntu/sys
    busybox mount --bind  /dev /data/local/ubuntu/dev

echo 'Exporting a proper path'
export PATH=/bin:/usr/bin:/sbin:/usr/sbin:$PATH

echo 'Chrooting and starting ssh server'
chroot /data/local/ubuntu /bin/bash

echo "And your ip is:"
busybox ifconfig | busybox grep "inet addr"
 

gnarlyc

Retired Recognized Developer
Feb 20, 2010
441
57
Raleigh, NC
I looked at rootstock. It doesn't appear to be Debian friendly, but maybe I'm just missing something. As soon as I'm happy with this on Debian, I'll look into making it work on Ubuntu also. I also realized that debootstrap has an option to install extra packages, so that's cool.

Right now, this is working well for me, but there are things that I would like to add.
 

swordrune10

Senior Member
Mar 26, 2009
1,032
675
Houston, TX
www.swordrune10.net
ran into a problem, apparently it doesnt know let so it pretty much didnt work..

Code:
./debianImageBuilder.sh: 20: let: not found

running oneiric and the UI is gnome3

---------- Post added at 04:53 PM ---------- Previous post was at 04:37 PM ----------

nvm, i got it to work by modifying it to this.. u can do whatever to the code, im just happy to help... tho im not sure why let doesnt work for me x.x

Code:
export image_name=debian.img	
export build_folder=image_folder
real_image_size=$(6442450944)
echo "******************************"
echo "Installing dependencies"
echo "******************************"
apt-get install debootstrap
echo "******************************"
echo "Gather info"
echo "******************************"
echo -n "What size image would you like to create? (in GBs): "
read image_size
real_image_size=$(((($image_size * 1024) * 1024) * 1024))
 

gnarlyc

Retired Recognized Developer
Feb 20, 2010
441
57
Raleigh, NC
ran into a problem, apparently it doesnt know let so it pretty much didnt work..

Code:
./debianImageBuilder.sh: 20: let: not found

running oneiric and the UI is gnome3

---------- Post added at 04:53 PM ---------- Previous post was at 04:37 PM ----------

nvm, i got it to work by modifying it to this.. u can do whatever to the code, im just happy to help... tho im not sure why let doesnt work for me x.x

Code:
export image_name=debian.img	
export build_folder=image_folder
real_image_size=$(6442450944)
echo "******************************"
echo "Installing dependencies"
echo "******************************"
apt-get install debootstrap
echo "******************************"
echo "Gather info"
echo "******************************"
echo -n "What size image would you like to create? (in GBs): "
read image_size
real_image_size=$(((($image_size * 1024) * 1024) * 1024))

Cool. That does look a bit cleaner. The code for installing extra packages wasn't right/all there, so I'm working on that now.
 

NTolerance

Member
Jan 8, 2011
28
6
Thanks for this script. It worked perfectly for me. It's great to be able to apt-get things on my phone, and it's interesting to run debian's utilities on Android. A lot of other methods are about getting some sort of Linux desktop on Android, but I really appreciate the barebones CLI that this provides. To my knowledge this is the only way to be able to run ping6 on Android.

To anyone thinking of setting this up - make sure to install busybox!

I made a couple of helper scripts to get cleanly in and out of the chroot, and to make the sdcard directory available within debian. I'm keeping this stuff stored in /sdcard/debian:

Code:
root@android:/sdcard/debian # ls
debian.img
debroot
start.sh
stop.sh

start.sh
Code:
mount -o loop -t ext2 debian.img debroot
busybox mount --bind /sdcard debroot/mnt
chroot debroot /bin/bash

stop.sh
Code:
umount /mnt/sdcard/debian/debroot/mnt
umount /mnt/sdcard/debian/debroot/dev/pts
umount /mnt/sdcard/debian/debroot/proc
umount /mnt/sdcard/debian/debroot/sys
umount /mnt/sdcard/debian/debroot
 

Top Liked Posts

  • There are no posts matching your filters.
  • 2
    Debian Image Builder...

    So basically, I've been reading several different articles, etc. on running Debian and/or Ubuntu on Android. I did this on my Eris and D1 in the past, and I figured that it would work even better on the Galaxy Nexus. Of course it does... Anyway, it can be run from a loop mounted image or a separate partition on most phones. However, for phones like this one with no sdcard slot, it makes sense to just do the image thing.

    After building and rebuilding an image a few times, I decided to do what I normally do and turn those crazy linux commands into a script. It's not really all that complex or fancy, but it works and can be improved. I hope you find it helpful.

    NOTE: This is really just the first step in getting Debian running on your phone. This will just create the image. You still have some work to do. There are other ways to do this, but I like having control of the initial image...

    1/14/2012 - fixed some typos and added 'apt' as a default package (debootstrap did this by default, but apparently multistrap doesn't)
    1/16/2012 - removed multistrap and went back to debootstrap for now
    1/21/2012 - added a setup script to do the second stage and updates after booting into Debian on the phone, fixed extra package install code
    1/22/2012 - updated variable code per swordrune10's suggestion

    Download: https://github.com/gnarlyc/DebianImageBuilder

    Currently requires Debian 6, but feel free to fix that for me.

    Rock on.