blob: 96549604c769c16daff66fe6510587439fc59de7 [file] [log] [blame] [view]
Andrew Scull23042042018-08-22 17:44:56 +01001# Preparing Linux
2
3To boot Linux, a kernel image (`vmlinuz`) and a suitable initial RAM disk
4(`initrd.img`) need to be created.
5
6## Build the kernel
7
8The Linux kernel for the primary VM can be built using the following
9command-line:
10
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +010011```shell
Andrew Scull23042042018-08-22 17:44:56 +010012git clone https://github.com/torvalds/linux.git
13cd linux
14ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make defconfig
15ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make -j24
16```
17
18The compiled image is stored in `arch/arm64/boot/Image`. This will later be
19copied to the Hafnium RAM disk's root as `vmlinuz`.
20
21## Build the kernel Module
22
23From the Hafnium root directory, the following commands can be used to compile
24the kernel module, replacing `<kernel-path>` with the path to the kernel checked
25out in the previous section:
26
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +010027```shell
Andrew Scull23042042018-08-22 17:44:56 +010028cd hafnium/driver/linux/
29ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- KERNEL_PATH=<kernel-path> make
30```
31
32The compiled module is called `hafnium.ko`, and will later be copied into the
33RAM disk for Linux.
34
35## Build Busybox
36
37To make Linux useful, it needs a shell. These following instructions will
38construct a file system for the Linux RAM disk with the BusyBox shell as the
39init process.
40
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +010041```shell
Andrew Scull23042042018-08-22 17:44:56 +010042git clone git://busybox.net/busybox.git
43cd busybox
44ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make defconfig
45ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make menuconfig
46```
47
48At this point you should ensure that the option `Settings > Build static binary
49(no shared libs)` is selected. Then you can proceed with the following commands:
50
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +010051```shell
Andrew Scull23042042018-08-22 17:44:56 +010052ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make -j24
53ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make install
54cd _install
55mkdir proc
56mkdir sys
57mkdir -p etc/init.d
58cat <<EOF > etc/init.d/rcS
59#!bin/sh
60mount -t proc none /proc
61mount -t sysfs none /sys
62EOF
63chmod u+x etc/init.d/rcS
64grep -v tty ../examples/inittab > ./etc/inittab
65```
66
67## Create a RAM disk for Linux
68
69At this point you can copy into the current directory additional files you may
70want in the RAM disk, for example, the kernel module built in the previous
Andrew Walbranf3f85e62018-09-18 16:57:40 +010071section. Assuming the BusyBox root directory is in the same parent directory as
72the Hafnium root directory:
73
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +010074```shell
Andrew Walbranf3f85e62018-09-18 16:57:40 +010075cp ../../hafnium/driver/linux/hafnium.ko .
76```
77
78Then run the following commands:
Andrew Scull23042042018-08-22 17:44:56 +010079
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +010080```shell
Andrew Scull23042042018-08-22 17:44:56 +010081find . | cpio -o -H newc | gzip > ../initrd.img
82cd ..
83```
84
85The resulting file is `initrd.img`. It should be copied to the Hafnium RAM
86disk's root.