1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Run Debian on your phone with Debroid</title>
<link rel="shortcut icon" type="image/gif" href="/favicon.ico" />
<link rel="stylesheet" href="../style.css" />
<link rel="stylesheet" href="style-override.css" />
</head>
<body>
<p class="header">
<a href="https://foo.zone">Home</a> | <a href="https://codeberg.org/snonux/foo.zone/src/branch/content-md/gemfeed/2015-12-05-run-debian-on-your-phone-with-debroid.md">Markdown</a> | <a href="gemini://foo.zone/gemfeed/2015-12-05-run-debian-on-your-phone-with-debroid.gmi">Gemini</a>
</p>
<h1 style='display: inline' id='run-debian-on-your-phone-with-debroid'>Run Debian on your phone with Debroid</h1><br />
<br />
<span class='quote'>Published at 2015-12-05T16:12:57+00:00; Updated at 2021-05-16</span><br />
<br />
<span>You can use the following tutorial to install a full-blown Debian GNU/Linux Chroot on an LG G3 D855 CyanogenMod 13 (Android 6). First of all, you need to have root permissions on your phone, and you also need to have the developer mode activated. The following steps have been tested on Linux (Fedora 23).</span><br />
<br />
<a href='./run-debian-on-your-phone-with-debroid/Deboroid.png'><img src='./run-debian-on-your-phone-with-debroid/Deboroid.png' /></a><br />
<br />
<span>A couple of years have passed since I last worked on Debroid. Currently, I am using the Termux app on Android, which is less sophisticated than a fully blown Debian installation but sufficient for my current requirements. The content of this site may be still relevant, and it would also work with more recent versions of Debian and Android. I would expect that some minor modifications need to be made, though. </span><br />
<br />
<pre>
____ _ _ _
| _ \ ___| |__ _ __ ___ (_) __| |
| | | |/ _ \ '_ \| '__/ _ \| |/ _` |
| |_| | __/ |_) | | | (_) | | (_| |
|____/ \___|_.__/|_| \___/|_|\__,_|
</pre>
<br />
<h2 style='display: inline' id='table-of-contents'>Table of Contents</h2><br />
<br />
<ul>
<li><a href='#run-debian-on-your-phone-with-debroid'>Run Debian on your phone with Debroid</a></li>
<li>⇢ <a href='#step-by-step-guide'>Step by step guide</a></li>
<li>⇢ ⇢ <a href='#first-debootstrap-stage'>First debootstrap stage</a></li>
<li>⇢ ⇢ <a href='#copy-debian-image-to-the-phone'>Copy Debian image to the phone</a></li>
<li>⇢ ⇢ <a href='#second-debootstrap-stage'>Second debootstrap stage</a></li>
<li>⇢ ⇢ <a href='#setup-of-various-scripts'>Setup of various scripts</a></li>
<li>⇢ ⇢ <a href='#entering-debroid-and-enable-a-service'>Entering Debroid and enable a service</a></li>
<li>⇢ ⇢ <a href='#include-to-android-startup'>Include to Android startup:</a></li>
</ul><br />
<h2 style='display: inline' id='step-by-step-guide'>Step by step guide</h2><br />
<br />
<span>All scripts mentioned here can be found on GitHub at:</span><br />
<br />
<a class='textlink' href='https://codeberg.org/snonux/debroid'>https://codeberg.org/snonux/debroid</a><br />
<br />
<h3 style='display: inline' id='first-debootstrap-stage'>First debootstrap stage</h3><br />
<br />
<span>This is to be performed on a Fedora Linux machine (could work on a Debian too, but Fedora is just what I use on my Laptop). The following steps prepare an initial Debian base image, which can then be transferred to the phone.</span><br />
<br />
<!-- Generator: GNU source-highlight 3.1.9
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre>sudo dnf install debootstrap
<i><font color="silver"># 5g</font></i>
dd <b><u><font color="#000000">if</font></u></b>=/dev/zero of=jessie.img bs=$[ <font color="#000000">1024</font> * <font color="#000000">1024</font> ] \
count=$[ <font color="#000000">1024</font> * <font color="#000000">5</font> ]
<i><font color="silver"># Show used loop devices</font></i>
sudo losetup -f
<i><font color="silver"># Store the next free one to $loop</font></i>
loop=loopN
sudo losetup /dev/$loop jessie.img
mkdir jessie
sudo mkfs.ext4 /dev/$loop
sudo mount /dev/$loop jessie
sudo debootstrap --foreign --variant=minbase \
--arch armel jessie jessie/ \
http://http.debian.net/debian
sudo umount jessie
</pre>
<br />
<h3 style='display: inline' id='copy-debian-image-to-the-phone'>Copy Debian image to the phone</h3><br />
<br />
<span>Now setup the Debian image on an external SD card on the Phone via Android Debugger as follows:</span><br />
<br />
<!-- Generator: GNU source-highlight 3.1.9
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre>adb root && adb wait-for-device && adb shell
mkdir -p /storage/sdcard<font color="#000000">1</font>/Linux/jessie
<b><u><font color="#000000">exit</font></u></b>
<i><font color="silver"># Sparse image problem, may be too big for copying otherwise</font></i>
gzip jessie.img
<i><font color="silver"># Copy over</font></i>
adb push jessie.img.gz /storage/sdcard<font color="#000000">1</font>/Linux/jessie.img.gz
adb shell
cd /storage/sdcard<font color="#000000">1</font>/Linux
gunzip jessie.img.gz
<i><font color="silver"># Show used loop devices</font></i>
losetup -f
<i><font color="silver"># Store the next free one to $loop</font></i>
loop=loopN
<i><font color="silver"># Use the next free one (replace the loop number)</font></i>
losetup /dev/block/$loop $(pwd)/jessie.img
mount -t ext4 /dev/block/$loop $(pwd)/jessie
<i><font color="silver"># Bind-Mound proc, dev, sys`</font></i>
busybox mount --bind /proc $(pwd)/jessie/proc
busybox mount --bind /dev $(pwd)/jessie/dev
busybox mount --bind /dev/pts $(pwd)/jessie/dev/pts
busybox mount --bind /sys $(pwd)/jessie/sys
<i><font color="silver"># Bind-Mound the rest of Android</font></i>
mkdir -p $(pwd)/jessie/storage/sdcard{<font color="#000000">0</font>,<font color="#000000">1</font>}
busybox mount --bind /storage/emulated \
$(pwd)/jessie/storage/sdcard<font color="#000000">0</font>
busybox mount --bind /storage/sdcard<font color="#000000">1</font> \
$(pwd)/jessie/storage/sdcard<font color="#000000">1</font>
<i><font color="silver"># Check mounts</font></i>
mount | grep jessie
</pre>
<br />
<h3 style='display: inline' id='second-debootstrap-stage'>Second debootstrap stage</h3><br />
<br />
<span>This is to be performed on the Android phone itself (inside a Debian chroot):</span><br />
<br />
<!-- Generator: GNU source-highlight 3.1.9
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre>chroot $(pwd)/jessie /bin/bash -l
<b><u><font color="#000000">export</font></u></b> PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin
/debootstrap/debootstrap --second-stage
<b><u><font color="#000000">exit</font></u></b> <i><font color="silver"># Leave chroot</font></i>
<b><u><font color="#000000">exit</font></u></b> <i><font color="silver"># Leave adb shell</font></i>
</pre>
<br />
<h3 style='display: inline' id='setup-of-various-scripts'>Setup of various scripts</h3><br />
<br />
<span>jessie.sh deals with all the loopback mount magic and so on. It will be run later every time you start Debroid on your phone.</span><br />
<br />
<!-- Generator: GNU source-highlight 3.1.9
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><i><font color="silver"># Install script jessie.sh</font></i>
adb push storage/sdcard<font color="#000000">1</font>/Linux/jessie.sh /storage/sdcard/Linux/jessie.sh
adb shell
cd /storage/sdcard<font color="#000000">1</font>/Linux
sh jessie.sh enter
<i><font color="silver"># Bashrc</font></i>
cat <<END >~/.bashrc
<b><u><font color="#000000">export</font></u></b> PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH
<b><u><font color="#000000">export</font></u></b> EDITOR=vim
hostname $(cat /etc/hostname)
END
<i><font color="silver"># Fixing an error message while loading the profile</font></i>
sed -i s<i><font color="silver">#id#/usr/bin/id# /etc/profile</font></i>
<i><font color="silver"># Setting the hostname</font></i>
echo phobos > /etc/hostname
echo <font color="#000000">127.0</font>.<font color="#000000">0.1</font> phobos > /etc/hosts
hostname phobos
<i><font color="silver"># Apt-sources</font></i>
cat <<END > sources.list
deb http://ftp.uk.debian.org/debian/ jessie main contrib non-free
deb-src http://ftp.uk.debian.org/debian/ jessie main contrib non-free
END
apt-get update
apt-get upgrade
apt-get dist-upgrade
<b><u><font color="#000000">exit</font></u></b> <i><font color="silver"># Exit chroot</font></i>
</pre>
<br />
<h3 style='display: inline' id='entering-debroid-and-enable-a-service'>Entering Debroid and enable a service</h3><br />
<br />
<span>This enters Debroid on your phone and starts the example service uptimed:</span><br />
<br />
<!-- Generator: GNU source-highlight 3.1.9
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre>sh jessie.sh enter
<i><font color="silver"># Setup example serice uptimed</font></i>
apt-get install uptimed
cat <<END > /etc/rc.debroid
<b><u><font color="#000000">export</font></u></b> PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH
service uptimed status &>/dev/null || service uptimed start
<b><u><font color="#000000">exit</font></u></b> <font color="#000000">0</font>
END
chmod <font color="#000000">0755</font> /etc/rc.debroid
<b><u><font color="#000000">exit</font></u></b> <i><font color="silver"># Exit chroot</font></i>
<b><u><font color="#000000">exit</font></u></b> <i><font color="silver"># Exit adb shell</font></i>
</pre>
<br />
<h3 style='display: inline' id='include-to-android-startup'>Include to Android startup:</h3><br />
<br />
<span>If you want to start Debroid automatically whenever your phone starts, then do the following:</span><br />
<br />
<!-- Generator: GNU source-highlight 3.1.9
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre>adb push data/local/userinit.sh /data/local/userinit.sh
adb shell
chmod +x /data/local/userinit.sh
<b><u><font color="#000000">exit</font></u></b>
</pre>
<br />
<span>Reboot & test! Enjoy!</span><br />
<br />
<span>E-Mail your comments to <span class='inlinecode'>paul@nospam.buetow.org</span> :-)</span><br />
<br />
<a class='textlink' href='../'>Back to the main site</a><br />
<p class="footer">
Generated with <a href="https://codeberg.org/snonux/gemtexter">Gemtexter 3.0.1-develop</a> |
served by <a href="https://www.OpenBSD.org">OpenBSD</a>/<a href="https://man.openbsd.org/relayd.8">relayd(8)</a>+<a href="https://man.openbsd.org/httpd.8">httpd(8)</a> |
<a href="https://foo.zone/site-mirrors.html">Site Mirrors</a>
<br />
Webring: <a href="https://shring.sh/foo.zone/previous">previous</a> | <a href="https://shring.sh">shring</a> | <a href="https://shring.sh/foo.zone/next">next</a>
</p>
</body>
</html>
|