Friday, April 09, 2010

Installing Debian on a G1 (HTC Dream)

I bought a G1 in November having heard good reviews of them from the few people I knew who owned one and pleasantly surprised at how easy it was to type on the keyboard, which was the main problem I had had with iPhones.

Anyway, I haven't really done much messing with it until the last couple of weeks when I discovered myself very bored while at home for the Easter break. Having heard it was possible a while ago I started off by rooting the phone and installing CyanogenMod (instructions here for those of you who want to try it), a replacement for the default Android installation, adding a features that haven't been pushed down the line by vendors yet and a few extras such as the ability to store apps on the SD card, USB tethering and various Unix commands.

Having rooted the phone I was curious as to what I could now do and found it mentioned that it was possible to install Debian in a chroot since it already supports ARM EABI. I partially followed this post by saurik but came across several issues and shortcuts due to using CyanogenMod.

Here are some brief instructions to get Debian working on CyanogenMod:

Making a Debian image
To avoid having to partition my SD card (I use it for various other things) I created a mountable image as follows (assuming you are running Debian on your computer too), to avoid confusion I also add an sdcard directory here that the sdcard will later be mounted in:
apt-get install debootstrap
dd if=/dev/zero of=debian.img seek=749999999 bs=1 count=1
mke2fs -F debian.img
mkdir debian
mount -o loop debian.img debian debootstrap --verbose --arch armel --foreign lenny debian http://ftp.de.debian.org/debian
mkdir debian/sdcard
umount debian
As CyanogenMod comes with the Linux filesystem drivers and busybox you don't need to worry about adding them which means a large portion of saurik's instructions can be skipped.

Mounting the Image
Mounting the loop device caused some problems but I eventually found that it was looking for the loop devices at /dev/block/loop* rather than /dev/loop* which was fixed by adding a few ifs to the start of the mounting script.
#!/system/bin/sh
if [ ! -e /dev/loop0 ]
then
ln /dev/block/loop0 /dev/loop0
fi
if [ ! -e /dev/loop1 ]
then
ln /dev/block/loop1 /dev/loop1
fi
if [ ! -e /dev/loop2 ]
then
ln /dev/block/loop2 /dev/loop2
fi
if [ ! -e /dev/loop3 ]
then
ln /dev/block/loop3 /dev/loop3
fi
if [ ! -e /dev/loop4 ]
then
ln /dev/block/loop4 /dev/loop4
fi
if [ ! -e /dev/loop5 ]
then
ln /dev/block/loop5 /dev/loop5
fi
if [ ! -e /dev/loop6 ]
then
ln /dev/block/loop6 /dev/loop6
fi
if [ ! -e /dev/loop7 ]
then
ln /dev/block/loop7 /dev/loop7
fi
mount -o loop,noatime -t ext2 /sdcard/debian/debian.img /data/local/debian/mnt
busybox mount -o bind /sdcard /data/local/debian/mnt/sdcard
export PATH=/usr/bin:/usr/sbin:/bin:$PATH
export TERM=linux
export HOME=/root
export USER=root
busybox mount -t proc none /data/local/debian/mnt/proc
busybox mount -t sysfs sysfs /data/local/debian/mnt/sys
busybox mount -t devpts devpts /data/local/debian/mnt/dev/pts
if [ ! -e /data/local/debian/installed ]
then
busybox chroot /data/local/debian/mnt/ /debootstrap/debootstrap --second-stage
touch /data/local/debian/installed
fi
I saved this script as mountdeb.sh and the debian.img file in a folder called "debian" at the root of the SD card and mounted it on my G1 again.
I used a terminal emulator (search Market for Terminal Emulator by ZTA Technologies). First to enable things like tab completion and command history I changed the initial command (done through the menu in the Terminal) to:
su -c "busybox sh"
which nicely drops you in busybox as root instead of the poor implementation of sh that android comes with by default.

Running:
/sdcard/debian/mountdeb.sh
chroot /data/local/debian/mnt/ /bin/bash
drops you into bash in your shiny new Debian installation from which you can use apt-get to install whatever you feel like.

