blob: 333209620b6ecd62e5b1279949d2d2667084a6d5 [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
Andrew Walbranb7849972019-11-15 15:23:43 +00006[TOC]
7
Andrew Scull23042042018-08-22 17:44:56 +01008## Build the kernel
9
10The Linux kernel for the primary VM can be built using the following
11command-line:
12
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +010013```shell
Andrew Scull23042042018-08-22 17:44:56 +010014git clone https://github.com/torvalds/linux.git
15cd linux
16ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make defconfig
17ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make -j24
18```
19
20The compiled image is stored in `arch/arm64/boot/Image`. This will later be
21copied to the Hafnium RAM disk's root as `vmlinuz`.
22
23## Build the kernel Module
24
25From the Hafnium root directory, the following commands can be used to compile
26the kernel module, replacing `<kernel-path>` with the path to the kernel checked
27out in the previous section:
28
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +010029```shell
Andrew Scull23042042018-08-22 17:44:56 +010030cd hafnium/driver/linux/
31ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- KERNEL_PATH=<kernel-path> make
32```
33
34The compiled module is called `hafnium.ko`, and will later be copied into the
35RAM disk for Linux.
36
37## Build Busybox
38
39To make Linux useful, it needs a shell. These following instructions will
40construct a file system for the Linux RAM disk with the BusyBox shell as the
41init process.
42
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +010043```shell
Andrew Scull23042042018-08-22 17:44:56 +010044git clone git://busybox.net/busybox.git
45cd busybox
46ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make defconfig
47ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make menuconfig
48```
49
50At this point you should ensure that the option `Settings > Build static binary
51(no shared libs)` is selected. Then you can proceed with the following commands:
52
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +010053```shell
Andrew Scull23042042018-08-22 17:44:56 +010054ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make -j24
55ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make install
56cd _install
57mkdir proc
58mkdir sys
59mkdir -p etc/init.d
60cat <<EOF > etc/init.d/rcS
61#!bin/sh
62mount -t proc none /proc
63mount -t sysfs none /sys
64EOF
65chmod u+x etc/init.d/rcS
66grep -v tty ../examples/inittab > ./etc/inittab
67```
68
69## Create a RAM disk for Linux
70
71At this point you can copy into the current directory additional files you may
72want in the RAM disk, for example, the kernel module built in the previous
Andrew Walbranf3f85e62018-09-18 16:57:40 +010073section. Assuming the BusyBox root directory is in the same parent directory as
74the Hafnium root directory:
75
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +010076```shell
Andrew Walbranf3f85e62018-09-18 16:57:40 +010077cp ../../hafnium/driver/linux/hafnium.ko .
78```
79
80Then run the following commands:
Andrew Scull23042042018-08-22 17:44:56 +010081
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +010082```shell
Andrew Scull23042042018-08-22 17:44:56 +010083find . | cpio -o -H newc | gzip > ../initrd.img
84cd ..
85```
86
87The resulting file is `initrd.img`. It should be copied to the Hafnium RAM
88disk's root.