úterý 5. srpna 2014

Kindle Paperwhite 2 JailBroken, rooted, and made to run Arch Linux


Procedure

Install JailBreak.

If you own Kindle Paperwhite 2, there is already prepacked solution for you. All you need to do is following:
  • Go at http://www.mobileread.com/forums/showpost.php?p=2658944 and download K5 JailBreak
  • In the downloaded file (You may need 7zip to open it) there will be file kindle-5.4-jailbreak.zip. Open it.
  • Connect Kindle with your computer using USB, and unpack files from kindle-5.4-jailbreak.zip into Kindle's root USB directory.
  • Unmount and disconnect Kindle
  • Go at Kindle homescreen, open Menu > Settings > Menu > Update Your Kindle
If everything went alright, you should see notification message at the bottom of the screen.
**** JAILBREAK ****

Install KUAL

You could go immediately for command line via SSH by installing USBNetwork Hack, but it is nice to have a few user friendly buttons. For that, download KUAL from the same page as the JailBreak, and copy KUAL-KDK-2.0.azw2 into the documents directory of Kindle's USB root. Now you will see Kindle Launcher among your e-books. If you run that, you will see a list of all registered apps.

Install kterm

Now we will actually acquire full Linux terminal. Kindle is already running Linux with Xserver, so we just need an app to access tty. One such app is kterm which you can acquire from http://www.fabiszewski.net/kindle-terminal/. All you need to do is to unpack the zip into the extensions directory of Kindle's USB root. Now when you run Kindle Launcher, you will see entry kterm. Once you click on it, you are the root of your own Kindle world.
But be careful, for with great power, comes great responsibility. It is really difficult to debrick Kindle with ruined filesystem.
Now you can use standard linux shell commands such as
  • cd <dir> to move into another directory
  • cd .. to move one directory level up
  • ls to list all files inside a directory
  • pwd to display current directory
  • cat <file> | more to display content of a file
  • vi to enter simple vi editor (which you can quit by typing :q!+Enter)
  • all the other Linux commands like dd, mount, ln, mv, cp, rm, top, kill, grep, and the rest.
When you tap with two fingers on the terminal, simple menu will appear. You can abort execution of program running in foreground by pressing Ctrl+C, and you can log out from the terminal by Ctrl+D.

Create empty OS directory

Now that we have control over the device, lets start making use of it. Move to /mnt/us/ directory, and create directories arch/ and arch/os/ by issuing following commands:
cd /mnt/us/
mkdir arch
cd arch/
mkdir os

Create empty disk image

Now image holding all Linux files needs to be created.
dd if=/dev/zero of=arch.img seek=1610612736 count=1 bs=1

Create file system on the image

mke2fs -F -t ext3 arch.img

Mount image into the directory

mount -t ext3 -o loop arch.img os/

Download Arch binaries for ARMv7, and unzip

wget http://os.archlinuxarm.org/os/ArchLinuxARM-armv7-latest.tar.gz
cd os/
nice -19 tar -xzvf ../ArchLinuxARM-armv7-latest.tar.gz

Mount auxiliary directories

mount -o bind /dev/ dev/
mount -t proc /proc/ proc/
mount --rbind /sys/ sys/
mount --rbind /dev/ dev/

Copy DNS Resolve file

cp /etc/resolv.conf etc/resolv.conf

chroot

Now that the Linux image is ready, you can chroot into current directory.
chroot ./ /bin/bash
And congratulation, you are running your own Linux on Kindle. pacman package manager is available, so you can update the system by calling
nice -19 pacman -Syu
I persoally immediately installed gcc, mc, and other useful programs:
nice -19 pacman -S gcc mc netcat nasm
And that's it. If you make Xorg working on it, let me know!
UNIX: Where there is a shell, there is a way

Issues encountered

Freeze

kterm tends to freeze during long operations, such as creating empty image file, or unTARing linux distro. If that happens, hard restart may be required. You can do that by holding the power button until the screen starts blanking. After that you may want to try adding nice -15 in front of given commands to prevent them from locking up the screen.

Further reading

Credits

HisDudeness@MobileRead
dos1@MobileRead