| Andrew Scull | 2304204 | 2018-08-22 17:44:56 +0100 | [diff] [blame] | 1 | # Preparing Linux |
| 2 | |
| 3 | To boot Linux, a kernel image (`vmlinuz`) and a suitable initial RAM disk |
| 4 | (`initrd.img`) need to be created. |
| 5 | |
| Andrew Walbran | b784997 | 2019-11-15 15:23:43 +0000 | [diff] [blame] | 6 | [TOC] |
| 7 | |
| Andrew Scull | 2304204 | 2018-08-22 17:44:56 +0100 | [diff] [blame] | 8 | ## Build the kernel |
| 9 | |
| 10 | The Linux kernel for the primary VM can be built using the following |
| 11 | command-line: |
| 12 | |
| Andrew Walbran | 6f8fd4c | 2019-08-05 13:28:17 +0100 | [diff] [blame] | 13 | ```shell |
| Andrew Scull | 2304204 | 2018-08-22 17:44:56 +0100 | [diff] [blame] | 14 | git clone https://github.com/torvalds/linux.git |
| 15 | cd linux |
| 16 | ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make defconfig |
| 17 | ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make -j24 |
| 18 | ``` |
| 19 | |
| 20 | The compiled image is stored in `arch/arm64/boot/Image`. This will later be |
| 21 | copied to the Hafnium RAM disk's root as `vmlinuz`. |
| 22 | |
| 23 | ## Build the kernel Module |
| 24 | |
| 25 | From the Hafnium root directory, the following commands can be used to compile |
| 26 | the kernel module, replacing `<kernel-path>` with the path to the kernel checked |
| 27 | out in the previous section: |
| 28 | |
| Andrew Walbran | 6f8fd4c | 2019-08-05 13:28:17 +0100 | [diff] [blame] | 29 | ```shell |
| Andrew Scull | 2304204 | 2018-08-22 17:44:56 +0100 | [diff] [blame] | 30 | cd hafnium/driver/linux/ |
| 31 | ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- KERNEL_PATH=<kernel-path> make |
| 32 | ``` |
| 33 | |
| 34 | The compiled module is called `hafnium.ko`, and will later be copied into the |
| 35 | RAM disk for Linux. |
| 36 | |
| 37 | ## Build Busybox |
| 38 | |
| 39 | To make Linux useful, it needs a shell. These following instructions will |
| 40 | construct a file system for the Linux RAM disk with the BusyBox shell as the |
| 41 | init process. |
| 42 | |
| Andrew Walbran | 6f8fd4c | 2019-08-05 13:28:17 +0100 | [diff] [blame] | 43 | ```shell |
| Andrew Scull | 2304204 | 2018-08-22 17:44:56 +0100 | [diff] [blame] | 44 | git clone git://busybox.net/busybox.git |
| 45 | cd busybox |
| 46 | ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make defconfig |
| 47 | ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make menuconfig |
| 48 | ``` |
| 49 | |
| 50 | At 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 Walbran | 6f8fd4c | 2019-08-05 13:28:17 +0100 | [diff] [blame] | 53 | ```shell |
| Andrew Scull | 2304204 | 2018-08-22 17:44:56 +0100 | [diff] [blame] | 54 | ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make -j24 |
| 55 | ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make install |
| 56 | cd _install |
| 57 | mkdir proc |
| 58 | mkdir sys |
| 59 | mkdir -p etc/init.d |
| 60 | cat <<EOF > etc/init.d/rcS |
| 61 | #!bin/sh |
| 62 | mount -t proc none /proc |
| 63 | mount -t sysfs none /sys |
| 64 | EOF |
| 65 | chmod u+x etc/init.d/rcS |
| 66 | grep -v tty ../examples/inittab > ./etc/inittab |
| 67 | ``` |
| 68 | |
| 69 | ## Create a RAM disk for Linux |
| 70 | |
| 71 | At this point you can copy into the current directory additional files you may |
| 72 | want in the RAM disk, for example, the kernel module built in the previous |
| Andrew Walbran | f3f85e6 | 2018-09-18 16:57:40 +0100 | [diff] [blame] | 73 | section. Assuming the BusyBox root directory is in the same parent directory as |
| 74 | the Hafnium root directory: |
| 75 | |
| Andrew Walbran | 6f8fd4c | 2019-08-05 13:28:17 +0100 | [diff] [blame] | 76 | ```shell |
| Andrew Walbran | f3f85e6 | 2018-09-18 16:57:40 +0100 | [diff] [blame] | 77 | cp ../../hafnium/driver/linux/hafnium.ko . |
| 78 | ``` |
| 79 | |
| 80 | Then run the following commands: |
| Andrew Scull | 2304204 | 2018-08-22 17:44:56 +0100 | [diff] [blame] | 81 | |
| Andrew Walbran | 6f8fd4c | 2019-08-05 13:28:17 +0100 | [diff] [blame] | 82 | ```shell |
| Andrew Scull | 2304204 | 2018-08-22 17:44:56 +0100 | [diff] [blame] | 83 | find . | cpio -o -H newc | gzip > ../initrd.img |
| 84 | cd .. |
| 85 | ``` |
| 86 | |
| 87 | The resulting file is `initrd.img`. It should be copied to the Hafnium RAM |
| 88 | disk's root. |