Skip to content

Commit d8d4d3c

Browse files
committed
resources: Update building kernel and modules on host
1 parent 22d3fe2 commit d8d4d3c

File tree

4 files changed

+165
-28
lines changed

4 files changed

+165
-28
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Start from Ubuntu 24.04 base image
2+
FROM ubuntu:24.04
3+
4+
# Install necessary packages for kernel and module build
5+
RUN apt update && apt install -y \
6+
build-essential \
7+
libncurses-dev \
8+
bison \
9+
flex \
10+
libssl-dev \
11+
libelf-dev \
12+
bc \
13+
wget \
14+
git \
15+
kmod
16+
17+
# Set the default working directory
18+
WORKDIR /workspace
19+
20+
# Use bash as the default shell
21+
CMD ["/bin/bash"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Make kernel and the gem5 bridge driver
2+
3+
This document will highlight the steps needed to make a kernel and its modules with the gem5-bridge driver.
4+
5+
## Ubuntu 24.04 disk image
6+
7+
Assuming you are in the `src/ubuntu-generic-diskiamges` directory.
8+
`cd` to the `24.04-dockerfile` directory and build the docker image.
9+
10+
```bash
11+
cd 24.04-dockerfile
12+
docker build -t ubuntu-kernel-build .
13+
cd ..
14+
```
15+
16+
Then lets make a new directory called `my-arm-6.8.12-kernel`.
17+
This directory will have the kernel source and the modules of our built kernel.
18+
19+
```bash
20+
mkdir my-arm-6.8.12-kernel
21+
```
22+
23+
lets get the kernel source from `apt source`, we will be making the `6.8.12 96.8.0-47-generic)` kernel.
24+
25+
```bash
26+
cd my-arm-6.8.12-kernel
27+
apt source linux-image-unsigned-6.8.0-47-generic
28+
```
29+
30+
You might need to update ubuntu source list to use the above command.
31+
Checkout this post if you need to update: <https://askubuntu.com/questions/1512042/ubuntu-24-04-getting-error-you-must-put-some-deb-src-uris-in-your-sources-list>
32+
33+
Lets make an output directory that will have our built modules
34+
35+
```bash
36+
mkdir output
37+
```
38+
39+
Lets run the docker image from the `my-arm-6.8.12-kernel` directory.
40+
41+
```bash
42+
docker run --rm -it -u $UID:$GID -v ./linux-6.8.0:/workspace/source -v ./output:/workspace/output --name kernel-builder ubuntu-kernel-build
43+
```
44+
45+
Now in the docker terminal, lets build the kernel
46+
47+
```bash
48+
cd source
49+
make defconfig
50+
make -j$nproc
51+
```
52+
53+
The above commands will make the kernel and the modules.
54+
lets install the modules to the output directory
55+
56+
```bash
57+
make INSTALL_MOD_PATH=/workspace/output modules_install
58+
```
59+
60+
After the modules are installed, lets install our gem5-bridge driver.
61+
62+
in the `/workspace/source`, lets get the driver files
63+
64+
```bash
65+
git clone https://github.com/nkrim/gem5.git --depth=1 --filter=blob:none --no-checkout --sparse --single-branch --branch=gem5-bridge
66+
cd gem5
67+
git sparse-checkout add util/m5
68+
git sparse-checkout add util/gem5_bridge
69+
git sparse-checkout add include
70+
git checkout
71+
```
72+
Now lets make our driver
73+
74+
```bash
75+
cd util/gem5_bridge
76+
make KMAKEDIR=/workspace/source INSTALL_MOD_PATH=/workspace/output build install
77+
```
78+
79+
The above command specifies the kernel source path and the output path.
80+
You can find the kernel at `src/ubuntu-generic-diskimages/my-arm-6.8.12-kernel/linux-6.8.0/vmlinux`
81+
and the modules at `src/ubuntu-generic-diskimages/my-arm-6.8.12-kernel/output/lib/modules/6.8.12`.
82+
83+
Now lets move the modules to our disk image.
84+
85+
First you will need to delete the `build` file in `src/ubuntu-generic-diskimages/my-arm-6.8.12-kernel/output/lib/modules/6.8.12` as that is a symlink to the `/workspace` directory in source
86+
87+
```bash
88+
rm output/lib/modules/6.8.12/build
89+
```
90+
91+
now add the following file provisioner to move the files from host to the disk
92+
93+
```hcl
94+
provisioner "file" {
95+
destination= "/home/gem5"
96+
source = "my-arm-6.8.12-kernel/output/lib/modules/6.8.12"
97+
}
98+
```
99+
100+
also add the following lines in the post install script to move the modules to `/lib/modules` and run `depmode` and `initramfs`
101+
102+
```bash
103+
mv /home/gem5/6.8.12 /lib/modules/6.8.12
104+
depmod --quick -a 6.8.12
105+
update-initramfs -u -k 6.8.12
106+
```
107+
108+
Now you can run a gem5 fs simulation with this disk and the kernel we just made to use the new gem 5-bridge driver.

src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl

+6-5
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,16 @@ build {
133133
source = "files/[email protected]"
134134
}
135135

136+
provisioner "file" {
137+
destination= "/home/gem5"
138+
source = "my-arm-6.8.12-kernel/output/lib/modules/6.8.12"
139+
}
140+
136141
provisioner "shell" {
137142
execute_command = "echo '${var.ssh_password}' | {{ .Vars }} sudo -E -S bash '{{ .Path }}'"
138143
scripts = ["scripts/post-installation.sh"]
139144
environment_vars = ["ISA=arm64"]
140145
expect_disconnect = true
141146
}
142-
provisioner "file" {
143-
source = "/home/gem5/my-arm-kernel/linux-6.8.0/vmlinux"
144-
destination = "./arm-disk-image-24-04/vmlinux"
145-
direction = "download"
146-
}
147+
147148
}

