start work on debian on android tutorial
[www.git] / tutorials / debian_on_samsung_galaxy.shtml
1 <!--#include virtual="/doctype.txt"-->
2 <html>
3
4 <!--#include virtual="/head.shtml"-->
5
6 <body>
7
8 <!--#include virtual="/header.shtml"-->
9
10 <!--#include virtual="/navigation.shtml"-->
11
12 <div id="content">
13
14 <!--
15
16 NOTE TO SELF:
17
18 When updating this page, be sure to update the "Last Updated" field below,
19 AND on the tutorials index page!
20
21 -->
22
23 <h1>Installing Debian GNU/Linux in a chroot on a Samsung Galaxy S II</h1>
24 <p><em>(Last updated 2011-11-25)</em></p>
25
26 <p>
27 There are numerous how-tos on the web for installing a Debian chroot onto
28 a smartphone running Android, but most of them either give you an image
29 to install on your phone (which doesn't teach you anything) or have you
30 set up the Debian system on your desktop and copy it to the phone.
31 Neither of these options appeal to me, so I've done it my own way and
32 written this document to light the way for others, too.
33 </p>
34
35 <p>
36 Assumptions made:
37 </p>
38
39 <ul>
40 <li>
41 You have an Android smartphone with access to a root shell via SSH. I run
42 <a href="http://www.cyanogenmod.com/">CyanogenMod 7.1</a> on my Galaxy S
43 II, but any Android system with root SSH access will do.
44 </li>
45 <li>
46 You have a basic understanding of Debian and its packaging system. This
47 procedure does require manual invocation of <tt>dpkg</tt> if you run into
48 problems -- if you don't know what <tt>dpkg</tt> is or how to use it,
49 this method probably isn't for you.
50 </li>
51 </ul>
52
53 <p>
54 If not all of these assumptions are true, please don't contact me if
55 something doesn't go right for you when following this how-to.
56 </p>
57
58 <h2>Preparation</h2>
59
60 <p>
61 The first thing you need to do is install <tt>cdebootstrap</tt> on your
62 phone. <tt>cdebootstrap</tt> is a tool for bootstrapping a Debian system,
63 usually from another Debian system, but in this case we'll be doing it
64 from Android.
65 </p>
66
67 <p>
68 So, to install <tt>cdebootstrap</tt>:
69 </p>
70
71 <ul>
72 <li>
73 Download the <a href="http://packages.debian.org/sid/cdebootstrap-static">cdebootstrap-static</a>
74 package for your architecture. Both armel and armhf packages should work
75 on recent Android phones; if you have an older phone, you may need to
76 stick with armel. I'll be using armhf in this tutorial, but you are free
77 to choose whichever architecture suits you best.
78 </li>
79 <li>
80 Now, copy the files needed for <tt>cdebootstrap</tt> to work across to
81 the phone. It doesn't matter where you put them, as long as you can
82 execute the <tt>cdebootstrap</tt> binary -- so don't put it in
83 <tt>/mnt/sdcard</tt>, as this is mounted with the <tt>noexec</tt> mount
84 option. These files are nicely ready for us in a tarball located at
85 <tt>./usr/lib/cdebootstrap/cdebootstrap_0.5.8+b1_armhf.tar.gz</tt> inside
86 the package, so you can just pipe the contents of this tarball to ssh and
87 extract it on the phone. I'm going to put it into
88 <tt>/data/local/bin/</tt>, because that's already in the default
89 <tt>$PATH</tt> so I don't have to care about it again.
90 <code>
91 $ mkdir /tmp/cdebootstrap && cd /tmp/cdebootstrap
92 $ ar x /path/to/cdebootstrap-static_0.5.8+b1_armhf.deb data.tar.gz
93 $ tar xzOf data.tar.gz ./usr/lib/cdebootstrap/cdebootstrap_0.5.8+b1_armhf.tar.gz | ssh root@$PHONE 'tar xz -C /data/local/bin/'
94 </code>
95 Obviously, replace <tt>$PHONE</tt> with the hostname of your phone.
96 </li>
97 </ul>
98
99 <h2>Bootstrapping the Debian system</h2>
100
101 <p>
102 Now that you have a working <tt>cdebootstrap</tt> on your phone, you can
103 use it to bootstrap Debian. First, however, you will need to create a
104 file system for Debian to live on. It may be possible to create such a
105 file system directly on the SD card, but as I don't really understand
106 Android partitioning, I decided not to try this and risk losing data. (If
107 someone knows of a way to do this, please
108 <a href="about.shtml">contact me</a> and let me know!) The reason you
109 need a separate file system for Debian is that Android mounts its own
110 file systems with options like <tt>noexec</tt>, which would disallow
111 executing all binaries placed on them (thus defeating the purpose of an
112 operating system).
113 </p>
114
115 <p>
116 The easiest way to set up a file system is to simply create a file in
117 <tt>/mnt/sdcard</tt> and format that -- but beware, if you make this file
118 larger than 2 GiB, the FAT file system it lives on will complain and you
119 will lose the image next time you reboot. This happened to me the first
120 time I tried it, and I hadn't made a backup, so I had to do it all over
121 again. :(
122 </p>
123
124 <p>
125 So, ssh to your phone, and run the following commands:
126 </p>
127
128 <code>
129 # dd if=/dev/zero of=/mnt/sdcard/debian.img bs=1024 count=2000000
130 # mke2fs -Fj /mnt/sdcard/debian.img
131 # mkdir /debian
132 # mount -t ext3 -o noatime,errors=remount-ro /mnt/sdcard/debian.img /debian
133 </code>
134
135 <p>
136
137 </p>
138
139 </div>
140
141 <!--#include virtual="/footer.shtml"-->
142
143 </body>
144
145 </html>