MAC5856 - Road To The Linux Kernel
This post is a collection of reports on the tutorials provided for the MAC5856 class for Open Source Development. As such, this post will be continuously edited to account for my latest experiences with the tutorials.
More specifically, the tutoral pages provide a guide on how to setup a development environment for building and developing the Linux kernel.
After years of being an Arch Linux user, I've opted for going with a Fedora installation for a change. This required some small changes with respect to the tutorials - all of them are documented below.
Tutorial 1 - QEMU and Libvirt Setup
This first tutorial focuses on the creation of the basis for the development setup, such as the installation of all necessary packages for virtualisation.
-
Although the tutorial uses the
libvirt-qemuuser for the directory ownership, I had to go with theqemuuser in Fedora. -
To avoid having to use
sudoevery time I usevirsh, I opted for creating a tiny wrappervirshhin theactivate.shscript that solves this:function virshh() { virsh --connect "qemu:///system" $@ } export -f virshhNow instead of using
virshI usevirshhand it's working flawlessly so far. -
As many other students reported, I also had to install the
openssh-serverpackage in the VM:apt update && apt install openssh-server systemctl enable ssh && systemctl start ssh && systemctl status ssh
Tutorial 2 - Building and Booting The Kernel
-
I wasn't able to use
rsyncto fetch thevm_mod_listwe created in the last tutorial. For that I had to installrsyncin the VM first. -
I had a very annoyoing problem when creating the new VM: the system would never completely boot. Instead
virt-installwould halt very early and never finish the creation of the VM itself. After many attempts, this version worked:export img_file="${VM_DIR}/arm64_img.qcow2" export root_vda="/dev/vda2" export kernel_file="${IIO_TREE}/arch/arm64/boot/Image" export initrd_file="${BOOT_DIR}/initrd.img-6.1.0-44-arm64" export vm_name="arm64" function create-vm-virsh() { sudo virt-install \ --name ${vm_name} \ --memory 2048 \ --arch aarch64 \ --machine virt \ --osinfo detect=on,require=off \ --import \ --features acpi=off \ --disk path=${img_file},bus=virtio,format=qcow2 \ --boot kernel=${kernel_file},initrd=${initrd_file},kernel_args="loglevel=8 root=${root_vda} rootwait" \ --network bridge:virbr0 \ --graphics none }The problem seems to be that the device mapping was not going as expected but adding the
bus=virtio,format=qcow2did the job.
Tutorial 3 - Modules and Build Config
Pretty much uneventful tutorial, very easy to follow. For some reason I had to restart the VM network system with
systemctl restart systemd-networkd
Because virsh net-dhcp-leases default was failing to find any open connections even though its networking capabilities
were on.
Tutorial 4 - Device Characters
My only trouble in this tutorial was cross-compiling the host programs. Fedora doesn't ship a complete aarch64-compliant toolchain like Debian, so the easiest way around it (without manually installing an arm64-sysroot) was to use the Zig cross-compiler - which is honestly a shame for C/C++ compilers as it should've been easier with them anyway... Here is the simple command that made it work:
zig cc -target aarch64-linux-gnu read_prog.c -o read_prog