[Mageia-discuss] Testers needed/wished for to build Mageia in a chroot inside an Android-device from the written guide

Kristoffer Grundström kristoffer.grundstrom1983 at gmail.com
Sun Feb 24 15:13:04 CET 2013


I'd like it if someone took the time to test my guide that I wrote for a 
Samsung device.

Feel free to give me constructive critisism.

The intention of this written guide is to make it foolproof (everyone 
should understand how it works & what to do).

Let me know if you have managed to build without issues.

-------------- next part --------------
In order to fully compile & install Mageia in an ARM-device made by Samsung, here's what you need to have:

An ARM-based device made by Samsung.
A desktop-PC/Laptop/Netbook with Mageia 2 or later installed & fully updated.
USB-cable to the device.
ADB added to $PATH


To become root (which basically means that you get full access to the system in use). THIS IS RISKY & IS ONLY RECOMMENDED TO THOOSE WHO UNDERSTAND WHEN IT'S NEEDED & WHAT IT'S USED for!!!

Here's how you become root:

Press Power-button to start your device & wait til you get to Home-screen.

Open Program -> Settings -> About phone and then remember its kernel-version & baseband-version for later use.

Visit Google & find a thread from xda-developers.com by typing name of your device + xda-developers.com + forum + unsecure + kernel + root that contains an unsecure kernel for rooting (it's usually written in bold letters) and then choose a kernel-tarball that matches your current existing device-kernel or the closest one available.

Now, unpack/tar the zImage from the downloaded tarball from the xda-developers.com thread & put it on your desktop so you know where to find it when ADB is added to your $PATH & when the Heimdall Flash Suite is installed.

ADB means Android Debug Bridge and is used to communicate with your ARM-device through a shell.
It can also be used to push an APK (An Android installation package-file) & a whole lot more.

How to setup ADB (Android Debug Bridge) in Mageia:

To get ADB added to console in Mageia 2 or later you have to do as theese instructions tell you: https://wiki.mageia.org/en/How_to_add_adb_to_console_in_Mageia

Open Program-menu.
Click on Settings.
Click on Developeralternatives.
Tick the box for USB-debugging.
Press OK on the prompt (if you want to allow USB-debugging) and connect your USB-cable to the device & then to the USB-slot of the computer.

Now, just as a precaution, confirm that ADB sees your device by typing in a terminal-window:

adb devices

If ADB sees it it should present your device like this for example:

[your username at localhost or name of machine ~]$ adb devices
List of devices attached 
XX000xxx00x00x	device

I changed the numbers & letters for my device and replaced them with 0's and small x's.

Heimdall is a cross-platform open-source tool suite used to flash firmware (also known as a ROM) onto Samsung Galaxy S devices.

For i586-arch

The RPM's of heimdall & heimdall-frontend are located in the media called Core 32bit Release so make sure it's added to the mirrorlist & enabled for updates.

For the x86_64-arch

The RPM's of heimdall & heimdall-frontend are located in the media called Core Release so make sure it's added to the mirrorlist & enabled for updates.

First way of installing Heimdall Flash Suite:

In Mageia, open Program ->Tools ->Systemtools ->Mageia Control Center (type your given root-password from installation of Mageia on prompt-window & press Enter/Return-button) and then click on Install/Remove programs.
Now make sure that the first dropdown-menu that says Packages with a GUI is changed to All & type heimdall in the search-field followed by pressing Enter/Return-button.

That should give you heimdall and heimdall-frontend & then tick the boxes for x86_64 if that's your main arch followed by Apply & Yes. Wait til it's installed & that the window is reloaded & then click Exit-button.

Second way of installing Heimdall Flash Suite:

In Mageia, open Program -> Tools -> Terminal

In the Terminal-window type su - (press Enter/Return-button) and then type the given root-password from installation of Mageia on prompt-window.

You should now see either:

[root at localhost ~]#


[root at name of the machine]# (if you named your computer during the installation of Mageia)

Now type urpmi heimdall heimdall-frontend --auto (press Enter/Return-button and wait til you get a new root-prompt like the one described above).

You now have 2 ways to use Heimdall to flash the kernel:

1. Open Heimdall from Program -> Development -> Heimdall

Click the tab called Utilities & press the Detect-button to see if Heimdall recognizes the device in order to flash it.

Output should then say:

Device detected

Choose the tab called Flash and then add your device PIT-file (which you can retrieve from www.samfirmware.com or by googleing Samsung + Galaxy + modelname + pit) to the field that states Options followed by the word PIT directly beneath.

Make sure that the box for Partition isn't checked/ticked.

Click the Browse-button & choose the zImage that you put on your desktop & choose KERNEL as Partition Name.

Press Add-button on the right.

Now click Start to begin the flash-process of the unsecure (rooted) kernel & let the device fully reboot until you do anything else.

First way to confirm that you're using a rooted kernel is:

In the device:

1. Open Program-menu.
2. Open Google Play (also known as Store).
3. Search for 3 applications named Superuser & Busybox & Android Terminal Emulator.
4. Install Superuser & Busybox & Android Terminal Emulator.

Now, open Busybox & press button to install Busybox to whatever dir that is suggested by default.

Exit Busybox.

Open Android Terminal Emulator.

Type su - and press Enter/Return-button (Now you should be prompted by Superuser to either Decline or Allow the su-command to be executed & this is where you press Allow. A message will appear for a short time telling you "Terminalemulator has been granted Superuser permissions" and you'll also see prompt-change to [root at android ~]# and that means that you're now root & can do whatever you want with the system. REMEMBER THAT IT'S VERY RISKY TO DO COMMANDS IN THE TERMINAL AND MIGHT BREAK YOUR SYSTEM IF YOU DON'T KNOW WHAT YOU'RE DOING!!!!!

Second way to confirm that you're using a rooted kernel is:

In the device:

1. Open Program-menu.
2. Click on Settings.
3. Click on Developer options.
4. Tick the box to allow apps to be installed from unknown sources. Just click OK on the prompt to confirm that it's OK to do so.
5. Open Program-menu.
6. Open Google Play (also known as Store).
7. Search for Superuser & Busybox & Android Terminal Emulator.
8. Install Superuser & Busybox & Android Terminal Emulator.
9. Open the webbrowser.
10. Go to http://download2us.softpedia.com/dl/1d85264627c2e57c4a7661d5894a9d4f/51284217/800110178/pda/System%20Utilities/Enhancements/z4root.1.3.0.apk & go to Program ->Downloads when download is finished & press to install the apk followed by pressing OK-button on the question-prompt if you want to install this app.
Now press Finished.
If above link doesn't work go to http://www.softpedia.com/ & then click Handheld -> System Utilites -> Enhancements & then go through the list of apps until you find z4root or type z4root in the search-field (press Enter/Return-button).
11. Open Program-menu.
12. Click to open the z4root-app.
13. Press ROOT-button.
14. Click Allow when prompted by Superuser & that's it.
You've now rooted your device!
Same thing applies as in the first way, you play with su on your own now.
I take no responsibility for your actions what so ever.
Now that you've rooted your device, you're free to flash any ROM you want.

To find if your device is supported by CM, please refer to http://wiki.cyanogenmod.org/w/Devices#vendor=;

In the filter-field type the name of the devive that you've just rooted and see if it appears.

Click on the image of your device if it appears & continue from there.

NOTE! It does matter if it's GSM-based or CDMA-based when you flash a ROM so please find out so you'll read the right instructions. !NOTE
CHROOT-build for Mageia

Things you need to build the Mageia CHROOT-environment:

* Root-privileges on your device.
* Desktop/Laptop/Netbook with Mageia 2 or later installed.
* ADB added to $PATH.
* Cyanogenmod 9.0.0 built & flashed on your device.
* An SD-card for your device with more than 10 GB of space left & formatted with the MBR scheme & a single ext3-partition plus 15 sectors left over.
* The CPU-speed set to 710 mhz with an app for rooted devices (for example interactiveX governor, YMMV.
* SSHDroid installed & sideloaded.

Then, on a workstation (any architecture), insert the µSD card, and as root, type:

 debootstrap --arch=armel --variant=minbase --foreign  mageia  /media/PHONE\ CARD/mageia  http://http.mageia.org/mageia

You might want to consider using --arch=armhf if your phone supports ARMv7.

If you have a local mirror, replace the URL above with your local mirror.

Then remove the µSD-card and replace it in the phone, start SSHDroid (which provides the command chroot).
Then SSH to the phone and type:

  export SDCARD=/mnt/sdcard
  export ROOT=$SDCARD/mageia
  export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH
  mount -o remount,exec,dev,suid $SDCARD
  chroot $ROOT /bin/bash -l
  debootstrap/debootstrap --second-stage

Then build up the Mageia-system as you normally would a minimal installation.

If you need to run binaries from inside the chroot outside the chroot, you can use ld.so:

export SDCARD=/mnt/sdcard
export ROOT=$SDCARD/mageia
export LD_LIBRARY_PATH=$ROOT/lib:$ROOT/lib/arm-linux-gnueabi:$ROOT/lib/arm-linux-gnueabihf:$ROOT/usr/lib:$ROOT/usr/lib/arm-linux-gnueabi:$ROOT/usr/lib/arm-linux-gnueabihf
cd $ROOT
./lib/ld-linux-*.so* bin/ls

Available memory

Android pre-loads applications ( in some case that the user has never started) when there is free memory. This reduces the memory available to applications in a chroot.

It looks like the *_MEM properties in /init.rc along with the /sys/module/lowmemorykiller/parameters/minfree could help.

Zygote starts SystemServer and SystemServer restarts zygote, so simply killing one of them won't work.
The Android-native way of getting rid of zygote and all that descends from it is to just use the 'stop' command (in a script or through a remote (root) shell), to restart the whole Android environment you'd use the 'start' command:

stop # to stop zygote
# now do whatever you want without Android getting in the way.
Once you're ready just type following to start zygote:
start #

The display is now blank and ready for SDL.
The input devices only partly work with SDL on the 8120 ( write your own code to read /dev/input/event*), but graphics work well.

AF_INET privelages

On Android, you will need to add at least one group 3003 aid_inet for those processes which require access to creating sockets (other security guarded systems particular to Android may need addressing for other applications, search for 3003 aid_inet on the web for more detail).

exim4 and mailman chroot on Android

As well as altering inet access, the Mageia-exim user will have to be added to group 3003.
Further, if you experience trouble in the exim mainlog for creating sockets during DNS, try dropping privelages by adding "deliver_drop_privilege=true" to the exim4.conf.template file.
For mailman, the standard setup is required, as per the README.Mageia file in /usr/share/doc.
However the user list must also be added to the group 3003 to allow it to send mail.

More information about the Mageia-discuss mailing list