Debian deboostrap

Plan of action
Installing Debian from scratch is a complex and lengthy process. This is our plan of action :
 * 1) Partition the drive
 * 2) Boot to a temporary debian system on /dev/hda3, so we can
 * 3) debootstrap debian, chroot to it, configure it and
 * 4) compile a vanilla mainstream kernel
 * 5) reboot and see if everything is all right

For this guide, you need to have the newer Uboot version, with the netconsole working, available in Kurobox support in stock 2.6 kernels. The guide also assumes you are using foonas-em.

Also, before proceeding, have your netconsole running, we'll need to enter special boot parameters. (Run "nc -u -p 6666 -v -v 192.168.0.100 6666", replacing 192.168.0.100 for your Kurobox Ip. Make sure your kurobox/desktop are ready to use the netconsole)

Get on EM mode
Get on EM mode. On foonas-em this is done by pressing the Power button one time after the device powered on, and while the power light is still slowly blinking. If you can't get on EM mode by this way, you can enter 'run fooflboot' on the netconsole.

Partition the disk
We will create 3 partitions : one with about 3GB for the Debian system, another one with 256MB for swap, and another one that takes the rest of the disk.

-> o ( enter )               (clean the partition table on the disk) -> n, p, 1, (enter), +3000M; (New Primary partition in position 1, from start to 2048M after it) -> a, 1;                     (Set partition 1 as bootable) -> n, p, 2, (enter), +256M;  (New Primary partition in position 2, from the first free spot to 256M after it) -> t, 2, 82;                 (set Type of partition 2 as 82 (Linux Swap)    -> n, p, 3, (enter), (enter); (New Primary partition 3, taking the rest of the disk)    -> w                          (write the changes to the disk - THIS WILL REFORMAT YOUR HD! BACKUP YOUR DATA! - )
 * 1) fdisk /dev/sda
 * 1) mkfs.ext3 -j /dev/sda1         (Create a new journaled ext3 filesystem on /dev/sda1)
 * 2) mkfs.ext3 -j /dev/sda3         (Create a new journaled ext3 filesystem on /dev/sda1)
 * 3) mkswap /dev/sda2               (Create a swap filesystem on /dev/sda2)

Install a temporary Debian system on /dev/hda3
Now we will prepare to boot a pre-made image on /dev/hda3, so we can use the debootstrap tool later on to create our final system on /dev/hda1. Make sure you grab a kernel version compatible with your box.

Have the Debian image ready for boot

 * 1) mount /dev/hda3 /mnt
 * 2) cd /mnt
 * 3) wget http://www.nicholassavilerobinson.com/repository/debian-sarge-2.6.25.1-kuroHG-20100722.tgz
 * 4) tar xvzf debian-image.tgz
 * 5) cd boot/
 * 6) wget http://www.genbako.com/uImage/kernelimage-xxxxxxx-uImage.tgz
 * 7) tar xvzf linux-kenel_image.tgz
 * 8) vi etc/fstab                        (make sure everything is ok - /dev/hda3 should mount on /, hda1 should mount on /mnt)
 * 9) reboot

At this point, have your netconsole running on your pc, be ready to stop the boot procedure hitting 's'.

Running debootstrap on the Debian Image
These steps are done on the netconsole : -> Hit 's' before the timeout comes => ext2load ide 0:3 800000 boot/vmlinux.UBoot  (load the kernel on the memory) => setenv bootargs root=/dev/hda3              (set that the root file system is on hda3) => bootm 800000                                (finally, boot from that memory address)

Hopefully the Debian image will boot. Back on the normal shell, telnet to it :
 * 1) telnet 192.168.0.100  (username and password :  tmp-kun )
 * 2) su                    (root password : root )
 * 3) apt-get update

Get the url of the lastest deboostrap .ded package for debian :
 * 1) wget http://ftp.br.debian.org/debian/pool/main/d/debootstrap/debootstrap_1.0.28_all.deb
 * 2) dpkg -i debootstrap_1.0.28_all.deb
 * 3) debootstrap --arch powerpc squeeze /mnt http://ftp.br.debian.org/debian/

This will setup a base system on /mnt, and it will take a while. Nice time for a coffee :)

Configuring your Debian system
At this point, we will get the system ready to be booted on.


 * 1) cp /etc/fstab /mnt/etc/fstab (just a template that will help us configuring fstab later)
 * 2) chroot /mnt /bin/bash
 * 3) mount -t proc proc /proc