Automating the Installation
Since I didn't want to have to type the above into the phone every time I wanted to use Debian on my phone and I also much preferred being able to use ConnectBot to access it I automated starting it as follows:

First I installed the dropbear ssh server onto the Debian install:
apt-get install dropbear
This allowed me to either ssh to localhost from the phone or ssh in from my computer, which I was quite glad of after typing on the small keyboard for a while. Next to automate it.

Cyanogenmod provides facilities for auto running scripts using /etc/init.d/ however these all get run before android mounts /sdcard which means that we can't run our script at this point unless we mount /sdcard ourselves (which does work but it means that none of the applications on the phone will be able to access /sdcard (I think there may be a way to change this by messing around with permissions but I haven't tried it yet)).

Since init.d ran things to early I found an autorun application called Phone Prioritizer (available here (put the .apk in the attached zip on your SD card and open it with the package installer. Unfortunately you have to register on the XDA forums to get it), not on Market for some reason) which allows a script to be executed once the system has started up (Broadcast the BOOT_COMPLETED intent), it also had some options for running cron like scripts but I disabled these for the moment. To start the Debian chroot I edited /sdcard/phonePrioritizer/afterboot.txt (the file it checks after booting) to read:
busybox sh /sdcard/debian/mountdeb.sh
busybox chroot /data/local/debian/mnt/ /usr/sbin/dropbear
Rebooting the phone I found I could immediately ssh in using ConnectBot on the phone. Some simple certificate setup later and I didn't even need to type in a password from the phone to itself. :)

If anyone tries to follow these instructions let me know if you have any problems.

Thursday, November 16, 2006

Brief update

Over the next week or so I'm planning to make a few posts about my trip to Canada over the summer, especially if I can find all of the pictures.
At the moment I've got a maths exam though so I'm going to have to you all with a picture and write about it later.leave

(click to enlarge)

Edit: So, I rather forgot to do this, but here are the photos that I meant to post back when I wrote this post: http://zed0.uwcs.co.uk/Misc/Canada/

Sunday, November 05, 2006

Resurrection

Yep, I'm starting up my blog again with news from me at uni.

Warwick is pretty cool so far, work is pretty good and at a level where you can do pretty much as much or as little as you like, though naturally you need to do more for decent grades.

I've joined waaaay to many societies and sports clubs:

Juggling
Sci Fi
Climbing
Computing
Mountaineering
Video Game Design
Assassin's Guild
Snow Sports
Student Cinema
(in no particular order)

Juggling is really fun, despite my crappiness at juggling, I tend to do diabolo or poi there instead.
There was a society trip to Leeds yesterday to a juggling convention which was awesome, especially the shows at the end. Thoguh I did somehow manage to spend a ridiculous ammount of money on a new diabolo and poi, though they're pretty nice and should do me for a while.

Also heres a picture of me doing poi at 3 in the morning on top of a 12 foot sculpture wearing a toga.... don't ask.

(right click and view image to see full size)

Sci Fi club, however geeky it may be is pretty fun too, as the name suggests it is mainly to do with sci fi, but it isn't actually movies rather than board games and pen and paper role playing games.

Climbing is great fun especially since theres an awesome wall in our sports centre, which at £40 for the year is pretty good.

Computing, or compsoc as its known is another geeky one, also fun, though I haven't been along to many of their events, the exception being their 49 hour LAN party (note I didn't stay in there the entire 49 hours like some did).

