Categories
PC Nerding

Android, Linux and Chroot

I felt the hacky desire to install a chrooted Linux under my Android phone, I’ll probably end up not using it, but I just like doing this king of stuff.
Note this guide requires a rooted phone, loop devices support and BusyBox (I have a Samsung Galaxy S3 with rooted stock JB 4.1.1). Using apps with BusyBox included (like SSHDroid or Better Terminal Emulator Pro) MAY save you the need of installing BusyBox on your phone. I said ‘may’ because I did not test them.
I followed this guide from Sergio Rubio to install my Arch Linux and there’s no reason to write again from scratch a good guide, so your first step is following his guide. What Mr. Rubio’s guide lacks (on purpose) was a faster way to actually mount/umount the chrooted system and get access to Arch shell, think my guide as “Part 2” for his one.

The author installed it in /sdcard/archlinux folder, my guide will assume you used the same directory.
TIP: I suggest you to increase the archlinux.img file size, 750MB may be too small for installing other packets (eg. Mono takes up to 200MB). I personally made it 1,5GB.

After installing Arch, I suggest rebooting your phone. Android will forget about the mounted partitions and we can start from scratch.

Mounting and umounting five partitions take time, a lot if it on a super small android touch keyboard, so we will create two scripts to make life easier.
Using a file manager on Android or connecting it to a pc, create a two files in your sdcard folder
The first is archmount.sh, write this stuff in
#!/bin/bash
mount -v /sdcard/archlinux.img /sdcard/archlinux
mount -v -o bind /dev/ /sdcard/archlinux/dev/
mount -v -t proc proc /sdcard/archlinux/proc/
mount -v -t sysfs sysfs /sdcard/archlinux/sys/
mount -v -t devpts devpts /sdcard/archlinux/dev/pts/
cp /etc/resolv.conf /sdcard/archlinux/etc/resolv.conf

and the second is archumount.sh
#!/bin/bash
umount -v /sdcard/archlinux/dev/pts/
umount -v /sdcard/archlinux/sys/
umount -v /sdcard/archlinux/proc/
umount -v /sdcard/archlinux/dev/
umount -v /sdcard/archlinux

Those two scripts will take care of mounting and umounting the partitions, just run them on your phone using Android Terminal Emulator.
su sh /sdcard/archlinux/archmount.sh
#or
su sh /sdcard/archlinux/archumount.sh

After mounting you can get access to an Arch shell by running
su chroot /sdcard/archlinux/ /bin/bash

But unless you are using an hardware keyboard, those functions are still too long to type, we will shorten them using shell functions. In Android Terminal Emulator go to “Preferences” -> “Initial Command” and add those lines and restart the app.
function archmount() { su sh /sdcard/archlinux/archmount.sh ; }
function archumount() { su su sh /sdcard/archlinux/archumount.sh ; }
function archsh() { su chroot /sdcard/archlinux/ /bin/bash ; }

Now everytime you want to use Arch, mount partitions by running archmount, then type archsh to open an Arch shell. Now you have full access to a command line linux. When you are ready to quit type exit to return to Android terminal and type archumount to unmount Arch’s partitions.
If you want to use Arch later without having to remount it, just skip archumount and only run archsh whenever you need it.

A final note:
For some reason my Arch linux had an empty PATH variable, causing “command not found” error with almost every command ran in Arch’s shell. From Arch’s shell run export PATH=/bin:/usr/bin
to solve the issue. I recommend adding that same line it to .bashrc file, to access it run nano /.bashrc
After editing Press CTRL + O to save and CTRL + X to exit. Use Hacker’s Keyboard for your CTRL needs.

Categories
Uncategorized

Cheap things

dvddrive

Cheap prices not only get you bad quality items, but sometimes even not usable ones. I bought a 15€ usb dvd drive and I got it with two power cables and no data cable. Thankfully my wifi printer came with that cable, so I had a spare. But fuck off.

Categories
PC Nerding

Raspberry PI X11 forwarding with Cygwin

After my little Raspberry PI Mono installation accident, that fucked up everything with Mono, I decided to reinstall Raspbian Wheezy. I know a lot of people that love touchy and clicky interfaces, the tablet market rise reflect this. I personally use my RPi through command line, SSH it over LAN, because I one Desktop environment (my Windows machine) is more than enough for me.
But after a couple mails with a friend trying to view his PI’s lxsession on his Windows machine and explaining him my setup using Cygwin only, he told me there’s no tutorial on this. Nothing new or super cool, just another way.
This guide should work ok with any linux environment, not only RPIs, provide you properly set ssh configurations.

The first thing to do is downloading Cygwin installer, be sure to add xorg, xint and openssh packages while installing. There may be some other needed packages, if you get somenthing like a “command not found”, you have to add that package too.

Now open a Cygwin shell with its nice desktop shortcut and type:
cygstart xwin
cygstart tells Cygwin to run a command and give you back your shell control. Removes the need for two shells (one for launching the Xserver and one for SSH connection). It can be omitted.
xwin Launches the XWin application, which is our Xserver
This is usually enough, but as default setting, xwins create a window big as my current resolution. I prefer using this command:
cygstart xwin -screen 0 1440x900@1 -wgl
Fast explanation:
-screen 0 1440×900@1 tell xwin to create the remote screen window number 0, with a resolution of 1440×900 at monitor 1. Use this parameter as this, modifying only the resolution part. See Note 1 for better explanation.
-wgl will enable OpenGL accelerated graphics on the remote screen window. It is not mandatory and if not enabled the remote screen window will use software rendering.

After that we must make sure that Cywin is aware of this remote display, it can be done by setting and exporting the environment variable DISPLAY.
The newly created window will have name like: Cygwin/X:0.0, make sure to set this variable to whatever is written after the X, like
export DISPLAY=:0.0

Now, using Cygwin, SSH to your PI
ssh -Y pi@address
and after logon, start you windows manager:
lxsession
This should show your Raspberry PI desktop inside your XWin window.

Final notes:
If you want to do all of this stuff at cygwin’s startup, just add the lines
cygstart xwin #+your parameters
export DISPLAY=:0.0

at the end of cygwin\home\user\.bashrc.

Note 1:
See XWin manual for possible parameters.
-screen 0 1440×900@1 explanation:
0 Create windows number 0. It’s like an ID to identify which windows is this. If you want to use multiple remote screens, for each new screen you have to increment this value by one.
1440×900 Is pretty self explanatory. Sets the PI’s max resolution to this size.
@1 Tell XWin on which (real) monitor you want the window to appear. So in case of a multiple monitor setup 1 is the main monitor, while 2, 3, 4, …, are the other monitors. If you have a single monitor this value is always 1.