Saturday, 6 December 2014

Building a Debian root filesystem for Banana Pi

The last component of the bootable SD card is the root file system. The location of the root is passed on as a kernel command line parameter. :
CONFIG_CMDLINE="console=ttyS0,115200 root=/dev/mmcblk0p2 rootwait rw"
where ttyS0 is the the initial console, and the second partition of the SD card (mmcblk0p2) is where the Debian root filesystem is. We need a couple of tools available in our development machine :
 sudo apt-get install qemu-arm-static debootstrap binfmt-support  
mount the SD, described in building a bootable SD card for Banana Pi
 sudo mount /dev/sdb2 /mnt  
start the debootstrap process:
 sudo debootstrap --arch=armhf --foreign wheezy /mnt  
Once this process is done, chroot into the filesystem and continue onto the second stage. One key binary is the qemu-arm-static, which emulates an armhf machine within the chroot, to continue the process.
 sudo cp /usr/bin/qemu-arm-static /mnt/usr/bin/  
 sudo chroot /mnt
now continue the debootstrap process in the chrooted environment:
 /debootstrap/debootstrap --second-stage  
when the process is finished, its time to update apt.
 cat >/etc/apt/sources.lst <<EOF  
 deb stable main contrib non-free  
 deb-src stable main contrib non-free  
 deb wheezy-updates main contrib non-free  
 deb-src wheezy-updates main contrib non-free  
 deb wheezy/updates main contrib non-free  
 deb-src wheezy/updates main contrib non-free  
and then update :
 apt-get update  
configure locales
 apt-get install locales dialog  
 dpkg-reconfigure locales  
setup root password :
setup hostname :
 echo BP-A20> /etc/hostname  
Preapare inittab to spawn a login on console ( /dev/ttyS0 ):
 echo T0:2345:respawn:/sbin/getty -L ttyS0 115200 vt100 >> /etc/inittab  
setup loopback and eth0 interfaces:
 cat > /etc/network/interfaces <<EOF  
 auto lo
 iface lo inet loopback
 allow-hotplug eth0  
 iface eth0 inet dhcp  
setup /etc/fstab :
 cat > /etc/fstab <<EOF  
 /dev/mmcblk0p1     /boot     vfat     defaults     1     1  
 /dev/mmcblk0p2     /     ext4     errors=remount-ro 0    1  
install a few useful tools :
 apt-get install openssh-server ntp vim  
exit from chroot, back to the host:
 sudo rm /mnt/usr/bin/qemu-arm-static  
now copy the modules, uImage and script.bin
 sudo cp -av /tmp/lib/modules /mnt/lib/  
 sudo sync  
 sudo umount /mnt  
 sudo mount /dev/sdb1 /mnt  
now its time to copy the uImage which was built in this post and script.bin from here.
/mnt should now look like this:
 -rwxr-xr-x 1 root root  50624 Nov 30 08:17 script.bin  
 -rwxr-xr-x 1 root root 3033152 Nov 30 08:18 uImage  
now unmount the SD
 sudo sync  
 sudo umount /mnt  
the SD card is now ready to boot.

No comments:

Post a Comment