View Single Post
Old 05-19-2017, 03:38 PM   #1
theol0403
Enthusiast
theol0403 is faster than a rolling 'o,' stronger than silent 'e,' and leaps capital 'T' in a single bound!theol0403 is faster than a rolling 'o,' stronger than silent 'e,' and leaps capital 'T' in a single bound!theol0403 is faster than a rolling 'o,' stronger than silent 'e,' and leaps capital 'T' in a single bound!theol0403 is faster than a rolling 'o,' stronger than silent 'e,' and leaps capital 'T' in a single bound!theol0403 is faster than a rolling 'o,' stronger than silent 'e,' and leaps capital 'T' in a single bound!theol0403 is faster than a rolling 'o,' stronger than silent 'e,' and leaps capital 'T' in a single bound!theol0403 is faster than a rolling 'o,' stronger than silent 'e,' and leaps capital 'T' in a single bound!theol0403 is faster than a rolling 'o,' stronger than silent 'e,' and leaps capital 'T' in a single bound!theol0403 is faster than a rolling 'o,' stronger than silent 'e,' and leaps capital 'T' in a single bound!theol0403 is faster than a rolling 'o,' stronger than silent 'e,' and leaps capital 'T' in a single bound!theol0403 is faster than a rolling 'o,' stronger than silent 'e,' and leaps capital 'T' in a single bound!
 
Posts: 37
Karma: 50278
Join Date: Feb 2017
Device: Kindle PW3
Debian on modern kindles with pre-built qemu and debian image, scripts, desktop

Hello, this is my first big post. I have been lurking for awhile, and have gone and tried everything on this forum. When I started, I didn't know anything about linux, coding, or debian. Now, after a year, I know a lot more. I will release a couple tutorials in the future about stuff I learned, giving back to this forum.

One of the many things that I couldn't do at first is get debian on my kindle. However, finally I figured it out. Now I have a fully functional desktop on my kindle =).
All this information you can find on this forum, but here it is consolidated. These are all the tips that if I had In the beginning, when I didn’t know everything, I could have done a lot earlier. The only tutorial you will need for setting up debian is https://wiki.mobileread.com/wiki/Deb...n_Kindle_Touch
I will copy much from there, but add a couple steps. I have attached the completed product (debian image) of this whole post, but I will explain the process.
You will need a jailbroken kindle with usbnet.

1. Setup qemu with an armel system
Spoiler:
Ok. Here is my setup. My computer is windows, with a lubuntu virtual machine. Within that I have a qemu virtual machine emulating the same processor of the kindle (armv7; armel).

You will need an ubuntu or lubuntu (or debian) installation (probably in vmware) on your computer.

The first thing I did was try to use only ubuntu to debootstrap, but I was having errors with when I chrooted in the kindle. I got
Code:
FATAL: KERNEL TOO OLD.
Now I know how to fix that, but when I tried recently with bootstrapping in ubuntu, I was having problems with apt on my kindle.

What works for me is bootstrapping natively in the qemu, where it sets everything up without error. I also can compile and build in that qemu, so it is worth setting up.
Here is a VERY useful tutorial on how to set up qemu for armel, but I was having problems with the EXTREME wait time in installing debian onto it (internet failing and having to completely restart the process).
https://gist.github.com/Liryna/10710751#install-qemu


So what I ended up doing is using a pre-built image made from some random site, which I think was done with the exact process as the tutorial. Here are the links for the prebuilt image.
https://people.debian.org/~aurel32/qemu/armel/
We will want the debian_wheezy_armel_standard.qcow2 with the initrd.img-3.2.0-4-versatile and the vmlinuz-3.2.0-4-versatile.

STEP 1:
In your ubuntu system, create a folder for qemu. Then navigate to it in a terminal and wget these three files. (command is wget <file>).
Type “sudo apt-get install qemu” to install qemu
Then, launch the following command.

