Created
July 29, 2014 02:44
-
-
Save luftreich/1ffb9c8a2cb81741721d to your computer and use it in GitHub Desktop.
Debian on Android/Atrix with Debootstrap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://fooprotected.wordpress.com/2012/04/02/debian-on-androidatrix-with-debootstrap/ | |
Debian on Android/Atrix with Debootstrap | |
April 2, 2012deathjest3rLeave a commentGo to comments | |
The Story | |
I have bought a new Smartphone. No, not the new and shiny Samsung Galaxy Nexus. An already a little bit older model, but still one of the most powerful devices out there, and a lot cheaper then the Galaxy Nexus, the Motorola Atrix 4G. My Nokia N900 served me well for the past 1.5 years, but now it was time for me to jump on the train called Android. But with my new Smartphone I don’t wanted to lose the possibility to use all my favorite Unix tools (e.g. SSH, SCP, RSYNC, etc.). So I decided to search for a guide on how to install Debian on Android. I found a lot, but non of them directly addressed on how to install Debian on Android/Atrix. So I decided to write a short guide for all the Atrix owners out there. | |
Rooting the Atrix | |
Before you start with the guide on how to install Debian you have to root your phone, otherwise this tutorial is useless for you. There are plenty of tutorials on how to do that, just bug google with “root atrix”. In other words, here I will not explain how to root your phone. | |
Debian Image | |
First of all we have to build a Debian image file, which we store on the Atrix to chroot into later. Just follow these steps to create an image. The parameter seek=xxxx defines the size of your chroot, so if you have enough space on your phone you can also create a bigger image. The command below will create a 800MB Debian image. | |
sudo -s | |
apt-get install debootstrap | |
dd if=/dev/zero of=debian.img seek=838860800 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.us.debian.org/debian | |
umount debian/ | |
rm -r debian/ | |
The debootstrap command will take some time, because it basically downloads the whole OS from the Debian FTP server. | |
Bootdebian | |
On the Web I found a script to boot Debian on your phone, but for my Atrix it didn’t work out of the box. So I changed it to fit the Atrix’s system structure. | |
if [ $EUID -ne 0 ] | |
then | |
echo "Becoming ROOT!" | |
su -c bootdebian | |
exit 1 | |
fi | |
echo "Mounting system as R/W" | |
mount -o remount,rw -t ext3 /dev/block/mmcblk0p12 /system | |
echo "Setting some stuff up.." | |
export bin=/system/bin | |
export img=/mnt/sdcard-ext/debian.img | |
export mnt=/data/local/debian | |
export PATH=$bin:/usr/bin:/usr/sbin:/bin:$PATH | |
export TERM=linux | |
export HOME=/root | |
if [ ! -d $mnt ]; then | |
mkdir $mnt | |
fi | |
echo "Mounting the Linux Image" | |
losetup /dev/block/loop5 $img | |
mount -t ext2 -o noatime,nodiratime /dev/block/loop5 $mnt | |
mount -t devpts devpts $mnt/dev/pts | |
mount -t proc proc $mnt/proc | |
mount -t sysfs sysfs $mnt/sys | |
echo "Setting Up Networking" | |
sysctl -w net.ipv4.ip_forward=1 | |
echo "nameserver 8.8.8.8" > $mnt/etc/resolv.conf | |
echo "nameserver 8.8.4.4" >> $mnt/etc/resolv.conf | |
echo "127.0.0.1 localhost" > $mnt/etc/hosts | |
echo "Mounting sdcard and emmc in /mnt" | |
if [ ! -d $mnt/mnt/sdcard ]; then | |
mkdir $mnt/mnt/sdcard | |
fi | |
/system/xbin/busybox mount --bind /mnt/sdcard $mnt/mnt/sdcard | |
if [ ! -d $mnt/mnt/sdcard-ext ]; then | |
mkdir $mnt/mnt/sdcard-ext | |
fi | |
/system/xbin/busybox mount --bind /mnt/sdcard-ext/ $mnt/mnt/sdcard-ext | |
echo "Entering CHROOT " | |
echo " " | |
chroot $mnt /bin/bash | |
echo " " | |
echo "Shutting down CHROOT" | |
umount $mnt/mnt/sdcard | |
umount $mnt/mnt/sdcard-ext | |
sysctl -w net.ipv4.ip_forward=0 | |
umount $mnt/dev/pts | |
umount $mnt/proc | |
umount $mnt/sys | |
umount $mnt | |
losetup -d /dev/block/loop5 | |
mount -o remount,ro -t ext3 /dev/block/mmcblk0p12 /system | |
Copy the quoted text and save it to the root folder of the internal memory of the Atrix (/sdcard) with the name | |
bootdebian | |
It’s important to keep the name, otherwise the first command where the script checks if you’re root will fail. Now start the terminal application of your choice on the Atrix. I use the Better Terminal Emulator (I think its worth the price for only 2.99). Start the second stage of the debootstrap process by typing the following text. | |
su | |
mount -o remount,rw -t ext3 /dev/block/mmcblk0p12 /system | |
cat /sdcard/bootdebian > /system/xbin/bootdebian | |
rm /sdcard/bootdebian | |
chmod 777 /system/xbin/bootdebian | |
bootdebian | |
/debootstrap/debootstrap --second-stage | |
echo 'deb http://ftp.us.debian.org/debian lenny main' > /etc/apt/sources.list | |
apt-get autoclean | |
apt-get update | |
exit | |
Now thats it, From now on you can call bootdebian when ever you need access to your Chroot. You can install everything with apt-get, the same as on you Desktop machine or Laptop. | |
Have Fun! | |
Debian on Android/Atrix with Debootstrap (Part II) | |
July 16, 2012deathjest3rLeave a commentGo to comments | |
When running Debian on Android in a chroot, you are bind to a Shell, but if you want a graphical user-interface to have a more comfortable usage experience you can also install a VNC server in the chroot and connect to it from the Android host system. This tutorial is an extension to my already published tutorial because someone asked me if I can write a little bit more on how to get the VNC Server to run. Here it is: | |
Follow my first tutorial (here) | |
Start the chroot environment | |
Before you execute the commands below keep the following things in mind, | |
You need around 38MBytes of free storage in your chroot | |
When first starting the vncserver you need to specify a password (Remember it!) | |
Now execute the commands to install the vnc server and a lightweight X-Window setup | |
aptitude install –without-recommends lxde tightvncserver xfonts-base | |
export USER=root | |
vncserver -geometry 960×540 | |
Switch back to Android and install the android-vnc-viewer | |
Start the app and put in the following settings: | |
Nickname: *Whatever* | |
Password: -the-vncserver-password-you-defined-before- | |
Address: localhost | |
Port: 5901 | |
Username: -empty- | |
Color Format: 24-bit color (4bpp) | |
Make sure you set the port to 5901 not the default (5900). | |
You are done. With these steps you should be able to connect to the running VNC server inside the chroot. | |
Finally, here is a photo of my Atrix running LXDE: | |
http://fooprotected.wordpress.com/2012/07/16/debian-on-androidatrix-with-debootstrap-part-ii/ | |
Debian on Android/Atrix with Debootstrap (Part III) | |
July 22, 2012deathjest3rLeave a commentGo to comments | |
As an extension to my previous post I will now explain how to make all the stuff persistent. You then do not need to retype the whole stuff to start the VNCServer every time you restart your phone. Just put the following script into the folder /etc/init.d/ of your chroot: | |
#!/bin/sh | |
export HOME=”/root” | |
export USER=”/root” | |
STARTCMD=”vncserver -geometry 960×540″ | |
STOPCMD=”vncserver -kill :1″ | |
case $1 in | |
start) | |
if [ -e /tmp/.X1-lock ]; then | |
echo “VNCServer already running” | |
else | |
$STARTCMD | |
fi | |
;; | |
stop) | |
$STOPCMD | |
;; | |
restart) | |
$STOPCMD | |
$STARTCMD | |
;; | |
*) | |
echo “$0 start|stop|restart” | |
exit 1 | |
;; | |
esac | |
exit 0 | |
Afterwards you are able to start and stop the VNCServer, with the commands | |
service vncserver start | |
and | |
service vncserver stop | |
This allows starting, stopping and restarting the server. | |
To actually start the server when you switch into your chroot, you have to autostart it. The following way is not best practice (don’t let a Linux guru know ;-)). But for us it is working: | |
echo “service vncserver start” >> /root/.bashrc | |
or (when you don’t want to get the “VNCServer started…” message everytime you log into your chroot) | |
echo “service vncserver start > /dev/null 2>&1″ >> /root/.bashrc | |
When you call “bootdebian” in your shell, the VNCServer will automatically start and you can connect to it via your favorite VNCClient. | |
Have fun! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment