Friday, August 29, 2014

Debian Wheezy root files system from scratch

Wanted to experiment with making a Debian Wheezy root file system for my SAMA5D3 XPLAIN from scratch.  I followed this link mostly but it is missing pieces so I used this link to fill in the gaps.

First is to install all the necessary packages (I am still using Ubuntu 14.04 via parallels on my Mac).  I think this list is a little overkill but I saw no reason to try and figure out which I did not need to install (most were already installed).

sudo apt-get install emdebian-archive-keyring
sudo apt-get update
sudo apt-get install libc6-armel-cross libc6-dev-armel-cross
sudo apt-get install binutils-arm-linux-gnueabi
sudo apt-get install gcc-4.7-arm-linux-gnueabi
sudo apt-get install g++-4.7-arm-linux-gnueabi
sudo apt-get install uboot-mkimage
sudo apt-get install libncurses5-dev
sudo apt-get install git bc curl
sudo apt-get install debootstrap dpkg-dev
sudo apt-get install qemu binfmt-support gemu-user-static dpkg-cross

With everything installed we can now start to create the root file system

mkdir armel-root
cd armel-root
debootstrap --foreign --arch armel wheezy .

This will take a bit to download all basic packages.  The next steps continue with the second stage:

cp /usr/bin/qemu-arm-static usr/bin
LC_ALL=C LANGUAGE=C LANG=C chroot . /debootstrap/debootstrap --second-stage
LC_ALL=C LANGUAGE=C LANG=C chroot . dpkg --configure -a

This setups the basic root file system, now it is just a matter of making modifications and additions to meet your needs.  First lets add a password for root:

sudo chroot . passwd

setup the package repository (/etc/apt/sources.list) which will vary based on your needs:

deb http://ftp.us.debian.org/debian/ wheezy main contrib non-free #deb-src http://ftp.us.debian.org/debian/ wheezy main contrib non-free deb http://ftp.us.debian.org/debian/ wheezy-updates main contrib non-free #deb-src http://ftp.us.debian.org/debian/ wheezy-updates main contrib non-free deb http://security.debian.org/ wheezy/updates main contrib non-free #deb-src http://security.debian.org/ wheezy/updates main contrib non-free #deb http://ftp.debian.org/debian wheezy-backports main contrib non-free ##deb-src http://ftp.debian.org/debian wheezy-backports main contrib non-free #Kernel source: https://github.com/RobertCNelson deb [arch=armhf] http://repos.rcn-ee.net/debian/ wheezy main

and install some packages (these will be different depending on your needs):

LC_ALL=C LANGUAGE=C LANG=C chroot . apt-get install <package_name>

Some packages to add include python3, vim, etc.

Then you can modify different files to file your build as well.  For example:
modify etc/fstab using the following:
sudo sh -c "echo '/dev/mmcblk0p2 / auto errors=remount-ro 0 1' >> etc/fstab"
sudo sh -c "echo '/dev/mmcblk0p1 /boot/uboot auto defaults 0 2' >> etc/fstab"
and modify etc/inittab using the following:
sudo sh -c "echo 'T0:23:respawn:/sbin/getty -L ttyS0 115200 vt102' >> etc/inittab"

Or modify the network interfaces:

sudo vim etc/network/interfaces

and add the following:
allow-hotplug eth0
iface eth0 inet dhcp
allow-hotplug eth1
iface eth1 inet dhcp
After this you can make other changes and modifications as needed, just remember to always use chroot . when calling an application. To copy your root file system to an SD card just do the following (where target-rootfs is top level folder and /media/rootfs is the mounted SD card):

sudo rsync -axHAX --progress target-rootfs/ /media/rootfs/

Enjoy


No comments:

Post a Comment