In our previous posts we have built the bootloader and the Linux kernel and put them on a SD Card. Now we will also add a root filesystem to complete our GNU/Linux system. There are many different root file system we could have used, Yocto, Debian … but I chose ArchLinux ARM since ArchLinux is my preferred GNU/Linux distribution.

First we download ArchLinuxARM.

$  cd
$  wget http://os.archlinuxarm.org/os/ArchLinuxARM-armv7-latest.tar.gz

We are going to add another partition to the image file we created earlier. Use the following sequence in fdisk: p, enter, n, enter, p, enter, 2, enter, enter, enter, p, enter, w and enter.

$  cd ~/arrow-sockit-ghrd/sdcard/
$  sudo losetup --show -f sdcard.img
$  sudo fdisk /dev/loop0

Welcome to fdisk (util-linux 2.36).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/loop0: 3 GiB, 3221225472 bytes, 6291456 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x039cfc37

Device       Boot Start    End Sectors  Size Id Type
/dev/loop0p1       4096 528383  524288  256M  b W95 FAT32
/dev/loop0p3       2048   4095    2048    1M a2 unknown

Partition table entries are not in disk order.

Command (m for help): n
Partition type
   p   primary (2 primary, 0 extended, 2 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (2,4, default 2): 2
First sector (528384-6291455, default 528384):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (528384-6291455, default 6291455):

Created a new partition 2 of type 'Linux' and of size 2.7 GiB.

Command (m for help): p
Disk /dev/loop0: 3 GiB, 3221225472 bytes, 6291456 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x039cfc37

Device       Boot  Start     End Sectors  Size Id Type
/dev/loop0p1        4096  528383  524288  256M  b W95 FAT32
/dev/loop0p2      528384 6291455 5763072  2.7G 83 Linux
/dev/loop0p3        2048    4095    2048    1M a2 unknown

Partition table entries are not in disk order.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Invalid argument

The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or partx(8).

We need to format this partition with a EXT4 file system.

$  sudo partprobe /dev/loop0
$  sudo mkfs.ext4 /dev/loop0p2

Now we mount the file system and unpack the root file system onto it.

$  mkdir part2
$  sudo mount /dev/loop0p2 part2/
$  sudo tar xzvf /home/oddbjorn/ArchLinuxARM-armv7-latest.tar.gz -C part2/

We need to update some things in the root file system in order for it to be usable. If you look at fstab there are no entries. We only need one entry which is out root file system. If you have specific needs you can add other entries of modify the one for the root file system.

/dev/mmcblk0p2	/	ext4	defaults	0	1 

You can make other changes to the root file system if you like, but now it is should at least boot. So We umount the partition, delete the loop back devices and write the sdcard.img to the SD card. We then insert the SD card into the SocKit and boot up connected to the serial terminal with putty or another serial terminal. If everything was done correctly we should see ArchLinuxARM boot up. We can log in with the default password for root which is root.

.
.
.

Arch Linux 5.8.0zImage-32685-geb446787abdf (ttyS0)

alarm login: root
Password:
[root@alarm ~]# uname -a
Linux alarm 5.8.0zImage-32685-geb446787abdf #1 SMP Wed Oct 28 18:32:05 CET 2020 armv7l GNU/Linux
[root@alarm ~]#

We can now continue to set up ArchLinuxARM to our liking. Have fun!