johnlane
Posts: 63
Joined: Fri Jul 20, 2012 8:26 pm

Building from scratch

Fri Jul 20, 2012 8:32 pm

Hello everyone. I'm an experienced Arch user and it's therefore the obvious choice for my new Pi. The first thing I would like to do is understand the packages in the system and be able to build my own. I've been doing this for ages on Arch using "mkarchroot" but I'm hitting conflicts when I try to do that on the Pi.
I've tried something like this to start with:

Code: Select all
mkarchroot -C /path/to/my/pacman.conf newarchroot base

I presume "base" contains stuff not relevant in the arm space and that I either need a different meta-package or a specific list of packages. I've had a look around and done some google searches but I haven't found anything relevant hence the post.
thanks in advance.
Can anyone help point me in the right direction?
Raspberry Pi Utilities: https://github.com/johnlane/rpi-utils
For Raspberry Pi and Arch Linux

pepedog
Posts: 1043
Joined: Fri Oct 07, 2011 9:55 am

Re: Building from scratch

Fri Jul 20, 2012 9:33 pm

I don't have time to refine this, but this is base without unwanted kernels

Code: Select all

pacman -S bash bzip2 coreutils cronie cryptsetup device-mapper dhcpcd diffutils e2fsprogs file filesystem findutils gawk gcc-libs gettext glibc grep gzip heirloom-mailx inetutils initscripts iputils jfsutils less licenses logrotate lvm2 man-db man-pages mdadm nano pacman pacman-mirrorlist pciutils perl ppp procps-ng psmisc reiserfsprogs sed shadow sysfsutils syslog-ng sysvinit tar texinfo usbutils util-linux vi wget which wpa_supplicant xfsprogs
You will want linux-raspberrypi linux-headers-raspberrypi raspberrypi-firmware also
Plus /etc/inittab /etc/securetty and /boot/cmdline.txt
It used to be done this way (do on a pi)

Code: Select all

#!/bin/bash
#
# Arch Linux ARM Image Builder
#
# Licensed under the GPLv2.
#
# This script builds an Arch Linux ARM distribution/image.
# First, it downloads and installs packages to the workingdir,
# then configures some basics, sets the root password to "root",
# and then creates a rootts.tar.gz and/or a UBI image, ready to flash.
#
# Usage: ./distro-builder workingdir
#
# NOTE: This script is interactive.
# Agree to installing packages and answer "y" to cleaning the Pacman database.
#
# ==== Variables to set ====
INSTALLEDPKGS="base kernel26 kernel26-headers file ntfs-3g openssh openssl"
RELEASEVER=2011.06
MAKETARGZ=1
# ==== The Process ====
mkdir -p $1
echo  -e "\033[1mInstalling packages...\033[0m"
mkdir -p $1/var/lib/pacman
pacman -Syyf --noconfirm --noprogressbar -r $1 $INSTALLEDPKGS

echo -e "\033[1mSetting the password to 'root' and cleaning up:\033[0m"
echo -e "root\nroot\n" | chroot $1/ /usr/bin/passwd root
rm $1/dev/{console,null,zero}
chroot $1/ mknod -m 600 /dev/console c 5 1
chroot $1/ mknod -m 666 /dev/null c 1 3
chroot $1/ mknod -m 666 /dev/zero c 1 5
rm $1/etc/locale.gen
echo "en_US.UTF-8 UTF-8" >> $1/etc/locale.gen
echo "en_US ISO-8859-1" >> $1/etc/locale.gen
echo "de_DE ISO-8859-1" >> $1/etc/locale.gen
echo "de_DE@euro ISO-8859-15" >> $1/etc/locale.gen
chroot $1/ /usr/sbin/locale-gen
chroot $1/ yes | /usr/bin/pacman -Scc
echo $RELEASEVER > $1/etc/alarm-version

# Here is the rootfs.tar.gz part if you set MAKETARGZ to 1
if [ $MAKETARGZ = 1 ]; then
     echo  -e "\033[1mCreating a rootfs.tar.gz...\033[0m"
     cd $1
     tar czf ../PlugApps-Linux-$RELEASEVER-rootfs.tar.gz ./*
     cd ../
else
     echo -e "\033[1mNot creating a rootfs.tar.gz...\033[0m"
fi

echo -e "\033[1mCleaning up...\033[0m"
rm -rf $1

johnlane
Posts: 63
Joined: Fri Jul 20, 2012 8:26 pm

Re: Building from scratch

Sat Jul 21, 2012 7:29 pm

thanks for this. I will try this out over the next few days and report back here in case anyone else is interested.
Raspberry Pi Utilities: https://github.com/johnlane/rpi-utils
For Raspberry Pi and Arch Linux

johnlane
Posts: 63
Joined: Fri Jul 20, 2012 8:26 pm

Re: Building from scratch

Tue Aug 21, 2012 8:13 pm

Ok, been away a while trying to sort this. I have written an image builder and I have built and booted an SD card using QEMU. I can't however get it to boot on the Pi. I

As I understand it, the boot process involves the GPU looking for the first FAT32 partition and loading "bootcode.bin". It does not execute MBR code but looks in the MBR partition table to locate the first FAT32 partition. Partitions don't need to be marked as bootable. Please correct me if I have that wrong.

I believe I have everything in place that the bootloader needs but it doesn't boot.

I have two partitions: partition 1 is "boot": FAT32 (type 0x0C) and partition 2 is "root", formatted ext4:

Code: Select all

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            2048      196607       97280    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          196608     4194303     1998848   83  Linux
I have inspected the sector 0 in a stock ArchLinux image (the June 16th one) and there are bytes in there. I have tried copying the first 446 bytes across into my image (just in case the MBR does get executed) but it made no difference. My sector 0 (without those bytes) is shown below:

Code: Select all

$ dd if=/dev/mmcblk0 bs=1 count=512 | hexdump -C
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001b0  00 00 00 00 00 00 00 00  19 a9 c2 f3 00 00 00 20  |............... |
000001c0  21 00 0c 3c 30 0c 00 08  00 00 00 f8 02 00 00 3c  |!..<0..........<|
000001d0  31 0c 83 15 50 05 00 00  03 00 00 00 3d 00 00 00  |1...P.......=...|
000001e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|
512+0 records in
512+0 records out
00000200
512 bytes (512 B) copied, 0.00690266 s, 74.2 kB/s
$ 
So I have a card formatted with 2 partitions. One of those (the first one) is FAT32 and contains the boot files:

Code: Select all

arm128_start.elf  bootcode.bin  COPYING.linux         kernel.img        start.elf
arm192_start.elf  cmdline.txt   kernel_cutdown.img    LICENCE.broadcom
arm224_start.elf  config.txt    kernel_emergency.img  loader.bin
What makes this difficult is that there is zero visual feedback on the Pi so I have absolutely no idea where the problem is. Any pointers greatly appreciated.

I have an image builder waiting to be released into the wild just as soon as I have this working :)
Raspberry Pi Utilities: https://github.com/johnlane/rpi-utils
For Raspberry Pi and Arch Linux

pepedog
Posts: 1043
Joined: Fri Oct 07, 2011 9:55 am

Re: Building from scratch

Tue Aug 21, 2012 10:10 pm

if you are using the repo packages, fine, if you build not all things build or run without mods, and they are here
https://github.com/archlinuxarm/PKGBUILDs

no magic creating the card, this is how

Code: Select all

If the media inserted is device sdb (use dmesg)
parted -s /dev/sdb mklabel msdos 
parted -s /dev/sdb unit cyl mkpart primary fat32 -- 0 16
parted -s /dev/sdb set 1 boot on 
parted -s /dev/sdb unit cyl mkpart primary ext2 -- 16 -2 
mkfs.vfat /dev/sdb1
mkfs.ext4 /dev/sdb2 
A few config files have to be tweaked, /etc/inittab /etc/securetty and maybe /boot/cmdline.txt and /boot/config.txt

johnlane
Posts: 63
Joined: Fri Jul 20, 2012 8:26 pm

Re: Building from scratch

Wed Aug 22, 2012 7:12 pm

[quote="pepedog"]
mkfs.vfat /dev/sdb1
[/code]

Aha! There it is: it's a FAT16 parttition!!! I've checked the stock Arch image and its boot filesystem is also FAT16 despite the partition being labelled FAT32.

Everywhere it says the partition needs to be FAT32. I assumed that also meant the filesystem on the partition needed to be FAT32 as well.

I have updated my tool not to specify a FAT type when creating the boot filesystem. It now creates a FAT16 and, guess what, it boots!!! :D

So it looks like the filesystem needs to be FAT 16 but the partition needs to be labelled FAT32.
Raspberry Pi Utilities: https://github.com/johnlane/rpi-utils
For Raspberry Pi and Arch Linux

pepedog
Posts: 1043
Joined: Fri Oct 07, 2011 9:55 am

Re: Building from scratch

Wed Aug 22, 2012 8:00 pm

Hmm, I never noticed that, I would have thought fat32 would have worked.
I'm glad it works for you.

Return to “Arch”