-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup-qemu-kernel.sh
executable file
·64 lines (47 loc) · 1.96 KB
/
setup-qemu-kernel.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
set -ex
cd "$(dirname "$0")"
ARCH=arm64
ROOT_DIR=$HOME
NUM_CORES=${NUM_CORES:-$(nproc)}
IMAGE_FILE=""
# The most recent linux kernel version at the time of this writing.
# Might need to be updated in the future.
KERNEL_VERSION="linux-6.6.8"
# Install the required packages. These include cross-compilers for arm64
# and required packages for QEMU itself.
sudo apt install -y \
gcc-aarch64-linux-gnu \
g++-aarch64-linux-gnu \
qemu \
qemubuilder \
qemu-system-arm \
qemu-utils \
qemu-system-data \
qemu-system \
flex \
bison \
libssl-dev
# Build the Linux kernel for qemu arm64
# The kernel can be downloaded from https://www.kernel.org/
# tar xvJf means: -x: extract, -v: verbose, -J: use the xz compression, -f: specify archive name
if [ -d "$KERNEL_VERSION" ]; then
echo "Directory $KERNEL_VERSION already exists, skipping download and extraction."
else
# Downloading the kernel source
echo "Downloading Linux kernel version $KERNEL_VERSION..."
wget "https://cdn.kernel.org/pub/linux/kernel/v6.x/${KERNEL_VERSION}.tar.xz"
# Extracting the kernel source
echo "Extracting ${KERNEL_VERSION}.tar.xz..."
tar xvJf "${KERNEL_VERSION}.tar.xz"
fi
cd "$KERNEL_VERSION"
# Create a .config file: This requires having flex and bison packages installed:
# Flex (Fast Lexial Analyzer Generator) is used for tokenizing input (breaking it into a series of tokens)
# and Bison takes these tokens and analyzes their structure to understand the higher-level syntax.
ARCH=${ARCH} CROSS_COMPILE=/bin/aarch64-linux-gnu- make defconfig
# Use the kvm_guest (kernel virtual machine) config as the base defconfig, which is suitable for qemu
ARCH=${ARCH} CROSS_COMPILE=/bin/aarch64-linux-gnu- make kvm_guest.config
# Build the kernel (parallelizable if nproc > 1)
ARCH=${ARCH} CROSS_COMPILE=/bin/aarch64-linux-gnu- make -j${NUM_CORES}
cp arch/${ARCH}/boot/Image ${ROOT_DIR}