From 8459cdf922246e0cdb46dd1d05b67675938a0307 Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Tue, 4 Feb 2025 12:17:07 -0800 Subject: [PATCH 01/18] resources: Add hypercall for x86 base disk image --- src/ubuntu-generic-diskimages/files/x86/after_boot.sh | 4 ++-- src/ubuntu-generic-diskimages/files/x86/gem5_init.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ubuntu-generic-diskimages/files/x86/after_boot.sh b/src/ubuntu-generic-diskimages/files/x86/after_boot.sh index c503c0f1f..db281d0c9 100755 --- a/src/ubuntu-generic-diskimages/files/x86/after_boot.sh +++ b/src/ubuntu-generic-diskimages/files/x86/after_boot.sh @@ -14,7 +14,7 @@ # gem5-bridge exit signifying that after_boot.sh is running printf "In after_boot.sh...\n" -gem5-bridge exit # TODO: Make this a specialized event. +gem5-bridge hypercall 2 # Read /proc/cmdline and parse options @@ -51,7 +51,7 @@ else /tmp/script printf "Done running script from gem5-bridge, exiting.\n" rm -f /tmp/script - gem5-bridge exit + gem5-bridge hypercall 3 fi fi fi diff --git a/src/ubuntu-generic-diskimages/files/x86/gem5_init.sh b/src/ubuntu-generic-diskimages/files/x86/gem5_init.sh index 553531732..bccf6826f 100755 --- a/src/ubuntu-generic-diskimages/files/x86/gem5_init.sh +++ b/src/ubuntu-generic-diskimages/files/x86/gem5_init.sh @@ -19,7 +19,7 @@ no_systemd=false # This will cause the simulation to exit. Note that this will # cause qemu to fail. printf "Kernel booted, In gem5 init...\n" -gem5-bridge exit # TODO: Make this a specialized event. +gem5-bridge hypercall 1 if [[ $cmdline == *"no_systemd"* ]]; then no_systemd=true From e6c5228a8b597460b29dfadfe452313f657c537f Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Tue, 4 Feb 2025 14:17:13 -0800 Subject: [PATCH 02/18] resources: Update scripts to add and build gem5 bridge driver for x86 disk image --- .../files/x86/gem5_init.sh | 16 ++++++++++++++++ .../packer-scripts/x86-ubuntu.pkr.hcl | 2 +- .../scripts/post-installation.sh | 14 +++++++++++++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/ubuntu-generic-diskimages/files/x86/gem5_init.sh b/src/ubuntu-generic-diskimages/files/x86/gem5_init.sh index bccf6826f..e421f8a2d 100755 --- a/src/ubuntu-generic-diskimages/files/x86/gem5_init.sh +++ b/src/ubuntu-generic-diskimages/files/x86/gem5_init.sh @@ -15,6 +15,22 @@ mount -t sysfs /sys /sys cmdline=$(cat /proc/cmdline) no_systemd=false +# Load gem5_bridge driver +## Default parameters (x86_64) +gem5_bridge_baseaddr=0xffff0000 +gem5_bridge_rangesize=0x10000 +## Try to read overloads from kernel arguments +if [[ $cmdline =~ gem5_bridge_baseaddr=([[:alnum:]]+) ]]; then + gem5_bridge_baseaddr=${BASH_REMATCH[1]} +fi +if [[ $cmdline =~ gem5_bridge_rangesize=([[:alnum:]]+) ]]; then + gem5_bridge_rangesize=${BASH_REMATCH[1]} +fi +## Insert driver +modprobe gem5_bridge \ + gem5_bridge_baseaddr=$gem5_bridge_baseaddr \ + gem5_bridge_rangesize=$gem5_bridge_rangesize + # gem5-bridge exit signifying that kernel is booted # This will cause the simulation to exit. Note that this will # cause qemu to fail. diff --git a/src/ubuntu-generic-diskimages/packer-scripts/x86-ubuntu.pkr.hcl b/src/ubuntu-generic-diskimages/packer-scripts/x86-ubuntu.pkr.hcl index 3d88dce63..04b752d96 100644 --- a/src/ubuntu-generic-diskimages/packer-scripts/x86-ubuntu.pkr.hcl +++ b/src/ubuntu-generic-diskimages/packer-scripts/x86-ubuntu.pkr.hcl @@ -105,7 +105,7 @@ build { provisioner "file" { source = "/home/gem5/vmlinux-x86-ubuntu" - destination = "./disk-image/vmlinux-x86-ubuntu" + destination = "./${local.iso_data[var.ubuntu_version].output_dir}/vmlinux-x86-ubuntu" direction = "download" } } diff --git a/src/ubuntu-generic-diskimages/scripts/post-installation.sh b/src/ubuntu-generic-diskimages/scripts/post-installation.sh index 1f37ac98b..9bb593f1a 100755 --- a/src/ubuntu-generic-diskimages/scripts/post-installation.sh +++ b/src/ubuntu-generic-diskimages/scripts/post-installation.sh @@ -47,10 +47,11 @@ if [ -z "$ISA" ]; then fi # Just get the files we need -git clone https://github.com/gem5/gem5.git --depth=1 --filter=blob:none --no-checkout --sparse --single-branch --branch=stable +git clone https://github.com/gem5/gem5.git --depth=1 --filter=blob:none --no-checkout --sparse --single-branch --branch=release-staging-v24-1-1-0 pushd gem5 # Checkout just the files we need git sparse-checkout add util/m5 +git sparse-checkout add util/gem5_bridge git sparse-checkout add include git checkout # Install the headers globally so that other benchmarks can use them @@ -62,6 +63,17 @@ scons build/${ISA}/out/m5 cp build/${ISA}/out/m5 /usr/local/bin/ cp build/${ISA}/out/libm5.a /usr/local/lib/ popd # util/m5 + +if [ "${ISA}" = "x86" ]; then + # Build and insert the gem5-bridge driver + # as we are extracting the kernel from + # the disk image. + pushd util/gem5_bridge + make build install + depmod --quick + popd +fi + popd # gem5 # rename the m5 binary to gem5-bridge From fa35116102b229f9eefffd8c3fb140bd33db5d61 Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Tue, 4 Feb 2025 14:19:07 -0800 Subject: [PATCH 03/18] resources: Update exit event call to hypercall for the arm disk images --- src/ubuntu-generic-diskimages/files/arm/after_boot.sh | 4 ++-- src/ubuntu-generic-diskimages/files/arm/gem5_init.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ubuntu-generic-diskimages/files/arm/after_boot.sh b/src/ubuntu-generic-diskimages/files/arm/after_boot.sh index e462de018..62d9a12ac 100755 --- a/src/ubuntu-generic-diskimages/files/arm/after_boot.sh +++ b/src/ubuntu-generic-diskimages/files/arm/after_boot.sh @@ -14,7 +14,7 @@ # gem5-bridge exit signifying that after_boot.sh is running printf "In after_boot.sh...\n" -gem5-bridge --addr=0x10010000 exit # TODO: Make this a specialized event. +gem5-bridge --addr=0x10010000 hypercall 2 # Read /proc/cmdline and parse options @@ -51,7 +51,7 @@ else /tmp/script printf "Done running script from gem5-bridge, exiting.\n" rm -f /tmp/script - gem5-bridge --addr=0x10010000 exit + gem5-bridge --addr=0x10010000 hypercall 3 fi fi fi diff --git a/src/ubuntu-generic-diskimages/files/arm/gem5_init.sh b/src/ubuntu-generic-diskimages/files/arm/gem5_init.sh index 0c13e97ad..2cfc6ecee 100755 --- a/src/ubuntu-generic-diskimages/files/arm/gem5_init.sh +++ b/src/ubuntu-generic-diskimages/files/arm/gem5_init.sh @@ -19,7 +19,7 @@ no_systemd=false # This will cause the simulation to exit. Note that this will # cause qemu to fail. printf "Kernel booted, In gem5 init...\n" -gem5-bridge --addr=0x10010000 exit # TODO: Make this a specialized event. +gem5-bridge --addr=0x10010000 hypercall 1 if [[ $cmdline == *"no_systemd"* ]]; then no_systemd=true From c6e44ecd75f5e843b5968c7c8258e5441248de55 Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Tue, 4 Feb 2025 14:56:20 -0800 Subject: [PATCH 04/18] resources: Add dockerfile to make kernel and modules for arm disk image --- .../arm-ubuntu-22.04/Dockerfile | 45 +++++++++++++++++++ .../arm-ubuntu-22.04/copy_modules_to_host.sh | 14 ++++++ .../arm-ubuntu-24.04/Dockerfile | 43 ++++++++++++++++++ .../arm-ubuntu-24.04/copy_modules_to_host.sh | 14 ++++++ 4 files changed, 116 insertions(+) create mode 100644 src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-22.04/Dockerfile create mode 100755 src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-22.04/copy_modules_to_host.sh create mode 100644 src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-24.04/Dockerfile create mode 100755 src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-24.04/copy_modules_to_host.sh diff --git a/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-22.04/Dockerfile b/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-22.04/Dockerfile new file mode 100644 index 000000000..76ef58dd2 --- /dev/null +++ b/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-22.04/Dockerfile @@ -0,0 +1,45 @@ +FROM ubuntu:22.04 AS stage1 + +# Install necessary packages for kernel build +RUN apt update && apt install -y \ + build-essential \ + libncurses-dev \ + bison \ + flex \ + libssl-dev \ + libelf-dev \ + bc \ + wget \ + git \ + kmod \ + apt-src \ + vim \ + curl \ + file + +RUN sed -Ei 's/^# deb-src /deb-src /' /etc/apt/sources.list +RUN apt update +RUN mkdir /workspace +RUN cd /workspace && apt source linux-image-unsigned-5.15.0-25-generic + +RUN cd /workspace/linux-5.15.0 && \ + make defconfig && \ + make -j 32 && \ + make INSTALL_MOD_PATH=/workspace/output modules_install + +RUN git clone https://github.com/nkrim/gem5.git --depth=1 --filter=blob:none --no-checkout --sparse --single-branch --branch=gem5-bridge && \ + cd gem5 && \ + git sparse-checkout add util/m5 && \ + git sparse-checkout add util/gem5_bridge && \ + git sparse-checkout add include && \ + git checkout + +RUN cd gem5/util/gem5_bridge && \ + make KMAKEDIR=/workspace/linux-5.15.0 INSTALL_MOD_PATH=/workspace/output build install + +RUN cd /workspace/output/lib/modules/5.15.* && \ + rm -rf build source + +FROM scratch AS export-stage +COPY --from=stage1 /workspace/output/lib/modules . +COPY --from=stage1 workspace/linux-5.15.0/vmlinux . \ No newline at end of file diff --git a/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-22.04/copy_modules_to_host.sh b/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-22.04/copy_modules_to_host.sh new file mode 100755 index 000000000..fb61543b3 --- /dev/null +++ b/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-22.04/copy_modules_to_host.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +# Copyright (c) 2025 The Regents of the University of California. +# SPDX-License-Identifier: BSD 3-Clause + +DOCKERFILE="./22.04-dockerfile/Dockerfile" +OUTPUT="my-arm-5.15.167-kernel" + +# Build the Docker image +DOCKER_BUILDKIT=1 docker build --no-cache \ + --file "$DOCKERFILE" \ + --output "$OUTPUT" . + +echo "Build completed for $1: Output directory is $OUTPUT" \ No newline at end of file diff --git a/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-24.04/Dockerfile b/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-24.04/Dockerfile new file mode 100644 index 000000000..f230b2d95 --- /dev/null +++ b/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-24.04/Dockerfile @@ -0,0 +1,43 @@ +# Start from Ubuntu 24.04 base image +FROM ubuntu:24.04 AS stage1 + +# Install necessary packages for kernel and module build +RUN apt update && apt install -y \ + build-essential \ + libncurses-dev \ + bison \ + flex \ + libssl-dev \ + libelf-dev \ + bc \ + wget \ + git \ + kmod + + +RUN sed -i 's/^Types: deb$/Types: deb deb-src/' /etc/apt/sources.list.d/ubuntu.sources +RUN apt update +RUN mkdir /workspace +RUN cd /workspace && apt source linux-image-unsigned-6.8.0-47-generic + +RUN cd /workspace/linux-6.8.0 && \ + make defconfig && \ + make -j 32 && \ + make INSTALL_MOD_PATH=/workspace/output modules_install + +RUN git clone https://github.com/nkrim/gem5.git --depth=1 --filter=blob:none --no-checkout --sparse --single-branch --branch=gem5-bridge && \ + cd gem5 && \ + git sparse-checkout add util/m5 && \ + git sparse-checkout add util/gem5_bridge && \ + git sparse-checkout add include && \ + git checkout + +RUN cd gem5/util/gem5_bridge && \ + make KMAKEDIR=/workspace/linux-6.8.0 INSTALL_MOD_PATH=/workspace/output build install + +RUN cd /workspace/output/lib/modules/6.8.12 && \ + rm -rf build + +FROM scratch AS export-stage +COPY --from=stage1 /workspace/output/lib/modules . +COPY --from=stage1 /workspace/linux-6.8.0/vmlinux . \ No newline at end of file diff --git a/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-24.04/copy_modules_to_host.sh b/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-24.04/copy_modules_to_host.sh new file mode 100755 index 000000000..1d023273a --- /dev/null +++ b/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-24.04/copy_modules_to_host.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +# Copyright (c) 2025 The Regents of the University of California. +# SPDX-License-Identifier: BSD 3-Clause + +DOCKERFILE="./Dockerfile" +OUTPUT="my-arm-6.8.12-kernel" + +# Build the Docker image +DOCKER_BUILDKIT=1 docker build --no-cache \ + --file "$DOCKERFILE" \ + --output "$OUTPUT" . + +echo "Build completed for $1: Output directory is $OUTPUT" \ No newline at end of file From ef1b6ef8a62eee1d005f97b41a06b53c267ec6fe Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Tue, 4 Feb 2025 16:13:26 -0800 Subject: [PATCH 05/18] resources: Update serial-getty service to override service section - This commit updates the serial-getty service file to override only the service section with autologin instead of the entire file. --- .../files/serial-getty@.service | 46 ------------------- .../files/serial-getty@.service-override.conf | 4 ++ 2 files changed, 4 insertions(+), 46 deletions(-) delete mode 100644 src/ubuntu-generic-diskimages/files/serial-getty@.service create mode 100644 src/ubuntu-generic-diskimages/files/serial-getty@.service-override.conf diff --git a/src/ubuntu-generic-diskimages/files/serial-getty@.service b/src/ubuntu-generic-diskimages/files/serial-getty@.service deleted file mode 100644 index 121e8e355..000000000 --- a/src/ubuntu-generic-diskimages/files/serial-getty@.service +++ /dev/null @@ -1,46 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1+ -# -# This file is part of systemd. -# -# systemd is free software; you can redistribute it and/or modify it -# under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation; either version 2.1 of the License, or -# (at your option) any later version. - -[Unit] -Description=Serial Getty on %I -Documentation=man:agetty(8) man:systemd-getty-generator(8) -Documentation=http://0pointer.de/blog/projects/serial-console.html -BindsTo=dev-%i.device -After=dev-%i.device systemd-user-sessions.service plymouth-quit-wait.service getty-pre.target -After=rc-local.service - -# If additional gettys are spawned during boot then we should make -# sure that this is synchronized before getty.target, even though -# getty.target didn't actually pull it in. -Before=getty.target -IgnoreOnIsolate=yes - -# IgnoreOnIsolate causes issues with sulogin, if someone isolates -# rescue.target or starts rescue.service from multi-user.target or -# graphical.target. -Conflicts=rescue.service -Before=rescue.service - -[Service] -# The '-o' option value tells agetty to replace 'login' arguments with an -# option to preserve environment (-p), followed by '--' for safety, and then -# the entered username. -ExecStart=-/sbin/agetty --autologin gem5 --keep-baud 115200,38400,9600 %I $TERM -Type=idle -Restart=always -UtmpIdentifier=%I -TTYPath=/dev/%I -TTYReset=yes -TTYVHangup=yes -KillMode=process -IgnoreSIGPIPE=no -SendSIGHUP=yes - -[Install] -WantedBy=getty.target diff --git a/src/ubuntu-generic-diskimages/files/serial-getty@.service-override.conf b/src/ubuntu-generic-diskimages/files/serial-getty@.service-override.conf new file mode 100644 index 000000000..031f440cf --- /dev/null +++ b/src/ubuntu-generic-diskimages/files/serial-getty@.service-override.conf @@ -0,0 +1,4 @@ + +[Service] +ExecStart= +ExecStart=-/sbin/agetty --autologin gem5 --keep-baud 115200,38400,9600 %I $TERM From 0f24310c18e385b44fa6c203055ca21ea2084bda Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Tue, 4 Feb 2025 16:15:16 -0800 Subject: [PATCH 06/18] resources: split post-installation.sh to smaller scripts --- .../packer-scripts/arm-ubuntu.pkr.hcl | 27 +++- .../packer-scripts/x86-ubuntu.pkr.hcl | 23 ++- .../scripts/disable-network.sh | 12 ++ .../scripts/disable-systemd-services-x86.sh | 32 ++++ .../scripts/extract-x86-kernel.sh | 11 ++ .../scripts/install-common-packages.sh | 32 ++++ .../scripts/install-gem5-bridge.sh | 56 +++++++ .../scripts/install-user-benchmarks.sh | 15 ++ .../scripts/install-user-packages.sh | 18 +++ .../scripts/post-installation.sh | 138 ------------------ .../scripts/update-gem5-init.sh | 12 ++ .../scripts/update-modules-arm-22.04.sh | 13 ++ .../scripts/update-modules-arm-24.04.sh | 13 ++ 13 files changed, 259 insertions(+), 143 deletions(-) create mode 100755 src/ubuntu-generic-diskimages/scripts/disable-network.sh create mode 100755 src/ubuntu-generic-diskimages/scripts/disable-systemd-services-x86.sh create mode 100755 src/ubuntu-generic-diskimages/scripts/extract-x86-kernel.sh create mode 100755 src/ubuntu-generic-diskimages/scripts/install-common-packages.sh create mode 100755 src/ubuntu-generic-diskimages/scripts/install-gem5-bridge.sh create mode 100755 src/ubuntu-generic-diskimages/scripts/install-user-benchmarks.sh create mode 100755 src/ubuntu-generic-diskimages/scripts/install-user-packages.sh delete mode 100755 src/ubuntu-generic-diskimages/scripts/post-installation.sh create mode 100755 src/ubuntu-generic-diskimages/scripts/update-gem5-init.sh create mode 100755 src/ubuntu-generic-diskimages/scripts/update-modules-arm-22.04.sh create mode 100755 src/ubuntu-generic-diskimages/scripts/update-modules-arm-24.04.sh diff --git a/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl b/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl index 6e81dd5e6..3e0ad4b3c 100644 --- a/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl +++ b/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl @@ -38,12 +38,14 @@ locals { iso_checksum = "sha256:c209ab013280d3cd26a344def60b7b19fbb427de904ea285057d94ca6ac82dd5" output_dir = "arm-disk-image-22-04" http_directory = "http/arm-22-04" + modules_dir = "kernel-and-modules/arm-ubuntu-22.04/my-arm-5.15.167-kernel/5.15.167" } "24.04" = { iso_url = "https://cdimage.ubuntu.com/releases/24.04/release/ubuntu-24.04-live-server-arm64.iso" iso_checksum = "sha256:d2d9986ada3864666e36a57634dfc97d17ad921fa44c56eeaca801e7dab08ad7" output_dir = "arm-disk-image-24-04" http_directory = "http/arm-24-04" + modules_dir = "kernel-and-modules/arm-ubuntu-24.04/my-arm-6.8.12-kernel/6.8.12" } } } @@ -130,13 +132,34 @@ build { provisioner "file" { destination = "/home/gem5/" - source = "files/serial-getty@.service" + source = "files/serial-getty@.service-override.conf" + } + + provisioner "file" { + destination = "/home/gem5/" + source = "${local.iso_data[var.ubuntu_version].modules_dir}" } provisioner "shell" { execute_command = "echo '${var.ssh_password}' | {{ .Vars }} sudo -E -S bash '{{ .Path }}'" - scripts = ["scripts/post-installation.sh"] + scripts = ["scripts/install-common-packages.sh", + "scripts/update-modules-arm-${var.ubuntu_version}.sh", + "scripts/update-gem5-init.sh", + "scripts/install-gem5-bridge.sh", + "scripts/install-user-packages.sh", + ] environment_vars = ["ISA=arm64"] expect_disconnect = true } + + provisioner "shell" { + scripts = ["files/serial-getty@.service-override.conf"] + } + + provisioner "shell" { + execute_command = "echo '${var.ssh_password}' | {{ .Vars }} sudo -E -S bash '{{ .Path }}'" + scripts = ["scripts/disable-network.sh"] + expect_disconnect = true + } + } diff --git a/src/ubuntu-generic-diskimages/packer-scripts/x86-ubuntu.pkr.hcl b/src/ubuntu-generic-diskimages/packer-scripts/x86-ubuntu.pkr.hcl index 04b752d96..5c9c8aafa 100644 --- a/src/ubuntu-generic-diskimages/packer-scripts/x86-ubuntu.pkr.hcl +++ b/src/ubuntu-generic-diskimages/packer-scripts/x86-ubuntu.pkr.hcl @@ -93,15 +93,32 @@ build { provisioner "file" { destination = "/home/gem5/" - source = "files/serial-getty@.service" + source = "files/serial-getty@.service-override.conf" } provisioner "shell" { execute_command = "echo '${var.ssh_password}' | {{ .Vars }} sudo -E -S bash '{{ .Path }}'" - scripts = ["scripts/post-installation.sh"] + scripts = ["scripts/install-common-packages.sh", + "scripts/extract-x86-kernel.sh", + "scripts/update-gem5-init.sh", + "scripts/install-gem5-bridge.sh", + "scripts/install-user-packages.sh", + ] environment_vars = ["ISA=x86"] + expect_disconnect = true + } + + provisioner "shell" { + scripts = ["scripts/install-user-benchmarks.sh"] + } + + provisioner "shell" { + execute_command = "echo '${var.ssh_password}' | {{ .Vars }} sudo -E -S bash '{{ .Path }}'" + scripts = ["scripts/disable-systemd-services-x86.sh", + "scripts/disable-network.sh" + ] + expect_disconnect = true } - provisioner "file" { source = "/home/gem5/vmlinux-x86-ubuntu" diff --git a/src/ubuntu-generic-diskimages/scripts/disable-network.sh b/src/ubuntu-generic-diskimages/scripts/disable-network.sh new file mode 100755 index 000000000..a37382379 --- /dev/null +++ b/src/ubuntu-generic-diskimages/scripts/disable-network.sh @@ -0,0 +1,12 @@ +# Disable network by default +echo "Disabling network by default" +echo "See README.md for instructions on how to enable network" +if [ -f /etc/netplan/50-cloud-init.yaml ]; then + mv /etc/netplan/50-cloud-init.yaml /etc/netplan/50-cloud-init.yaml.bak +elif [ -f /etc/netplan/00-installer-config.yaml ]; then + mv /etc/netplan/00-installer-config.yaml /etc/netplan/00-installer-config.yaml.bak + netplan apply +fi +# Disable systemd service that waits for network to be online +systemctl disable systemd-networkd-wait-online.service +systemctl mask systemd-networkd-wait-online.service \ No newline at end of file diff --git a/src/ubuntu-generic-diskimages/scripts/disable-systemd-services-x86.sh b/src/ubuntu-generic-diskimages/scripts/disable-systemd-services-x86.sh new file mode 100755 index 000000000..2c7d1077a --- /dev/null +++ b/src/ubuntu-generic-diskimages/scripts/disable-systemd-services-x86.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +# Copyright (c) 2024 The Regents of the University of California. +# SPDX-License-Identifier: BSD 3-Clause + +echo "Disabling systemd services for x86 architecture..." + +# Disable multipathd service +systemctl disable multipathd.service + +# Disable thermald service +systemctl disable thermald.service + +# Disable snapd services and socket +systemctl disable snapd.service snapd.socket + +# Disable unnecessary timers +systemctl disable apt-daily.timer apt-daily-upgrade.timer fstrim.timer + +# Disable accounts-daemon +systemctl disable accounts-daemon.service + +# Disable LVM monitoring service +systemctl disable lvm2-monitor.service + +# Switch default target to multi-user (no GUI) +systemctl set-default multi-user.target + +# Optionally disable AppArmor if not required +systemctl disable apparmor.service snapd.apparmor.service + +echo "completed disabling systemd services for x86." \ No newline at end of file diff --git a/src/ubuntu-generic-diskimages/scripts/extract-x86-kernel.sh b/src/ubuntu-generic-diskimages/scripts/extract-x86-kernel.sh new file mode 100755 index 000000000..64007594f --- /dev/null +++ b/src/ubuntu-generic-diskimages/scripts/extract-x86-kernel.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# Copyright (c) 2025 The Regents of the University of California. +# SPDX-License-Identifier: BSD 3-Clause + +# Make sure the headers are installed to extract the kernel that DKMS +# packages will be built against. +sudo apt -y install "linux-headers-$(uname -r)" "linux-modules-extra-$(uname -r)" + +echo "Extracting linux kernel $(uname -r) to /home/gem5/vmlinux-x86-ubuntu" +sudo bash -c "/usr/src/linux-headers-$(uname -r)/scripts/extract-vmlinux /boot/vmlinuz-$(uname -r) > /home/gem5/vmlinux-x86-ubuntu" \ No newline at end of file diff --git a/src/ubuntu-generic-diskimages/scripts/install-common-packages.sh b/src/ubuntu-generic-diskimages/scripts/install-common-packages.sh new file mode 100755 index 000000000..3956e5ace --- /dev/null +++ b/src/ubuntu-generic-diskimages/scripts/install-common-packages.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +# Copyright (c) 2025 The Regents of the University of California. +# SPDX-License-Identifier: BSD 3-Clause + +echo "Installing common packages." + + +echo "Installing serial service override for autologin after systemd." +mkdir /etc/systemd/system/serial-getty@.service.d/ +mv serial-getty@.service-override.conf /etc/systemd/system/serial-getty@.service.d/override.conf + +# Installing the packages in this script instead of the user-data +# file dueing ubuntu autoinstall. The reason is that sometimes +# the package install failes. This method is more reliable. + +echo "Installing packages required for gem5-bridge (m5) and libm5." +apt-get update +apt-get install -y scons +apt-get install -y git +apt-get install -y vim +apt-get install -y build-essential + +# Add after_boot.sh to bashrc in the gem5 user account +# This will run the script after the user automatically logs in +echo "Adding after_boot.sh to the gem5 user's .bashrc." +echo -e "\nif [ -z \"\$AFTER_BOOT_EXECUTED\" ]; then\n export AFTER_BOOT_EXECUTED=1\n /home/gem5/after_boot.sh\nfi\n" >> /home/gem5/.bashrc + +# Remove the motd +rm /etc/update-motd.d/* + +echo "Installation of common packages done." \ No newline at end of file diff --git a/src/ubuntu-generic-diskimages/scripts/install-gem5-bridge.sh b/src/ubuntu-generic-diskimages/scripts/install-gem5-bridge.sh new file mode 100755 index 000000000..eb0a2688e --- /dev/null +++ b/src/ubuntu-generic-diskimages/scripts/install-gem5-bridge.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +# Copyright (c) 2025 The Regents of the University of California. +# SPDX-License-Identifier: BSD 3-Clause + +# Build and install the gem5-bridge (m5) binary, library, and headers +echo "Building and installing gem5-bridge (m5) and libm5." + +# Ensure the ISA environment variable is set +if [ -z "$ISA" ]; then + echo "Error: ISA environment variable is not set." + exit 1 +fi + +# Just get the files we need +git clone https://github.com/gem5/gem5.git --depth=1 --filter=blob:none --no-checkout --sparse --single-branch --branch=release-staging-v24-1-1-0 +pushd gem5 +# Checkout just the files we need +git sparse-checkout add util/m5 +git sparse-checkout add util/gem5_bridge +git sparse-checkout add include +git checkout +# Install the headers globally so that other benchmarks can use them +cp -r include/gem5 /usr/local/include/ + +# Build the library and binary +pushd util/m5 +scons build/${ISA}/out/m5 +cp build/${ISA}/out/m5 /usr/local/bin/ +cp build/${ISA}/out/libm5.a /usr/local/lib/ +popd # util/m5 + +if [ "${ISA}" = "x86" ]; then + # We need to build the kernel module for x86 + # but not for ARM as we are copying the pre-built + # kernel module for ARM from host to the disk images + pushd util/gem5_bridge + make build install + depmod --quick + popd +fi + +popd # gem5 + +# rename the m5 binary to gem5-bridge +mv /usr/local/bin/m5 /usr/local/bin/gem5-bridge +# Set the setuid bit on the m5 binary +chmod 4755 /usr/local/bin/gem5-bridge +chmod u+s /usr/local/bin/gem5-bridge + +#create a symbolic link to the gem5 binary for backward compatibility +ln -s /usr/local/bin/gem5-bridge /usr/local/bin/m5 + +# delete the git repo for gem5 +rm -rf gem5 +echo "Done building and installing gem5-bridge (m5) and libm5." \ No newline at end of file diff --git a/src/ubuntu-generic-diskimages/scripts/install-user-benchmarks.sh b/src/ubuntu-generic-diskimages/scripts/install-user-benchmarks.sh new file mode 100755 index 000000000..2e260d62c --- /dev/null +++ b/src/ubuntu-generic-diskimages/scripts/install-user-benchmarks.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# Copyright (c) 2025 The Regents of the University of California. +# SPDX-License-Identifier: BSD 3-Clause + +echo "Installing benchmarks..." + +# You should write this script with the following assumptions: +# 1. common-packages and user-packages are installed; they are specified in +# install-common-packages.sh and install-user-packages.sh, respectively. +# 2. This script is run without sudo access. +# 3. All your files that you specify in your .pkr.hcl file are copied into +# the disk. + +echo "Done installing benchmarks." \ No newline at end of file diff --git a/src/ubuntu-generic-diskimages/scripts/install-user-packages.sh b/src/ubuntu-generic-diskimages/scripts/install-user-packages.sh new file mode 100755 index 000000000..570b0341a --- /dev/null +++ b/src/ubuntu-generic-diskimages/scripts/install-user-packages.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# Copyright (c) 2025 The Regents of the University of California. +# SPDX-License-Identifier: BSD 3-Clause + +echo "Installing user packages..." + +# Put your package installation commands here +# NOTE: Since we use packer we can not interact with the process of apt-get +# upgrade/install, I recommend that you add `Dpkg::Options::="--force-confnew"` +# to your commands here. See example below on how to update, upgrade, and +# install packages for cmake, python3-pip, gfortran, and openmpi, ... +# sudo apt-get -y update +# sudo apt-get -y -o Dpkg::Options::="--force-confnew" upgrade +# sudo apt-get -y -o Dpkg::Options::="--force-confnew" install \ +# python3-pip gfortran cmake openmpi-bin libopenmpi-dev + +echo "Done installing user packages." \ No newline at end of file diff --git a/src/ubuntu-generic-diskimages/scripts/post-installation.sh b/src/ubuntu-generic-diskimages/scripts/post-installation.sh deleted file mode 100755 index 9bb593f1a..000000000 --- a/src/ubuntu-generic-diskimages/scripts/post-installation.sh +++ /dev/null @@ -1,138 +0,0 @@ -#!/bin/bash - -# Copyright (c) 2024 The Regents of the University of California. -# SPDX-License-Identifier: BSD 3-Clause - -echo 'Post Installation Started' - -# Installing the packages in this script instead of the user-data -# file dueing ubuntu autoinstall. The reason is that sometimes -# the package install failes. This method is more reliable. -echo 'installing packages' -apt-get update -apt-get install -y scons -apt-get install -y git -apt-get install -y vim -apt-get install -y build-essential - -echo "Installing serial service for autologin after systemd" -mv /home/gem5/serial-getty@.service /lib/systemd/system/ - -# Make sure the headers are installed to extract the kernel that DKMS -# packages will be built against. -sudo apt -y install "linux-headers-$(uname -r)" "linux-modules-extra-$(uname -r)" - -echo "Extracting linux kernel $(uname -r) to /home/gem5/vmlinux-x86-ubuntu" -sudo bash -c "/usr/src/linux-headers-$(uname -r)/scripts/extract-vmlinux /boot/vmlinuz-$(uname -r) > /home/gem5/vmlinux-x86-ubuntu" - -echo "Installing the gem5 init script in /sbin" -mv /home/gem5/gem5_init.sh /sbin -mv /sbin/init /sbin/init.old -ln -s /sbin/gem5_init.sh /sbin/init - -# Add after_boot.sh to bashrc in the gem5 user account -# This will run the script after the user automatically logs in -echo -e "\nif [ -z \"\$AFTER_BOOT_EXECUTED\" ]; then\n export AFTER_BOOT_EXECUTED=1\n /home/gem5/after_boot.sh\nfi\n" >> /home/gem5/.bashrc - -# Remove the motd -rm /etc/update-motd.d/* - -# Build and install the gem5-bridge (m5) binary, library, and headers -echo "Building and installing gem5-bridge (m5) and libm5" - -# Ensure the ISA environment variable is set -if [ -z "$ISA" ]; then - echo "Error: ISA environment variable is not set." - exit 1 -fi - -# Just get the files we need -git clone https://github.com/gem5/gem5.git --depth=1 --filter=blob:none --no-checkout --sparse --single-branch --branch=release-staging-v24-1-1-0 -pushd gem5 -# Checkout just the files we need -git sparse-checkout add util/m5 -git sparse-checkout add util/gem5_bridge -git sparse-checkout add include -git checkout -# Install the headers globally so that other benchmarks can use them -cp -r include/gem5 /usr/local/include/\ - -# Build the library and binary -pushd util/m5 -scons build/${ISA}/out/m5 -cp build/${ISA}/out/m5 /usr/local/bin/ -cp build/${ISA}/out/libm5.a /usr/local/lib/ -popd # util/m5 - -if [ "${ISA}" = "x86" ]; then - # Build and insert the gem5-bridge driver - # as we are extracting the kernel from - # the disk image. - pushd util/gem5_bridge - make build install - depmod --quick - popd -fi - -popd # gem5 - -# rename the m5 binary to gem5-bridge -mv /usr/local/bin/m5 /usr/local/bin/gem5-bridge -# Set the setuid bit on the m5 binary -chmod 4755 /usr/local/bin/gem5-bridge -chmod u+s /usr/local/bin/gem5-bridge - -#create a symbolic link to the gem5 binary for backward compatibility -ln -s /usr/local/bin/gem5-bridge /usr/local/bin/m5 - -# delete the git repo for gem5 -rm -rf gem5 -echo "Done building and installing gem5-bridge (m5) and libm5" - -# You can extend this script to install your own packages here or by modifying the `x86-ubuntu.pkr.hcl` -# or `arm-ubuntu.pkr.hcl` file depending on the disk you are building. - -# Disable network by default -echo "Disabling network by default" -echo "See README.md for instructions on how to enable network" -if [ -f /etc/netplan/50-cloud-init.yaml ]; then - mv /etc/netplan/50-cloud-init.yaml /etc/netplan/50-cloud-init.yaml.bak -elif [ -f /etc/netplan/00-installer-config.yaml ]; then - mv /etc/netplan/00-installer-config.yaml /etc/netplan/00-installer-config.yaml.bak - netplan apply -fi -# Disable systemd service that waits for network to be online -systemctl disable systemd-networkd-wait-online.service -systemctl mask systemd-networkd-wait-online.service - -if [ "${ISA}" = "x86" ]; then - echo "Disabling systemd services for x86 architecture..." - - # Disable multipathd service - systemctl disable multipathd.service - - # Disable thermald service - systemctl disable thermald.service - - # Disable snapd services and socket - systemctl disable snapd.service snapd.socket - - # Disable unnecessary timers - systemctl disable apt-daily.timer apt-daily-upgrade.timer fstrim.timer - - # Disable accounts-daemon - systemctl disable accounts-daemon.service - - # Disable LVM monitoring service - systemctl disable lvm2-monitor.service - - # Switch default target to multi-user (no GUI) - systemctl set-default multi-user.target - - # Optionally disable AppArmor if not required - systemctl disable apparmor.service snapd.apparmor.service - - echo "completed disabling systemd services for x86." -fi - -echo "Post Installation Done" diff --git a/src/ubuntu-generic-diskimages/scripts/update-gem5-init.sh b/src/ubuntu-generic-diskimages/scripts/update-gem5-init.sh new file mode 100755 index 000000000..dfcf0c513 --- /dev/null +++ b/src/ubuntu-generic-diskimages/scripts/update-gem5-init.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# Copyright (c) 2025 The Regents of the University of California. +# SPDX-License-Identifier: BSD 3-Clause + +echo "Installing the gem5 init script in /sbin." + +mv /home/gem5/gem5_init.sh /sbin/ +mv /sbin/init /sbin/init.gem5.bak +ln -s /sbin/gem5_init.sh /sbin/init + +echo "Done installing the gem5 init script as the init process." \ No newline at end of file diff --git a/src/ubuntu-generic-diskimages/scripts/update-modules-arm-22.04.sh b/src/ubuntu-generic-diskimages/scripts/update-modules-arm-22.04.sh new file mode 100755 index 000000000..3d8e585e1 --- /dev/null +++ b/src/ubuntu-generic-diskimages/scripts/update-modules-arm-22.04.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# Copyright (c) 2025 The Regents of the University of California. +# SPDX-License-Identifier: BSD 3-Clause + +echo "Updating modules." + +# moving modules to the correct location +mv /home/gem5/5.15.167 /lib/modules/5.15.167 +depmod --quick -a 5.15.167 +update-initramfs -u -k 5.15.167 + +echo "Modules updated." \ No newline at end of file diff --git a/src/ubuntu-generic-diskimages/scripts/update-modules-arm-24.04.sh b/src/ubuntu-generic-diskimages/scripts/update-modules-arm-24.04.sh new file mode 100755 index 000000000..cf5f904df --- /dev/null +++ b/src/ubuntu-generic-diskimages/scripts/update-modules-arm-24.04.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# Copyright (c) 2025 The Regents of the University of California. +# SPDX-License-Identifier: BSD 3-Clause + +echo "Updating modules." + +# moving modules to the correct location +mv /home/gem5/6.8.12 /lib/modules/6.8.12 +depmod --quick -a 6.8.12 +update-initramfs -u -k 6.8.12 + +echo "Modules updated." \ No newline at end of file From c4bd6eb514ca75351d90a1986a2f8ebb4a7243bb Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Tue, 4 Feb 2025 17:09:23 -0800 Subject: [PATCH 07/18] resources: update arm packer file to run correct shell script --- src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl b/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl index 3e0ad4b3c..73260d68b 100644 --- a/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl +++ b/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl @@ -153,7 +153,7 @@ build { } provisioner "shell" { - scripts = ["files/serial-getty@.service-override.conf"] + scripts = ["scripts/install-user-benchmarks.sh"] } provisioner "shell" { From bfb74f18e6ed59de3b31579356d4d41f8a2cd079 Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Tue, 4 Feb 2025 17:21:33 -0800 Subject: [PATCH 08/18] resources: update gem5_init to insert the gem5 bridge driver --- .../files/arm/gem5_init.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/ubuntu-generic-diskimages/files/arm/gem5_init.sh b/src/ubuntu-generic-diskimages/files/arm/gem5_init.sh index 2cfc6ecee..94719272e 100755 --- a/src/ubuntu-generic-diskimages/files/arm/gem5_init.sh +++ b/src/ubuntu-generic-diskimages/files/arm/gem5_init.sh @@ -15,6 +15,22 @@ mount -t sysfs /sys /sys cmdline=$(cat /proc/cmdline) no_systemd=false +# Load gem5_bridge driver +## Default parameters (ARM64) +gem5_bridge_baseaddr=0x10010000 +gem5_bridge_rangesize=0x10000 +## Try to read overloads from kernel arguments +if [[ $cmdline =~ gem5_bridge_baseaddr=([[:alnum:]]+) ]]; then + gem5_bridge_baseaddr=${BASH_REMATCH[1]} +fi +if [[ $cmdline =~ gem5_bridge_rangesize=([[:alnum:]]+) ]]; then + gem5_bridge_rangesize=${BASH_REMATCH[1]} +fi +## Insert driver +modprobe gem5_bridge \ + gem5_bridge_baseaddr=$gem5_bridge_baseaddr \ + gem5_bridge_rangesize=$gem5_bridge_rangesize + # gem5-bridge exit signifying that kernel is booted # This will cause the simulation to exit. Note that this will # cause qemu to fail. From 17e87402fdb4c5713833edca608c516c8b6063a1 Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Tue, 4 Feb 2025 17:22:12 -0800 Subject: [PATCH 09/18] resources: Add a script to increase system entropy for arm - This change should speed up boot time that is caused in gem5 due to low system entropy --- .../packer-scripts/arm-ubuntu.pkr.hcl | 1 + .../increase-system-entropy-for-arm-disk.sh | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 src/ubuntu-generic-diskimages/scripts/increase-system-entropy-for-arm-disk.sh diff --git a/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl b/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl index 73260d68b..b2446fa0d 100644 --- a/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl +++ b/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl @@ -143,6 +143,7 @@ build { provisioner "shell" { execute_command = "echo '${var.ssh_password}' | {{ .Vars }} sudo -E -S bash '{{ .Path }}'" scripts = ["scripts/install-common-packages.sh", + "scripts/increase-system-entropy-for-arm-disk.sh", "scripts/update-modules-arm-${var.ubuntu_version}.sh", "scripts/update-gem5-init.sh", "scripts/install-gem5-bridge.sh", diff --git a/src/ubuntu-generic-diskimages/scripts/increase-system-entropy-for-arm-disk.sh b/src/ubuntu-generic-diskimages/scripts/increase-system-entropy-for-arm-disk.sh new file mode 100644 index 000000000..66586a093 --- /dev/null +++ b/src/ubuntu-generic-diskimages/scripts/increase-system-entropy-for-arm-disk.sh @@ -0,0 +1,36 @@ + +#!/bin/bash + +# Copyright (c) 2025 The Regents of the University of California. +# SPDX-License-Identifier: BSD 3-Clause + +# Increase system entropy for ARM disk images as a workaround for slow boot times +# when booting in gem5 due to lack of entropy in the system. +sudo apt-get install -y haveged + +# Update the DAEMON_ARGS environment variable in /etc/default/haveged +echo "Updating DAEMON_ARGS in /etc/default/haveged..." +if grep -q '^#DAEMON_ARGS=""' /etc/default/haveged; then + # If DAEMON_ARGS is commented out, uncomment and set it + sudo sed -i 's/#DAEMON_ARGS=""/DAEMON_ARGS="-w 1024"/' /etc/default/haveged +elif grep -q '^DAEMON_ARGS=' /etc/default/haveged; then + # If DAEMON_ARGS exists, update its value + sudo sed -i 's/^DAEMON_ARGS=.*/DAEMON_ARGS="-w 1024"/' /etc/default/haveged +else + # If DAEMON_ARGS is missing, add it + echo 'DAEMON_ARGS="-w 1024"' | sudo tee -a /etc/default/haveged > /dev/null +fi + +# Start the haveged service +echo "Starting the haveged service..." +sudo systemctl start haveged + +# Enable the haveged service to start at boot +echo "Enabling the haveged service to start at boot..." +sudo systemctl enable haveged + +# Check the status of haveged +echo "Checking the status of the haveged service..." +sudo systemctl status haveged + +echo "Haveged installation and setup complete!" From c2b0f3b82afffcf22f47b895c20455dcbd7b0b7b Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Wed, 5 Feb 2025 13:23:32 -0800 Subject: [PATCH 10/18] resources: Update documentation for building disk images --- src/ubuntu-generic-diskimages/BUILDING.md | 214 ++++++++++++---------- 1 file changed, 113 insertions(+), 101 deletions(-) diff --git a/src/ubuntu-generic-diskimages/BUILDING.md b/src/ubuntu-generic-diskimages/BUILDING.md index 48b49352d..577628533 100644 --- a/src/ubuntu-generic-diskimages/BUILDING.md +++ b/src/ubuntu-generic-diskimages/BUILDING.md @@ -4,109 +4,139 @@ authors: - Harshil Patel --- -This document provides instructions to create the "x86-ubuntu" image and "arm-ubuntu" image. -This image can be a 22.04 or 24.04 Ubuntu image. +This document provides instructions for creating the **x86-ubuntu** and **arm-ubuntu** disk images. The images can be built for **Ubuntu 22.04** or **Ubuntu 24.04**. -## Directory map +## Directory Structure -- `files`: Files that are copied to the disk image. -- `scripts`: Scripts run on the disk image after installation. -- `http`: cloud-init Ubuntu autoinstall files for different versions of Ubuntu for Arm and x86. - - `arm-22-04`: cloud-init Ubuntu autoinstall files for arm ubuntu 22.04 image. - - `arm-24-04`: cloud-init Ubuntu autoinstall files for arm ubuntu 24.04 image. - - `x86`: cloud-init Ubuntu autoinstall files for x86 ubuntu 22.04 and 24.04 images. -- `x86-disk-image-24.04`: Disk image output directory for x86 ubuntu 24.04 image. -- `x86-disk-image-22.04`: Disk image output directory for x86 ubuntu 22.04 image. -- `arm-disk-image-24.04`: Disk image output directory for arm ubuntu 24.04 image. -- `arm-disk-image-22.04`: Disk image output directory for arm ubuntu 22.04 image. +- **`files/`**: Contains files that are copied to the disk image. +- **`kernel-and-modules/`**: Contains scripts and Dockerfiles necessary for building the default kernel in Ubuntu 22.04 and 24.04 for ARM disk images. Each subdirectory corresponds to a specific Ubuntu version: + - **`arm-ubuntu-22.04/`**: Contains a Dockerfile and `copy_modules_to_host.sh` for building the default Ubuntu 22.04 kernel and modules with the `gem5-bridge` module installed. + - **`arm-ubuntu-24.04/`**: Contains a Dockerfile and `copy_modules_to_host.sh` for building the default Ubuntu 24.04 kernel and modules with the `gem5-bridge` module installed. -## Disk Image + After building the Dockerfile, you can retrieve the kernel and modules on your host using the `copy_modules_to_host.sh` script. +- **`scripts/`**: Contains scripts that run on the disk image after installation. + - **`disable-network.sh`**: Disables networking by renaming the Netplan configuration file (`.yaml` → `.yaml.bak`) and disabling network services in systemd. + - **`disable-systemd-services-x86.sh`**: Disables non-essential systemd services for x86 disk images to reduce boot time in gem5 simulations. + - **`extract-x86-kernel.sh`**: Extracts the kernel from the x86 disk image and moves it to `/home/gem5`. Packer then copies the extracted kernel from the disk image to the host. + - **`increase-system-entropy-for-arm-disk.sh`**: Uses `haveged` to increase system entropy for ARM disk images, reducing boot delays caused by low entropy. + - **`install-common-packages.sh`**: Installs necessary packages common to all disk images. + - **`install-gem5-bridge.sh`**: Clones and builds `gem5-bridge`, allowing the disk image to use `m5ops` commands. + - **`install-user-benchmarks.sh`**: User-editable script for installing custom benchmarks. + - **`install-user-packages.sh`**: User-editable script for installing additional packages beyond those in `install-common-packages.sh`. + - **`update-gem5-init.sh`**: Updates the `init` file with `gem5_init.sh` from the `files` directory. + - **`update-modules-arm-22.04.sh`**: Installs kernel modules built via the Dockerfile in `kernel-and-modules/arm-ubuntu-22.04` for the ARM 22.04 disk image. + - **`update-modules-arm-24.04.sh`**: Installs kernel modules built via the Dockerfile in `kernel-and-modules/arm-ubuntu-24.04` for the ARM 24.04 disk image. -Run `build-x86.sh` with the argument `22.04` or `24.04` to build the respective x86 disk image in the `ubuntu-generic-diskimages` directory. -Run `build-arm.sh` with the argument `22.04` or `24.04` to build the respective arm disk image in the `ubuntu-generic-diskimages` directory. -Building the arm image assume that we are on an ARM machine as we use kvm to build the image. -You can also run the packer file by adding the "use_kvm=false" in `build-arm.sh` in the `./packer build` command to build the disk image without KVM. -This will download the packer binary, initialize packer, and build the disk image. +- **`http/`**: Contains Ubuntu cloud-init autoinstall files for different architectures and versions. + - `arm-22-04/`: Autoinstall files for ARM Ubuntu 22.04. + - `arm-24-04/`: Autoinstall files for ARM Ubuntu 24.04. + - `x86/`: Autoinstall files for x86 Ubuntu 22.04 and 24.04. -## Arm image specific requirements +- **Disk Image Output Directories**: + - `x86-disk-image-22.04/`: x86 Ubuntu 22.04 disk image output. + - `x86-disk-image-24.04/`: x86 Ubuntu 24.04 disk image output. + - `arm-disk-image-22.04/`: ARM Ubuntu 22.04 disk image output. + - `arm-disk-image-24.04/`: ARM Ubuntu 24.04 disk image output. -We need a EFI file to boot the arm image. We use the file named `flash0.img` in the packer file. +## ARM Image Specific Requirements -To get the `flash0.img` run the following commands in the `files` directory +To successfully build and boot an ARM disk image, you need to prepare the **kernel modules** and an **EFI boot file**. + +### **Building and Installing Kernel Modules (ARM)** + +Since the ARM disk image requires the `gem5-bridge` module to enable running `gem5-bridge` commands without using `sudo` inside gem5 simulations, we must build the kernel modules before running the Packer script. + +#### **Steps to Build the Kernel and Modules** + +1. **Navigate to the Appropriate Directory** + Change to the directory corresponding to the Ubuntu version of the disk image you are building: + + ```sh + cd kernel-and-modules/arm-ubuntu-22.04 # For Ubuntu 22.04 + cd kernel-and-modules/arm-ubuntu-24.04 # For Ubuntu 24.04 + ``` + +2. **Run the `copy_modules_to_host.sh` Script** + This script builds the kernel and modules inside a Docker container and then copies them to the host machine: + + ```sh + ./copy_modules_to_host.sh + ``` + +3. **Verify the Output Directory** + After running the script, a directory named **`my-arm--kernel`** will be created in the `kernel-and-modules` directory. This directory contains: + + - `vmlinux`: The built kernel (**used in gem5 simulations but not copied to the disk**). + - A subdirectory containing all kernel modules, including `gem5-bridge`. + +### **Generating the EFI Boot File** + +The ARM disk image requires an **EFI file** to boot in qemu. This is provided as `flash0.img` in the Packer configuration. + +To generate `flash0.img`, run the following commands in the `files/` directory: ```bash dd if=/dev/zero of=flash0.img bs=1M count=64 dd if=/usr/share/qemu-efi-aarch64/QEMU_EFI.fd of=flash0.img conv=notrunc ``` -**Note**: The `build-arm.sh` will make this file for you. +**Note:** Running `build-arm.sh` automatically generates this file. -Note: Building the image can take a while to run. -You will see `qemu.initialize: Waiting for SSH to become available...` while the installation is running. -You can watch the installation with a VNC viewer. -See [Troubleshooting](#troubleshooting) for more information. +## Building the Disk Image -## Kernel +- **For x86**: + Run `build-x86.sh` with either `22.04` or `24.04` as an argument to build the respective x86 disk image in the `ubuntu-generic-diskimages` directory. -For the x86 disk images a kernel is also extracted from the disk image during the post-installation process. -The extracted kernel does not have a version in its name, but the kernel version is printed before the extraction in `post-installation.sh` script. This extracted kernel can be used as a resource for gem5 simulations and is not limited to just be used with this disk image. -The extracted kernel does not have a version its name, but the kernel version is printed as before the extraction in `post-installation.sh` script. This extracted kernel can be used as a resource for gem5 simulations and is not limited to just be used with this disk image. +- **For ARM**: + Run `build-arm.sh` with `22.04` or `24.04` to build the respective ARM disk image in `ubuntu-generic-diskimages`. -The kernel is extracted using packer's file provisioner with `direction=download` which would copy a file from the image to the host machine. The path specifying in the provisioner copies the file `/home/gem5/vmlinux-x86-ubuntu` to the output directory `disk-image`. + **ARM Build Assumption**: + The build assumes execution on an **ARM machine**, as it uses KVM for virtualization. If running on a non-ARM host, update `build-arm.sh` by setting `"use_kvm=false"` in the `./packer build` command. -## Changes from the base Ubuntu image + This script downloads the Packer binary, initializes Packer, and builds the disk image. -- The default user is `gem5` with password `12345`. -- The `m5` utility is renamed to `gem5-bridge`. - - `gem5-bridge` utility is installed in `/usr/local/bin/gem5-bridge`. - - `gem5-bridge` has a symlink to `m5` for backwards compatibility. - - `libm5` is installed in `/usr/local/lib/` and the headers for `libm5` are installed in `/usr/local/include/m5`. -- The `.bashrc` file checks to see if there is anything in the `gem5-bridge readfile` command and executes the script if there is. -- The init process is modified to provide better annotations and more exit event. For more details see the [Init Process and Exit events](README.md#init-process-and-exit-events). - - The `gem5-bridge exit` command is run after the linux kernel initialization by default. - - If the `no_systemd` boot option is passed, systemd is not run and the user is dropped to a terminal. - - If the `interactive` boot option is passed, the `gem5-bridge exit` command is not run after the linux kernel initialization. -- Networking is disabled by moving the `/etc/netplan/00-installer-config.yaml` or `/etc/netplan/50-cloud-init.yaml` file to `/etc/netplan/00-installer-config.yaml.bak` or `/etc/netplan/50-cloud-init.yaml.bak` respectively. The `systemd-networkd-wait-online.service` is also disabled. -The x86 22.04 image should have `00-installer-config.yaml` while all the other disk images should have `50-cloud-init.yaml`. - - If you want to enable networking, you need to modify the disk image and move the file `/etc/netplan/00-installer-config.yaml.bak` or `/etc/netplan/50-cloud-init.yaml.bak` to `/etc/netplan/00-installer-config.yaml` or `/etc/netplan/50-cloud-init.yaml` depending on which config file the disk image contains. - To re-enable `systemd-networkd-wait-online.service`, first, unmask the service with `sudo systemctl unmask systemd-networkd-wait-online.service` and then enable the service to start with `sudo systemctl enable systemd-networkd-wait-online.service`. - If you require the service to start immediately without waiting for the next boot then also run the following: - `sudo systemctl start systemd-networkd-wait-online.service`. +## Kernel Extraction (x86 Only) -### Customization of the boot Processes +For **x86 disk images**, the kernel is extracted as part of the post-installation process. -- **`gem5_init.sh` replaces /sbin/init**: This script is what executes as the Linux init process (pid=0) immediately after Linux boot. This script adds an `gem5-bridge exit` when the file is executed. It also checks the `no_systemd` kernel arg to redirect to the user or boot with systemd. +- The extracted kernel is stored in `/home/gem5/vmlinux-x86-ubuntu` within the disk image. +- Packer's **file provisioner** (`direction=download`) copies this file to the host machine in the `x86-disk-image-24.04/` or `x86-disk-image-22.04/` output directory depending upon the disk image being built. +- The kernel version is printed before extraction in `post-installation.sh`. -### Details of the After-Boot Script +This kernel can be used as a resource for **gem5 simulations** and is not restricted to this disk image. -- **Persistent Execution of `after-boot.sh`**: The `after-boot.sh` script executes at first login. -To avoid its infinite execution, we incorporated a conditional check in `post-installation.sh` similar to the following: +## Changes from the Base Ubuntu Image -```sh -echo -e "\nif [ -z \"\$AFTER_BOOT_EXECUTED\" ]; then\n export AFTER_BOOT_EXECUTED=1\n /home/gem5/after_boot.sh\nfi\n" >> /home/gem5/.bashrc -``` +- **Default User**: + - Username: `gem5` + - Password: `12345` -This ensures `after-boot.sh` runs only once per session by setting an environment variable. +- **Networking**: + - **Disabled by default** by renaming `/etc/netplan/00-installer-config.yaml` or `/etc/netplan/50-cloud-init.yaml` to `.bak`. + - **To re-enable networking**: -### Adjusting File Permissions + ```sh + sudo mv /etc/netplan/00-installer-config.yaml.bak /etc/netplan/00-installer-config.yaml + sudo systemctl unmask systemd-networkd-wait-online.service + sudo systemctl enable systemd-networkd-wait-online.service + sudo systemctl start systemd-networkd-wait-online.service # If enabling immediately + ``` -- **Setting Permissions for `gem5-bridge`**: Since the default user is not root, `gem5-bridge` requires root permissions. Apply setuid to grant these permissions: +- **gem5-Bridge (`m5`)**: + - Installed at `/usr/local/bin/gem5-bridge` with a symlink to `m5` for compatibility. + - `libm5` is installed in `/usr/local/lib/`, and headers are placed in `/usr/local/include/m5`. - ```sh - chmod u+s /path/to/gem5-bridge - ``` - -## Extending the disk image with custom files and scripts +## Extending the Disk Image -- You can add more packages to the disk image by updating the `post-installation.sh` script. -- To add files from host to the disk image you can add a file provisioner with source as path in host and destination as path in the image. +- Add more packages by updating `post-installation.sh`. +- Transfer additional files using Packer’s file provisioner: -```hcl -provisioner "file" { - destination = "/home/gem5/" - source = "path/to/files" + ```hcl + provisioner "file" { + destination = "/home/gem5/" + source = "path/to/files" } -``` + ``` If you need to increase the size of the image when adding more libraries and files to the image update the size of the partition in the respective `http/*/user-data` file. Also, update the `disk_size` parameter in `post-installation.sh` to be at least one mega byte more than the size you defined in the `user-data` file. @@ -114,38 +144,20 @@ If you need to increase the size of the image when adding more libraries and fil To take a pre-built image and add new files or packages, take a look at the following [documentation](https://www.gem5.org/documentation/gem5-stdlib/extending-disk-images). -## Creating a Disk Image from Scratch - -### Automated Ubuntu Installation - -- **Ubuntu Autoinstall**: We leveraged Ubuntu's autoinstall feature for an automated setup process. -- **Acquire `user-data` File**: To get the `user-data` file, install your desired Ubuntu version on a machine or VM. Post-installation, retrieve the `autoinstall-user-data` from `/var/log/installer/autoinstall-user-data` after the system's first reboot. -The `user-data` file in this repo, is made by selecting all default options except a minimal server installation. - -### Configuration and Directory Structure - -- **Determine QEMU Arguments**: Identify the QEMU arguments required for booting the system. These vary by ISA and mirror the arguments used for booting a disk image in QEMU. -- **Directory Organization**: Arrange your source directory to include the `user-data` file and any additional content. Utilize the `provisioner` section for transferring extra files into the disk image, ensuring all necessary resources are embedded within your custom disk image. - ## Troubleshooting -To see what `packer` is doing, you can use the environment variable `PACKER_LOG=INFO` when running `./build.sh`. - -Packer seems to have a bug that aborts the VM build after 2-5 minutes regardless of the ssh_timeout setting. -As a workaround, set ssh_handshake_attempts to a high value. -Thus, I have `ssh_handshake_attempts = 1000`. -From +- **Enable Packer Logs**: -To see what is happening while packer is running, you can connect with a vnc viewer. -The port for the vnc viewer is shown in the terminal while packer is running. + ```sh + PACKER_LOG=INFO ./build.sh + ``` -You can mount the disk image to see what is inside. -Use the following command to mount the disk image: -(note `norecovery` is needed if you get the error "cannot mount ... read-only") +- **Common Packer Bug**: + - VM build may abort after **2-5 minutes**, even with `ssh_timeout` set. + - Workaround: **Increase `ssh_handshake_attempts`** (e.g., `1000`). -```sh -mkdir x86-ubuntu/mount -sudo mount -o loop,offset=2097152,norecovery x86-ubuntu/x86-ubuntu-image/x86-ubuntu x86-ubuntu/mount -``` +- **Monitor Installation**: + - Use a **VNC viewer** to watch installation. The port is displayed in the terminal. -Useful documentation: +For further details, refer to: +[Ubuntu Autoinstall Documentation](https://ubuntu.com/server/docs/install/autoinstall). From ec7c7b6aa99b82e647c66cf988e770cb16d7dffc Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Wed, 5 Feb 2025 13:33:41 -0800 Subject: [PATCH 11/18] resources: Update github clone link to clone from staging branch --- .../kernel-and-modules/arm-ubuntu-22.04/Dockerfile | 2 +- .../kernel-and-modules/arm-ubuntu-24.04/Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-22.04/Dockerfile b/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-22.04/Dockerfile index 76ef58dd2..19a19b085 100644 --- a/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-22.04/Dockerfile +++ b/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-22.04/Dockerfile @@ -27,7 +27,7 @@ RUN cd /workspace/linux-5.15.0 && \ make -j 32 && \ make INSTALL_MOD_PATH=/workspace/output modules_install -RUN git clone https://github.com/nkrim/gem5.git --depth=1 --filter=blob:none --no-checkout --sparse --single-branch --branch=gem5-bridge && \ +RUN git clone https://github.com/gem5/gem5.git --depth=1 --filter=blob:none --no-checkout --sparse --single-branch --branch=release-staging-v24-1-1-0 && \ cd gem5 && \ git sparse-checkout add util/m5 && \ git sparse-checkout add util/gem5_bridge && \ diff --git a/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-24.04/Dockerfile b/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-24.04/Dockerfile index f230b2d95..5e02c4d9e 100644 --- a/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-24.04/Dockerfile +++ b/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-24.04/Dockerfile @@ -25,7 +25,7 @@ RUN cd /workspace/linux-6.8.0 && \ make -j 32 && \ make INSTALL_MOD_PATH=/workspace/output modules_install -RUN git clone https://github.com/nkrim/gem5.git --depth=1 --filter=blob:none --no-checkout --sparse --single-branch --branch=gem5-bridge && \ +RUN git clone https://github.com/gem5/gem5.git --depth=1 --filter=blob:none --no-checkout --sparse --single-branch --branch=release-staging-v24-1-1-0 && \ cd gem5 && \ git sparse-checkout add util/m5 && \ git sparse-checkout add util/gem5_bridge && \ From 6edc682e3bc7713b28f62857e34175e180d8295e Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Wed, 5 Feb 2025 13:39:02 -0800 Subject: [PATCH 12/18] resources: Update the increase-system-entropy script - Update comments explaining the reason for increasing entropy --- .../scripts/increase-system-entropy-for-arm-disk.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ubuntu-generic-diskimages/scripts/increase-system-entropy-for-arm-disk.sh b/src/ubuntu-generic-diskimages/scripts/increase-system-entropy-for-arm-disk.sh index 66586a093..245f54c2d 100644 --- a/src/ubuntu-generic-diskimages/scripts/increase-system-entropy-for-arm-disk.sh +++ b/src/ubuntu-generic-diskimages/scripts/increase-system-entropy-for-arm-disk.sh @@ -4,8 +4,9 @@ # Copyright (c) 2025 The Regents of the University of California. # SPDX-License-Identifier: BSD 3-Clause -# Increase system entropy for ARM disk images as a workaround for slow boot times -# when booting in gem5 due to lack of entropy in the system. +# Increase system entropy for ARM disk images to reduce boot time in gem5. +# Some systemd services wait for sufficient entropy before proceeding, causing delays. +# By increasing entropy early, these services start without unnecessary waiting. sudo apt-get install -y haveged # Update the DAEMON_ARGS environment variable in /etc/default/haveged From 695c7ddbb635ab05a2a017907999833a9c51dac6 Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Wed, 5 Feb 2025 13:50:30 -0800 Subject: [PATCH 13/18] resources: Update make command in dockerfile to use nproc --- .../kernel-and-modules/arm-ubuntu-22.04/Dockerfile | 2 +- .../kernel-and-modules/arm-ubuntu-24.04/Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-22.04/Dockerfile b/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-22.04/Dockerfile index 19a19b085..6abd0151a 100644 --- a/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-22.04/Dockerfile +++ b/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-22.04/Dockerfile @@ -24,7 +24,7 @@ RUN cd /workspace && apt source linux-image-unsigned-5.15.0-25-generic RUN cd /workspace/linux-5.15.0 && \ make defconfig && \ - make -j 32 && \ + make -j $(nproc) && \ make INSTALL_MOD_PATH=/workspace/output modules_install RUN git clone https://github.com/gem5/gem5.git --depth=1 --filter=blob:none --no-checkout --sparse --single-branch --branch=release-staging-v24-1-1-0 && \ diff --git a/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-24.04/Dockerfile b/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-24.04/Dockerfile index 5e02c4d9e..737adaf1a 100644 --- a/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-24.04/Dockerfile +++ b/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-24.04/Dockerfile @@ -22,7 +22,7 @@ RUN cd /workspace && apt source linux-image-unsigned-6.8.0-47-generic RUN cd /workspace/linux-6.8.0 && \ make defconfig && \ - make -j 32 && \ + make -j $(nproc) && \ make INSTALL_MOD_PATH=/workspace/output modules_install RUN git clone https://github.com/gem5/gem5.git --depth=1 --filter=blob:none --no-checkout --sparse --single-branch --branch=release-staging-v24-1-1-0 && \ From 05d7bced7ca35220187c07740d7652fb53f20057 Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Thu, 6 Feb 2025 10:36:25 -0800 Subject: [PATCH 14/18] resources: update NPB disk image to use hypercall instead of workbegin and workend --- src/npb-24.04-imgs/arm-npb.pkr.hcl | 4 ++-- src/npb-24.04-imgs/npb-with-roi/NPB/NPB3.4-OMP/common/hooks.c | 4 ++-- src/npb-24.04-imgs/x86-npb.pkr.hcl | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/npb-24.04-imgs/arm-npb.pkr.hcl b/src/npb-24.04-imgs/arm-npb.pkr.hcl index e26db4e7d..72f223917 100644 --- a/src/npb-24.04-imgs/arm-npb.pkr.hcl +++ b/src/npb-24.04-imgs/arm-npb.pkr.hcl @@ -35,8 +35,8 @@ source "qemu" "initialize" { format = "raw" headless = "true" disk_image = "true" - iso_checksum = "sha256:eb94422a3908c6c5183c03666b278b6e8bcfbde04da3d7c3bb5374bc82e0ef48" - iso_urls = ["./arm-ubuntu-24.04-20240823"] + iso_checksum = "sha256:50cd77b981f149ef291a0ad36ad7f7f03fb9f31236c7969fe0b91151fdda768f" + iso_urls = ["../ubuntu-generic-diskimages/arm-disk-image-24-04/arm-ubuntu"] memory = "8192" output_directory = "disk-image-arm-npb" qemu_binary = "/usr/bin/qemu-system-aarch64" diff --git a/src/npb-24.04-imgs/npb-with-roi/NPB/NPB3.4-OMP/common/hooks.c b/src/npb-24.04-imgs/npb-with-roi/NPB/NPB3.4-OMP/common/hooks.c index 1322e12e9..c070fd21d 100644 --- a/src/npb-24.04-imgs/npb-with-roi/NPB/NPB3.4-OMP/common/hooks.c +++ b/src/npb-24.04-imgs/npb-with-roi/NPB/NPB3.4-OMP/common/hooks.c @@ -51,11 +51,11 @@ void m5_work_begin_interface_() { printf(" -------------------- ROI BEGIN -------------------- \n"); - m5_work_begin_addr(0,0); + m5_hypercall_addr(4); } void m5_work_end_interface_() { - m5_work_end_addr(0,0); + m5_hypercall_addr(5); printf(" -------------------- ROI END -------------------- \n"); } diff --git a/src/npb-24.04-imgs/x86-npb.pkr.hcl b/src/npb-24.04-imgs/x86-npb.pkr.hcl index e14670671..588a0e657 100644 --- a/src/npb-24.04-imgs/x86-npb.pkr.hcl +++ b/src/npb-24.04-imgs/x86-npb.pkr.hcl @@ -36,8 +36,8 @@ source "qemu" "initialize" { format = "raw" headless = "true" disk_image = "true" - iso_checksum = "sha256:6cedf26ebf281b823b24722341d3a2ab1f1ba26b10b536916d3f23cf92a8f4b5" - iso_urls = ["./x86-ubuntu-24-04-v2"] + iso_checksum = "sha256:b1f8421956d374207ebca70f176374ff9e1e8c46f74bfb2c47a6583e4eae758e" + iso_urls = ["../ubuntu-generic-diskimages/x86-disk-image-24-04/x86-ubuntu"] memory = "8192" output_directory = "disk-image-x86-npb" qemu_binary = "/usr/bin/qemu-system-x86_64" From f26c38ba1a22058626649ad466c86d60fb538fb9 Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Thu, 6 Feb 2025 11:59:20 -0800 Subject: [PATCH 15/18] resources: Update Dockerfile for building kernel and modules for 22.04 disk image --- .../kernel-and-modules/arm-ubuntu-22.04/Dockerfile | 5 ++++- .../arm-ubuntu-22.04/copy_modules_to_host.sh | 4 ++-- .../packer-scripts/arm-ubuntu.pkr.hcl | 2 +- .../scripts/update-modules-arm-22.04.sh | 6 +++--- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-22.04/Dockerfile b/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-22.04/Dockerfile index 6abd0151a..88d59da74 100644 --- a/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-22.04/Dockerfile +++ b/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-22.04/Dockerfile @@ -23,6 +23,9 @@ RUN mkdir /workspace RUN cd /workspace && apt source linux-image-unsigned-5.15.0-25-generic RUN cd /workspace/linux-5.15.0 && \ + cd scripts && \ + chmod +x pahole-version.sh && \ + cd .. && \ make defconfig && \ make -j $(nproc) && \ make INSTALL_MOD_PATH=/workspace/output modules_install @@ -37,7 +40,7 @@ RUN git clone https://github.com/gem5/gem5.git --depth=1 --filter=blob:none --no RUN cd gem5/util/gem5_bridge && \ make KMAKEDIR=/workspace/linux-5.15.0 INSTALL_MOD_PATH=/workspace/output build install -RUN cd /workspace/output/lib/modules/5.15.* && \ +RUN cd /workspace/output/lib/modules/5.15.168 && \ rm -rf build source FROM scratch AS export-stage diff --git a/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-22.04/copy_modules_to_host.sh b/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-22.04/copy_modules_to_host.sh index fb61543b3..b8e817a46 100755 --- a/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-22.04/copy_modules_to_host.sh +++ b/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-22.04/copy_modules_to_host.sh @@ -3,8 +3,8 @@ # Copyright (c) 2025 The Regents of the University of California. # SPDX-License-Identifier: BSD 3-Clause -DOCKERFILE="./22.04-dockerfile/Dockerfile" -OUTPUT="my-arm-5.15.167-kernel" +DOCKERFILE="Dockerfile" +OUTPUT="my-arm-5.15.168-kernel" # Build the Docker image DOCKER_BUILDKIT=1 docker build --no-cache \ diff --git a/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl b/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl index b2446fa0d..91ac95673 100644 --- a/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl +++ b/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl @@ -38,7 +38,7 @@ locals { iso_checksum = "sha256:c209ab013280d3cd26a344def60b7b19fbb427de904ea285057d94ca6ac82dd5" output_dir = "arm-disk-image-22-04" http_directory = "http/arm-22-04" - modules_dir = "kernel-and-modules/arm-ubuntu-22.04/my-arm-5.15.167-kernel/5.15.167" + modules_dir = "kernel-and-modules/arm-ubuntu-22.04/my-arm-5.15.168-kernel/5.15.168" } "24.04" = { iso_url = "https://cdimage.ubuntu.com/releases/24.04/release/ubuntu-24.04-live-server-arm64.iso" diff --git a/src/ubuntu-generic-diskimages/scripts/update-modules-arm-22.04.sh b/src/ubuntu-generic-diskimages/scripts/update-modules-arm-22.04.sh index 3d8e585e1..68b1d6a6f 100755 --- a/src/ubuntu-generic-diskimages/scripts/update-modules-arm-22.04.sh +++ b/src/ubuntu-generic-diskimages/scripts/update-modules-arm-22.04.sh @@ -6,8 +6,8 @@ echo "Updating modules." # moving modules to the correct location -mv /home/gem5/5.15.167 /lib/modules/5.15.167 -depmod --quick -a 5.15.167 -update-initramfs -u -k 5.15.167 +mv /home/gem5/5.15.168 /lib/modules/5.15.168 +depmod --quick -a 5.15.168 +update-initramfs -u -k 5.15.168 echo "Modules updated." \ No newline at end of file From 819ed59284b584531136313d7e7af851ac89f9d5 Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Tue, 18 Feb 2025 09:49:10 -0800 Subject: [PATCH 16/18] resources: Update documentation for building base disk images --- src/ubuntu-generic-diskimages/BUILDING.md | 48 ++++++++++++++++------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/src/ubuntu-generic-diskimages/BUILDING.md b/src/ubuntu-generic-diskimages/BUILDING.md index 577628533..dbe0887a2 100644 --- a/src/ubuntu-generic-diskimages/BUILDING.md +++ b/src/ubuntu-generic-diskimages/BUILDING.md @@ -15,15 +15,15 @@ This document provides instructions for creating the **x86-ubuntu** and **arm-ub After building the Dockerfile, you can retrieve the kernel and modules on your host using the `copy_modules_to_host.sh` script. - **`scripts/`**: Contains scripts that run on the disk image after installation. - - **`disable-network.sh`**: Disables networking by renaming the Netplan configuration file (`.yaml` → `.yaml.bak`) and disabling network services in systemd. + - **`disable-network.sh`**: Disables networking by renaming the Netplan configuration file (`.yaml` → `.yaml.bak`) and disabling network services in systemd. Disabling network decreases boot time by removing the 2 minute wait for network service to get online in systemd. - **`disable-systemd-services-x86.sh`**: Disables non-essential systemd services for x86 disk images to reduce boot time in gem5 simulations. - **`extract-x86-kernel.sh`**: Extracts the kernel from the x86 disk image and moves it to `/home/gem5`. Packer then copies the extracted kernel from the disk image to the host. - **`increase-system-entropy-for-arm-disk.sh`**: Uses `haveged` to increase system entropy for ARM disk images, reducing boot delays caused by low entropy. - **`install-common-packages.sh`**: Installs necessary packages common to all disk images. - - **`install-gem5-bridge.sh`**: Clones and builds `gem5-bridge`, allowing the disk image to use `m5ops` commands. + - **`install-gem5-bridge.sh`**: Clones and builds `gem5-bridge`, allowing the disk image to use `m5ops` commands. For more information about using `m5ops` you can take a look at . - **`install-user-benchmarks.sh`**: User-editable script for installing custom benchmarks. - **`install-user-packages.sh`**: User-editable script for installing additional packages beyond those in `install-common-packages.sh`. - - **`update-gem5-init.sh`**: Updates the `init` file with `gem5_init.sh` from the `files` directory. + - **`update-gem5-init.sh`**: Updates the `init` file with `gem5_init.sh` from the `files` directory. The `gem5_init.sh` script updates the `init` script that is run when ubuntu boots to include the `no_systemd` kernel arg, initialize the `gem5-bridge` driver and call an exit event indicating that the kernel has booted. - **`update-modules-arm-22.04.sh`**: Installs kernel modules built via the Dockerfile in `kernel-and-modules/arm-ubuntu-22.04` for the ARM 22.04 disk image. - **`update-modules-arm-24.04.sh`**: Installs kernel modules built via the Dockerfile in `kernel-and-modules/arm-ubuntu-24.04` for the ARM 24.04 disk image. @@ -66,22 +66,20 @@ Since the ARM disk image requires the `gem5-bridge` module to enable running `ge 3. **Verify the Output Directory** After running the script, a directory named **`my-arm--kernel`** will be created in the `kernel-and-modules` directory. This directory contains: - - `vmlinux`: The built kernel (**used in gem5 simulations but not copied to the disk**). + - `vmlinux`: The built kernel (**used in gem5 simulations but not copied onto the built disk image**). - A subdirectory containing all kernel modules, including `gem5-bridge`. ### **Generating the EFI Boot File** -The ARM disk image requires an **EFI file** to boot in qemu. This is provided as `flash0.img` in the Packer configuration. +The ARM disk image requires an **EFI file** to boot in qemu. Running `build-arm.sh` automatically generates this file.This is provided as `flash0.img` in the Packer configuration. -To generate `flash0.img`, run the following commands in the `files/` directory: +To generate `flash0.img` manually, run the following commands in the `files/` directory: ```bash dd if=/dev/zero of=flash0.img bs=1M count=64 dd if=/usr/share/qemu-efi-aarch64/QEMU_EFI.fd of=flash0.img conv=notrunc ``` -**Note:** Running `build-arm.sh` automatically generates this file. - ## Building the Disk Image - **For x86**: @@ -91,9 +89,23 @@ dd if=/usr/share/qemu-efi-aarch64/QEMU_EFI.fd of=flash0.img conv=notrunc Run `build-arm.sh` with `22.04` or `24.04` to build the respective ARM disk image in `ubuntu-generic-diskimages`. **ARM Build Assumption**: - The build assumes execution on an **ARM machine**, as it uses KVM for virtualization. If running on a non-ARM host, update `build-arm.sh` by setting `"use_kvm=false"` in the `./packer build` command. + The build assumes execution on an **ARM machine**, as it uses KVM for virtualization. If running on a non-ARM host, update `build-arm.sh` by setting `"use_kvm=false"` in the `./packer build` command: + + ```bash + ./packer build -var "use_kvm=false" -var "ubuntu_version=${ubuntu_version}" ./packer-scripts/arm-ubuntu.pkr.hcl + ``` - This script downloads the Packer binary, initializes Packer, and builds the disk image. + You would also need to update the isa of the packer binary being downloaded in the `build-arm.sh` file. To download the `amd64` packer binary you can update the section that downloads the packer binary in `build-arm.sh` file to the following: + + ```bash + if [ ! -f ./packer ]; then + wget https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_amd64.zip; + unzip packer_${PACKER_VERSION}_linux_amd64.zip; + rm packer_${PACKER_VERSION}_linux_amd64.zip; + fi + ``` + + The `build-arm.sh` script downloads the Packer binary, initializes Packer, and builds the disk image. ## Kernel Extraction (x86 Only) @@ -128,7 +140,7 @@ This kernel can be used as a resource for **gem5 simulations** and is not restri ## Extending the Disk Image -- Add more packages by updating `post-installation.sh`. +- Add more packages by modifying `scripts/install-user-packages.sh`. Install benchmarks onto the base disk image by modifying `scripts/install-user-benchmarks.sh`. - Transfer additional files using Packer’s file provisioner: ```hcl @@ -137,16 +149,16 @@ This kernel can be used as a resource for **gem5 simulations** and is not restri source = "path/to/files" } ``` + +If you need to increase the size of the image when adding more libraries and files to the image update the size of the partition in the respective `http/*/user-data` file. Also, update the `disk_size` parameter in the packer file to be at least one mega byte more than the size you defined in the `user-data` file. -If you need to increase the size of the image when adding more libraries and files to the image update the size of the partition in the respective `http/*/user-data` file. Also, update the `disk_size` parameter in `post-installation.sh` to be at least one mega byte more than the size you defined in the `user-data` file. - -**NOTE:** You can extend this disk image by modifying the `post-installation.sh` script, but it requires building the image from scratch. +**NOTE:** You can extend this disk image by modifying the `install-user-benchmarks` and `install-user-packages.sh` script, but it requires building the image from scratch. To take a pre-built image and add new files or packages, take a look at the following [documentation](https://www.gem5.org/documentation/gem5-stdlib/extending-disk-images). ## Troubleshooting -- **Enable Packer Logs**: +- **Enable Packer Logs**: This causes Packer to print additional debug messages. ```sh PACKER_LOG=INFO ./build.sh @@ -158,6 +170,12 @@ To take a pre-built image and add new files or packages, take a look at the foll - **Monitor Installation**: - Use a **VNC viewer** to watch installation. The port is displayed in the terminal. + The output may appear as follows: + + ```bash + ==> qemu.initialize: Waiting 10s for boot... + ==> qemu.initialize: Connecting to VM via VNC (127.0.0.1:5995) + ``` For further details, refer to: [Ubuntu Autoinstall Documentation](https://ubuntu.com/server/docs/install/autoinstall). From 2e2224cd45c2f17a62883176164435ebee405013 Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Fri, 16 May 2025 10:00:16 -0700 Subject: [PATCH 17/18] resources: add a script to disable systemd services for arm isa --- .../scripts/post-installation.sh | 11 +++-- .../packer-scripts/arm-ubuntu.pkr.hcl | 2 +- .../scripts/disable-systemd-services-arm.sh | 48 +++++++++++++++++++ 3 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 src/ubuntu-generic-diskimages/scripts/disable-systemd-services-arm.sh diff --git a/src/npb-24.04-imgs/scripts/post-installation.sh b/src/npb-24.04-imgs/scripts/post-installation.sh index b6518f16d..1754681e0 100755 --- a/src/npb-24.04-imgs/scripts/post-installation.sh +++ b/src/npb-24.04-imgs/scripts/post-installation.sh @@ -16,9 +16,14 @@ make clean make suite M5_ANNOTATION=1 echo "Disabling network by default" echo "See README.md for instructions on how to enable network" -mv /etc/netplan/50-cloud-init.yaml /etc/netplan/50-cloud-init.yaml.bak + +if [ -f /etc/netplan/50-cloud-init.yaml ]; then + mv /etc/netplan/50-cloud-init.yaml /etc/netplan/50-cloud-init.yaml.bak +elif [ -f /etc/netplan/00-installer-config.yaml ]; then + mv /etc/netplan/00-installer-config.yaml /etc/netplan/00-installer-config.yaml.bak + netplan apply +fi + # Disable systemd service that waits for network to be online systemctl disable systemd-networkd-wait-online.service systemctl mask systemd-networkd-wait-online.service - -netplan apply \ No newline at end of file diff --git a/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl b/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl index 91ac95673..86634e048 100644 --- a/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl +++ b/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl @@ -159,7 +159,7 @@ build { provisioner "shell" { execute_command = "echo '${var.ssh_password}' | {{ .Vars }} sudo -E -S bash '{{ .Path }}'" - scripts = ["scripts/disable-network.sh"] + scripts = ["scripts/disable-systemd-services-arm.sh","scripts/disable-network.sh"] expect_disconnect = true } diff --git a/src/ubuntu-generic-diskimages/scripts/disable-systemd-services-arm.sh b/src/ubuntu-generic-diskimages/scripts/disable-systemd-services-arm.sh new file mode 100644 index 000000000..a34bb1eab --- /dev/null +++ b/src/ubuntu-generic-diskimages/scripts/disable-systemd-services-arm.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +# Copyright (c) 2024 The Regents of the University of California. +# SPDX-License-Identifier: BSD 3-Clause + +echo "Disabling systemd services for arm architecture..." + +# Mask systemd-random-seed to avoid long waits for entropy in gem5 simulations +systemctl mask systemd-random-seed.service + +# Disable multipathd — not needed for single disk setup or simulation +systemctl disable multipathd.service + +# Disable snapd and its socket — snap package manager is not used in gem5 +systemctl disable snapd.service snapd.socket + +# Disable periodic system maintenance timers to reduce boot time +systemctl disable apt-daily.timer apt-daily-upgrade.timer fstrim.timer + +# Disable accounts-daemon — manages desktop login accounts (not needed headless) +systemctl disable accounts-daemon.service + +# Disable lvm2-monitor — not required unless simulating logical volumes +systemctl disable lvm2-monitor.service + +# Disable AppArmor — optional security daemon that slows boot and isn't needed +systemctl disable apparmor.service snapd.apparmor.service + +# Disable ModemManager — manages cellular devices, irrelevant in gem5 +systemctl mask ModemManager.service + +# Disable udisks2 — disk hotplug and automounting service, not useful in static sim +systemctl disable udisks2.service + +# Disable system time sync — not needed for simulated time environments +systemctl disable systemd-timesyncd.service + +# Disable rsyslog — persistent logging not required and slows simulation +systemctl disable rsyslog.service + +# Switch default target to multi-user (no GUI) +sudo systemctl set-default multi-user.target + +# Mask plymouth — graphical boot splash screen, not needed in headless mode +systemctl mask plymouth-start.service plymouth-quit.service plymouth-read-write.service + + +echo "completed disabling systemd services for arm." \ No newline at end of file From f480e520ef4cad4b142be50116b17da5c34d1784 Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Fri, 16 May 2025 15:40:43 -0700 Subject: [PATCH 18/18] resources: Update disk image download links --- src/npb-24.04-imgs/arm-npb.pkr.hcl | 6 +++--- src/npb-24.04-imgs/build-arm.sh | 4 ++-- src/npb-24.04-imgs/build-x86.sh | 4 ++-- src/npb-24.04-imgs/x86-npb.pkr.hcl | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/npb-24.04-imgs/arm-npb.pkr.hcl b/src/npb-24.04-imgs/arm-npb.pkr.hcl index 72f223917..20cef1397 100644 --- a/src/npb-24.04-imgs/arm-npb.pkr.hcl +++ b/src/npb-24.04-imgs/arm-npb.pkr.hcl @@ -35,10 +35,10 @@ source "qemu" "initialize" { format = "raw" headless = "true" disk_image = "true" - iso_checksum = "sha256:50cd77b981f149ef291a0ad36ad7f7f03fb9f31236c7969fe0b91151fdda768f" - iso_urls = ["../ubuntu-generic-diskimages/arm-disk-image-24-04/arm-ubuntu"] + iso_checksum = "sha256:3dbf4f105882cc386fc1e50b6e2c70c94789083038252175739ab6a5e4b1ce52" + iso_urls = ["./arm-ubuntu-24.04-20250515.gz"] memory = "8192" - output_directory = "disk-image-arm-npb" + output_directory = "disk-image-arm-npb-test" qemu_binary = "/usr/bin/qemu-system-aarch64" qemuargs = [ ["-boot", "order=dc"], ["-bios", "./files/flash0.img"], diff --git a/src/npb-24.04-imgs/build-arm.sh b/src/npb-24.04-imgs/build-arm.sh index 33f627e42..30beb9515 100755 --- a/src/npb-24.04-imgs/build-arm.sh +++ b/src/npb-24.04-imgs/build-arm.sh @@ -14,8 +14,8 @@ dd if=/usr/share/qemu-efi-aarch64/QEMU_EFI.fd of=flash0.img conv=notrunc cd .. # get the base image from gem5 resoruces -wget https://storage.googleapis.com/dist.gem5.org/dist/develop/images/arm/ubuntu-24-04/arm-ubuntu-24.04-20240823.gz -gunzip arm-ubuntu-24.04-20240823.gz +wget https://gem5resources.blob.core.windows.net/dist-gem5-org/dist/develop/images/arm/ubuntu-24-04/arm-ubuntu-24.04-20250515.gz +gunzip arm-ubuntu-24.04-20250515.gz # Install the needed plugins ./packer init arm-npb.pkr.hcl diff --git a/src/npb-24.04-imgs/build-x86.sh b/src/npb-24.04-imgs/build-x86.sh index 50ec0e8ac..e3cf74360 100755 --- a/src/npb-24.04-imgs/build-x86.sh +++ b/src/npb-24.04-imgs/build-x86.sh @@ -11,8 +11,8 @@ if [ ! -f ./packer ]; then rm packer_${PACKER_VERSION}_linux_amd64.zip; fi -wget https://storage.googleapis.com/dist.gem5.org/dist/develop/images/x86/ubuntu-24-04/x86-ubuntu-24-04-v2.gz -gunzip x86-ubuntu-24-04-v2.gz +wget https://gem5resources.blob.core.windows.net/dist-gem5-org/dist/develop/images/x86/ubuntu-24-04/x86-ubuntu-24.04-20250515.gz +gunzip x86-ubuntu-24.04-20250515.gz # Install the needed plugins ./packer init x86-npb.pkr.hcl diff --git a/src/npb-24.04-imgs/x86-npb.pkr.hcl b/src/npb-24.04-imgs/x86-npb.pkr.hcl index 588a0e657..b0f3976e3 100644 --- a/src/npb-24.04-imgs/x86-npb.pkr.hcl +++ b/src/npb-24.04-imgs/x86-npb.pkr.hcl @@ -36,8 +36,8 @@ source "qemu" "initialize" { format = "raw" headless = "true" disk_image = "true" - iso_checksum = "sha256:b1f8421956d374207ebca70f176374ff9e1e8c46f74bfb2c47a6583e4eae758e" - iso_urls = ["../ubuntu-generic-diskimages/x86-disk-image-24-04/x86-ubuntu"] + iso_checksum = "sha256:58dfdabfd2510657776ad946c8c4e9cceacbd0806414690598a4f4808c2349b6" + iso_urls = ["./x86-ubuntu-24.04-20250515"] memory = "8192" output_directory = "disk-image-x86-npb" qemu_binary = "/usr/bin/qemu-system-x86_64"