Mountaineering is good in that it gets me out walking some more (since my last post I've done barely any walking and I was disgraced the other day to find that me feet were aching after a 15 mile walk), there was a trip to Snowdonia two weeks ago which was great fun, we did some nice walks and scrambles as well as a lot of table traversing (climbing over and under tables without touching the floor) in the evenings. There is another trip, this time to Ambleside (in the lake district), next weekend which I am looking foreward to imensely.

Video Game Design is just what it sounds like, and also gives me an excuse to pla my DS with otuer people from time to time.

Assassin's Guild is rather odd and apparently originated in Cambridge. Basically you sign up to a game over a few weeks, you get given a target who is someone else who has signed up, and you have to kill them in a novel way i.e. dropping a (polystyrene) fridge on their head, shooting them with a water pistol or setting up elaborate water traps. Unfortunatley I ahven;t managed to sign up for any games of this yet, but it should be fun.

Snow Sports is mostly a reason to go skiing, though they do a lot of socials too, I didn't make it into the Christmas trip to France, but I'm probalby going somewhere with Warwick Mountains instead anyhow.

Student Cinema is what it sounds like, they take over a huge lecture theatre and then project a film every night. So far I've been too busy with work and other societies to go and see anything but I'm hoping to go and see Brick (an awesome film) late tonight after our lamb roast.

Well, thats what I've been up to since I got to Uni, more details will probably follow.

Stay Alive
Zed0

Monday, May 29, 2006

...But I would walk five hundred miles...

...ok well maybe only one hundred...

Well I am glad to say that I managed it in a time of 33 hours and 59 minutes. I got to the last checkpoint at 7:20 (33 hours and 20 mins) with 3.2 miles to go over a hill and was wondering whether I would managed to finish in under 34 hours, I got in to the school at the end just as the church bell was chiming. =)

I was going to go for a Marvin like approach to this post (i.e. "The first twenty miles were the worst. The second twenty, they were the worst too. After that I went into a bit of a decline...") but I changed my mind at about 80 miles round the route when I got into a checkpoint where they happened to be playing "I’m Gonna Be (500 Miles)" as I left and it stayed in my head for a while and I decided it would make a good title.
You can listen to the whole song on the Proclaimer's site here (Track 4 under "The Best Of...") although unfortunatley you have to have Real Player (or Windows Media Player Classic).

Anyway, onto the actual walk. I promise I will get photos up when they are developed (I wasn't the one taking the photos) and I will then scan my certificate too.
The start was fairly easy and pretty fast, I did 8.12 miles in an hour and 50 minutes, ariving at the first checkpoint 10 minutes before they were allowed to let people through. From then on it got a bit slower although until the fourth check point at thirty miles it was reasonably fast going. After that the route went over Windy Gile among other bumps along the Cheviot ridge which slowed things down a little bit, however props to the mountain rescue who were on checkpoint duty there between 6 in the evening and 6 in the morning (on a bloody windy and cold ridge). I got down off the hills and into the next checkpoint just as it got dark and I spent a good twenty minutes there equiping myself with a torch and easting cheese pastys. Then we went up over a marilyn which my dad was very annoyed he had not yet been over and the Marshals walk skirted around (however he took some time to go up it as he was sweeping the route). It got light eventually and I got to my preakfast point which was great. Just after breakfast I slowed to a crawl but eventually sped up about five miles later just in time to avoid getting lost where the route description was rather vauge.
The 10th last to the 3rd last miles weren't great as they were pretty much entirely on roads. =(
I did survive though and manage to do over 4 miles an hour at the end to get into the finish in a pretty good time.

My mum also drove around the route and walked along with me or some stretchs which was nice and gave me someone to talk to (though I talked to random other walkers that I happened to be walking by).
I was the only 18 year old to take part (the average entrant is about 50) although there were a couple of other guys below twenty (one of him had his 19th birthday two days beforehand).

Anyhow I'm glad its over and I've no idea how I got talked into doing something so stupid.

Friday, May 26, 2006

Its a long way to Tipperary

Yeah, well the title doesn't have a lot to do with the post but anyhow. This time tomorrow I should be starting on the stroll I'm going on. I'm hoping it won't take too long, I'm looking at around 36 hours (30 hours walking, 6 hours stopping at checkpoints etc). The weather isn't looking great, I suspect I'll be pretty wet by the end, not that I'll really notice it at that point.
My dad completed this walk in 28 hours a few weeks ago under tougher conditions but he has done 22 of them before...

I have now seen up to the end of season 2 of LOST, which as I predicted leaves a lot of questions, although you can answer a few of them by looking at the Hanso Foundation site. There are a few interesting sites and e-mail addresses connected to it (doing WHOIS etc) but so far they haven't yielde anything of interest.

In other news: finishing work on Wednesday, not seen X3 yet.