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