Note that we will use the mainstream kernel on this system. This means that we have to use the PATA drivers, instead of IDE. So edit your fstab file, make sure sda1 goes to /, and sda3 goes to /mnt. Ensure we have no "hda1", "hda2" or "hda3", replace for "sda1", "sda2", "sda3".
 * 1) vim /etc/fstab

We have to ensure the box will connect to the network. So edit the /etc/network/interfaces file. If you use DHPC : auto eth0 lo iface eth0 inet dhcp iface lo inet loopback
 * 1) vim /etc/network/interfaces (configure to use with dhcp or static config)

If you use a static setting (replace the ips to fit you) : auto eth0 lo iface eth0 inet static address 192.168.0.100 network 192.168.0.0 netmask 255.255.255.0 broadcast 192.168.0.255 gateway 192.168.0.1 iface lo inet loopback Ok, let's move on : 127.0.0.1 localhost 192.168.1.100 NameOfYourBox ALL : 192.168.0.0/255.255.0.0 ALL : 127.0.0.1 YourUserName ALL=(ALL) NOPASSWD: ALL
 * 1) vim /etc/resolv.conf (make sure that is has your nameserver/router)
 * 2) echo NameOfYourBox > /etc/hostname  (this is the coolest part - name your host! )
 * 3) vim /etc/hosts (Update your hosts file with your new IP & hostname (if using static IP)
 * 1) vim /etc/apt/sources.list ( you can generate one for you on http://debgen.simplylinux.ch/ )
 * 2) apt-get update
 * 3) apt-get install console-data (reconfigure keyboard, if needed)
 * 4) vim etc/hosts.allow (you should add your network there)
 * 1) dpkg-reconfigure tzdata (adjust your timezone)
 * 2) adduser YourUserName
 * 3) passwd (change the root password)
 * 4) apt-get install sudo
 * 5) vim /etc/sudoers  (add the following to the file, and save, so your user can use sudo)
 * 1) apt-get install ssh    (you'll need this to login to your Kurobox later)

Building the kernel
$ cd /usr/src $ wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.37.tar.bz2 (get the most recent from http://www.kernel.org/pub/linux/kernel) $ tar xjf linux-2.6.37.tar.bz2 $ ln -sf linux-2.6.37 linux $ git clone git://www.jdl.com/software/dtc.git dtc (the dtc tool is used to compile a required special hardware database file) $ cd /usr/src/dtc $ make $ sudo ln -sf /usr/src/dtc/dtc /usr/local/bin/ $ sudo apt-get install uboot-mkimage (that is needed to produce kernel images that the u-boot can boot into) $ cd /usr/src/linux $ cp arch/powerpc/configs/linkstation_defconfig .config $ make menuconfig $ make uImage modules $ exit
 * 1) apt-get install git git-core make patch unzip bison flex libncurses5-dev gcc  (install the additional packages for compiling kernel)
 * 2) chown -R YourUserName:users /usr/src  (you need permission to write on that folder)
 * 3) su YourUserName (this part is meant to be run as a normal use)
 * 1) cd /usr/src/linux
 * 2) make modules_install
 * 3) cp arch/powerpc/boot/uImage /boot/vmlinux.UBoot
 * 4) cp arch/powerpc/boot/dts/kuroboxHG.dts /boot/
 * 5) cd /boot
 * 6) dtc -f -I dts -O dtb -o kuroboxHG.dtb -V 16 kuroboxHG.dts
 * 7) reboot

Make the Power/Back button work
$ sudo apt-get install avr-evtd $ sudo vim /etc/default/avr_evtd    (tweak the configuration to suit your needs)

Fix Perl locale-related problems
If you see the following error when running perl: perl: warning: Setting locale failed. perl: warning: Please check that your locale settings: LANGUAGE = (unset), LC_ALL = (unset), LANG = "en_GB.UTF-8" are supported and installed on your system. perl: warning: Falling back to the standard locale ("C"). Then run: (be sure to generate the en_US.UTF-8 locale)
 * 1) apt-get instal locales
 * 2) dpkg-reconfigure locales

Install popularity-contest
Inform the repository that you are using the packages related to the Kurobox, so they don't get forgotten, run :
 * 1) sudo apt-get install popularity-contest

How could this guide be improved

 * A better foonas-em busybox, comming with ar, that would allow debootstrapping directly without the need to boot the temporary debian image.