View Single Post
Old 01-03-2021, 12:02 PM   #1
NiMa
Fanatic
NiMa ought to be getting tired of karma fortunes by now.NiMa ought to be getting tired of karma fortunes by now.NiMa ought to be getting tired of karma fortunes by now.NiMa ought to be getting tired of karma fortunes by now.NiMa ought to be getting tired of karma fortunes by now.NiMa ought to be getting tired of karma fortunes by now.NiMa ought to be getting tired of karma fortunes by now.NiMa ought to be getting tired of karma fortunes by now.NiMa ought to be getting tired of karma fortunes by now.NiMa ought to be getting tired of karma fortunes by now.NiMa ought to be getting tired of karma fortunes by now.
 
NiMa's Avatar
 
Posts: 507
Karma: 2390534
Join Date: Jun 2020
Location: Somewhere in the Universe
Device: Kobo Libra, Glo HD, Touch C/B, Mini, Glo, Aura SE, Clara HD, KT
Lightbulb [Xorg works!] [HOWTO] Create your own native development environment on your Kobo!

Hi,
It's been a while since I last posted, but now I think I have something to share with you. Those last months, I wasn't finding any interesting books to read and started to find my Kobo just ... boring. And I thought 'then maybe some hacking could be fun' and here I am with this guide. It will help you set up Alpine Linux with gcc, g++ or clang to develop custom applications for your Kobo. Then you could use them (if they are CLI apps) with https://github.com/llandsmeer/inkvt (thanks NiLuJe & Llandsmeer !). And now, you can run Xorg on it! (https://www.mobileread.com/forums/sh....php?p=4077882)
So, how ?
Prerequisites
1. A Kobo with a fair amount of free space (ideally 3GB+). Preferably with kernel >3.0, but maybe it'll work with older versions too, you just have to try! I tested with my Glo HD and Libra and both worked (Glo HD has 3.0.35, Libra has 4.1).
2. A computer (or something you can ssh/telnet with).
3. NiLuJe's stuff (not mandatory, but is very useful for SSH) https://www.mobileread.com/forums/sh...d.php?t=254214

Let's start!
1. First, enable devmode on your Kobo. Fairly easy; just "search" devmodeon in your Kobo's search bar. It will add some games to your "Beta features" menu, but more importantly, it will give us entire access to the Kobo via telnet.

2. Check what IP your Kobo is using by going to Settings/Technical information.

3. Tap the WiFi icon at the top of the screen and leave the menu open. It will disable "wifi sleep" which could disrupt our telnet access. Note: you can also set up usbnet from there and then telnet via USB, with no interruptions.

4. In a Linux terminal/Telnet-able machine, type "telnet <IP>". E.g.
Code:
telnet 192.168.0.183
Log in as root. There's no password.

5. Check your Linux kernel version by typing in "uname -r". If it is less than 3.0, you may encounter problems.

6. Change directory to /mnt/onboard:
Code:
cd /mnt/onboard
Here we will create a disk image. It's not possible to just dump a rootfs in the onboard partition because it is formatted in FAT32, and FAT32 doesn't like Linux very much (permission problems). So a disk image will help us circumvent this problem. Type in:
Code:
dd if=/dev/zero of=/mnt/onboard/alpine.img bs=1M count=2048
Note: the above command creates a 2G disk image. If your Kobo doesn't have the disk space required for that, you could change the "count" to 1024 or 512 for example, and you will get, respectively, a 1G and 512MB disk image.

7. Format the disk image. If your Kobo is from the future or has this capability, you *could* be able to format it in ext4 format natively by adding the "-t ext4" flag in the command line. However, mke2fs here only supports ext2, which is usable too, albeit older. So you could try to format a 2G image on your host system with an ext4 filesystem, then txz-compress it and extract it in your Kobo's storage. This didn't work in my Glo HD though, but did in my Libra. So we'll use the legacy way:
Code:
mke2fs -F /mnt/onboard/alpine.img
8. Mount the disk image. Here we'll use /mnt/user as a mountpoint, but you can mount it in another directory if you want.
Code:
mount /mnt/onboard/alpine.img /mnt/user
This should run without errors. Then, change directory to the mountpoint:
Code:
cd /mnt/user
and do a quick
Code:
df -h
to check if you see your mountpoint in the list, like that:
Code:
/dev/loop1                2047.7M     13.0K      2047.2M   0% /mnt/user
9. Ensure that your Kobo is connected to the Internet, then head over to https://alpinelinux.org/downloads/ and scroll down to the "Mini Root Filesystem" part, and right-click the green button with "armv7", then click on "Copy link location" or something like that.
On your Kobo:
Code:
cd /mnt/user && wget https://dl-cdn.alpinelinux.org/alpine/v3.12/releases/armv7/alpine-minirootfs-3.12.3-armv7.tar.gz
(where the link should be replaced with the latest version available)
This should get the tar archive with the Alpine Linux filesystem on your disk image.

10. On your Kobo, we'll now get the tar archive extracted. Ensure you're still on your SSH/Telnet session and type:
Code:
cd /mnt/user && tar -xvf alpine-minirootfs*.tar.gz
Where the wildcard (*) could be replaced with the actual name of the tar archive, but could also stay like that, because ash will automatically detect it if the prefix has not changed.

11. Prepare the chroot. Type in:
Code:
mount -v --bind /dev /mnt/user/dev
mount -v --bind /dev/pts /mnt/user/dev/pts
mount -vt proc proc /mnt/user/proc
mount -vt sysfs sysfs /mnt/user/sys
mount -vt tmpfs tmpfs /mnt/user/run
mount -vt tmpfs tmpfs /mnt/user/tmp
mkdir /mnt/user/dev/shm
mount -vt tmpfs tmpfs /mnt/user/dev/shm
cp /etc/resolv.conf /mnt/user/etc
This will bind your Kobo's existing /dev, /proc, /sys, /run contents to your Alpine Linux mounted disk image on /mnt/user. Therefore, you'll have greater flexibility when it comes to more hardware-based tasks or process monitoring. Also, we copy the resolv.conf file from the root filesystem to the Alpine disk image to be able to access the network from the chroot. You may need to re-copy this file later if your network info changes.

12. Chroot. Type in:
Code:
chroot /mnt/user /bin/sh
You should get in Alpine Linux. Congratulations !

13. Now, Alpine Linux comes with the holy grail: a package manager!, apk. First, try installing Nano:
Code:
apk add nano
If all goes well, you should be able to run it directly after, by simply typing in "nano". Isn't that great?

14. If you want to have a compiler, nothing is easier! Just type in:
Code:
apk add gcc g++
or you can install clang instead if you prefer it to gcc/g++. You should now be able to compile! I successfully compiled binutils yesterday and "file" this morning. It's slow, but usable and it works well! If you want to go further, you could build gcc/g++ with gcc/g++, to obtain a fully optimized compiler (three-stage process: https://gcc.gnu.org/install/build.html), but the default binary works well.

15. Well, it's done! If you reboot your Kobo, you can think of adding the disk image to /etc/fstab so it is automatically mounted at startup, and set up an init script which mounts /dev, /sys, /run, etc. automatically.

I hope you enjoyed this! Let me know if it worked for you and ask questions if you want!

For Xorg, go there:
https://www.mobileread.com/forums/sh....php?p=4077882

Disclaimer: I am not responsible if you brick your Kobo with this technique, or if you lose files.

Last edited by NiMa; 01-07-2021 at 02:56 PM.
NiMa is offline   Reply With Quote