src/ubuntu-generic-diskimages/scripts/post-installation.sh

+30-23
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,33 @@ apt-get install -y build-essential
1818
echo "Installing serial service for autologin after systemd"
1919
mv /home/gem5/[email protected] /lib/systemd/system/
2020

21-
apt-get update
22-
apt-get install -y fakeroot build-essential crash kexec-tools makedumpfile kernel-wedge
23-
# Fixing the sources.list file to include deb-src: https://askubuntu.com/questions/1512042/ubuntu-24-04-getting-error-you-must-put-some-deb-src-uris-in-your-sources-list
24-
sed -i 's/^Types: deb$/Types: deb deb-src/' /etc/apt/sources.list.d/ubuntu.sources
21+
# apt-get update
22+
# apt-get install -y fakeroot build-essential crash kexec-tools makedumpfile kernel-wedge
23+
# # Fixing the sources.list file to include deb-src: https://askubuntu.com/questions/1512042/ubuntu-24-04-getting-error-you-must-put-some-deb-src-uris-in-your-sources-list
24+
# sed -i 's/^Types: deb$/Types: deb deb-src/' /etc/apt/sources.list.d/ubuntu.sources
25+
26+
# apt update
27+
28+
# apt-get -y build-dep linux
29+
# apt-get -y install git-core libncurses5 libncurses5-dev libelf-dev asciidoc binutils-dev
30+
# apt-get -y install libssl-dev
31+
# apt -y install flex bison
32+
# apt -y install zstd
2533

26-
apt update
34+
# mkdir my-arm-kernel
35+
# cd my-arm-kernel
36+
# apt source linux-image-unsigned-6.8.0-47-generic
37+
# cd linux-6.8.0
38+
# cp /boot/config-$(uname -r) .config
39+
# make -j$(nproc) vmlinux
2740

28-
apt-get -y build-dep linux
29-
apt-get -y install git-core libncurses5 libncurses5-dev libelf-dev asciidoc binutils-dev
30-
apt-get -y install libssl-dev
31-
apt -y install flex bison
32-
apt -y install zstd
41+
# chmod +x ./debian/scripts/sign-module
42+
# make -j$(nproc) modules
43+
# make -j modules_install
3344

34-
mkdir my-arm-kernel
35-
cd my-arm-kernel
36-
apt source linux-image-unsigned-$(uname -r)
37-
cd linux-6.8.0
38-
cp /boot/config-$(uname -r) .config
39-
make -j$(nproc) vmlinux
45+
mv /home/gem5/6.8.12 /lib/modules/6.8.12
4046

41-
chmod +x ./debian/scripts/sign-module
42-
make -j$(nproc) modules
43-
make -j modules_install
47+
depmod --quick -a 6.8.12
4448

4549
update-initramfs -u -k 6.8.12
4650

@@ -84,10 +88,11 @@ cp build/${ISA}/out/libm5.a /usr/local/lib/
8488
popd # util/m5
8589

8690
# Build and insert the gem5-bridge driver
87-
pushd util/gem5_bridge
88-
make build install
89-
depmod --quick
90-
popd
91+
# pushd util/gem5_bridge
92+
# make build install
93+
94+
95+
# popd
9196

9297
popd # gem5
9398

@@ -121,3 +126,5 @@ systemctl disable systemd-networkd-wait-online.service
121126
systemctl mask systemd-networkd-wait-online.service
122127

123128
echo "Post Installation Done"
129+
130+
sleep 10m

0 commit comments

Comments
 (0)