Code:
qemu-system-arm -M versatilepb -kernel vmlinuz-3.2.0-4-versatile -initrd initrd.img-3.2.0-4-versatile -hda debian_wheezy_armel_standard.qcow2 -append "root=/dev/sda1" -redir tcp:2222::22
You can put it in a script for easy access. (to do this type “nano <script name>.sh”. Paste the command. Exit (ctrl-x). Then enter “chmod +x <script name.sh>” to let you run it in the terminal).

Logins:
user = root
password = root

Now you have a full debian wheezy system with the same processor as the kindle! Files you compile with gcc will work on the kindle.


NOTE: It may come that your kernel will be updated. Notably this will give you errors with mounting, with the system not knowing what ext3 is. To fix this close qemu and run "extractkernel.txt" (sh extractkernel.txt). This will update the kernels. To see that this works look in your qemu folder and you will see much more files.

Because you typed “-redir tcp:2222::22”, you can ssh into the qemu system, so that you can do stuff such as copy and paste.
To do this type
Code:
ssh -p 2222 root@localhost
in a new terminal window.

Also, you can navigate the qemu filesystem by typing these commands:
Code:
apt-get install sshfs
mkdir qemumount
sshfs -p 2222 root@localhost:/ ./qemumount/
Now you can browse the filesystem inside qemumount


2. debootstrapping an debian image in qemu

First, you want to find out how much space you have on the kindle. I often find that I run out of space in debian, so always have the largest debian installation possible.
Code:
Type “df” on the kindle
Scroll up, and look for /mnt/us
Under available, look at the amount of space available. Divide by 1000
Now in the following command under the count, type in a bit less than that number. 
A good size is 1700 (1.7 GB).
DEBOOTSTRAP IN QEMU:
Spoiler:
This is not too different from the wiki debian tutorial.


In the qemu system, type:

Code:
dd if=/dev/zero of=/tmp/debian.ext3 bs=1M count=<SIZE WANTED THAT WILL FIT ON KINDLE>
mkfs.ext3 /tmp/debian.ext3
tune2fs -i 0 -c 0 /tmp/debian.ext3
mkdir /mnt/debian/
mount -o loop -t ext3 /tmp/debian.ext3 /mnt/debian
Next, you will fill that container. Type
Code:
apt-get install debootstrap
debootstrap --variant=minbase --arch=armel jessie /mnt/debian http://ftp.us.debian.org/debian
You will have to wait awhile.
NOTE: there are two variations from the wiki tutorial.
One: --variant=minbase will really reduce the size of the installation.
Two: instead of “testing” I put “jessie”. This is because now, testing is the sid (stretch) release, which says FATAL: KERNEL TOO OLD when you chroot on the kindle.
Jessie is the last release that supports the kindle kernel.

Unmount the image by typing:
Code:
umount /mnt/debian/
Now copy the image in /tmp/debian.ext3 to your computer (you can find it in qemumount)



NOTE: Attached is the image up to this step!!! It is smalldebian.ext3
This file is the bare minimum container size, being only 200 MB. In order to increase the size of your debian installation, follow these steps:

Code:
in ubuntu, type 
dd if=/dev/zero of=debian.ext3 bs=1M count=<SIZE WANTED THAT WILL FIT ON KINDLE>
mkfs.ext3 debian.ext3
tune2fs -i 0 -c 0 debian.ext3
sudo mkdir /mnt/debian/
sudo mkdir /mnt/smalldebian/
sudo mount -o loop -t ext3 debian.ext3 /mnt/debian/
sudo mount -o loop -t ext3 smalldebian.ext3 /mnt/smalldebian/
sudo cp -r /mnt/smalldebian/* /mnt/debian/
sudo umount /mnt/debian/
sudo umount /mnt/smalldebian/
now debian.ext3 has the contents of smalldebian.ext3 but with a larger container (potential space)



STEP 3: copy the image to kindle.


IMPORTANT: Copy the image to /mnt/base-us/ . this is to stop hangups and bricks.

STEP 4: Chroot into debian

Attached is the “chrootdebian.txt” file. Copy this to the kindle’s /mnt/us/
Turn on wifi
Now on the kindle type
Code:
 sh /mnt/us/chrootdebian.txt
You now have a working debian environment!!!

SECTION 2:--------------------------------------------

Setting up debian and installing a desktop environment.

I have made a script that installs the system described here:
https://www.mobileread.com/forums/sh...52&postcount=5


Explaining install script - you can skip:
Spoiler:

PART 1:
I will tell you how to fix some issues in debian, and install the basics, if you only want debian for building, coding, and compiling.

One error that keeps coming up is a LANG error. To fix this type the following in a chroot:
Code:
apt-get -y install locales; sed -i '/en_US.UTF-8/s/^#//' /etc/locale.gen; locale-gen en_US.UTF-8
Also to stop apt from installing unwanted software and using space, type this:

Code:
echo APT::Install-Recommends "0" ; APT::Install-Suggests "0"; >> /etc/apt/apt.conf

Also some basics to install is:

Code:
apt-get install sudo psmisc wget nano
PART 2: Installing the matchbox-desktop interface.
I will provide a run-through of the steps included, but then provide a script that installs everything.

Download everything in http://dosowisko.net/kindle/debian/ to a folder in the chroot. This folder is attached (matchbox-dos.zip)
In that folder type in the following to install dos’s hacks:
Code:
dpkg -i *.deb;apt-get -y install -f
cp gtkrc.Moko /usr/share/themes/Moko/gtk-2.0/
rm /usr/share/themes/Moko/gtk-2.0/gtkrc
mv /usr/share/themes/Moko/gtk-2.0/gtkrc.Moko /usr/share/themes/Moko/gtk-2.0/gtkrc
tar xzf ffportraitdos.tar.gz -C /usr/share/themes/
cp gtkrc /etc/gtk-2.0/
cp start-x /usr/bin/
chmod +x /usr/bin/start-x
cp startx-flipped /usr/bin/
chmod +x /usr/bin/startx-flipped
cp stop-x /usr/bin/
chmod +x /usr/bin/stop-x
mkdir /usr/share/applications/
cp stopx.desktop /usr/share/applications/
cp session /etc/matchbox/
chmod +x /etc/matchbox/session
type start-x
A desktop environment should launch


NOTE: In start-x there is the script to start the desktop environment. It starts a xephyr server over top on the current ui. Change the resolution to fit you kindle.

PART 3:

I have provided a script that does all the above steps smoothly (including fixing the locales and installing stuff)
To run copy matchbox-dos.zip and installdebian.txt to kindle /mnt/us/
NOTE: this is NOT done inside a chroot, debian needs to be unmounted
Then execute installdebian.txt ( sh /mnt/us/installdebian.txt)
It will do everything for you.

After installing you will find some files on /mnt/us/
chroot.sh is for opening a shell into an already mounted debian system.
The launch-debian files mount debian and directly starts the desktop environment.
Use the attached chrootdebian.txt (sh) file to mount and chroot debian.


Summary:

If you encounter any problems please report and if you need help with anything please ask.
Any feedback welcome.
Good Luck.

smalldebian.ext3 links:
https://mega.nz/#!4mwkzZza!V7H4EwYMTJHkNxYk8s7HdXybkQyMj1ula69nBsm CtKo

http://mir.cr/1V0UD2WN
Attached Files
File Type: txt chrootdebian.txt (734 Bytes, 413 views)
File Type: txt extractkernel.txt (240 Bytes, 406 views)
File Type: zip matchbox-dos.zip (930.8 KB, 312 views)
File Type: txt installdebian.txt (2.1 KB, 368 views)

Last edited by theol0403; 08-24-2017 at 06:06 PM. Reason: I realized that after installation you had no tools to launch debian
theol0403 is offline   Reply With Quote