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" diff --git a/src/ubuntu-generic-diskimages/BUILDING.md b/src/ubuntu-generic-diskimages/BUILDING.md index 48b49352d..dbe0887a2 100644 --- a/src/ubuntu-generic-diskimages/BUILDING.md +++ b/src/ubuntu-generic-diskimages/BUILDING.md @@ -4,148 +4,178 @@ 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. 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. 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. 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. -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**. -```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 -``` +### **Building and Installing Kernel Modules (ARM)** -**Note**: The `build-arm.sh` will make this file for you. +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. -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. +#### **Steps to Build the Kernel and Modules** -## Kernel +1. **Navigate to the Appropriate Directory** + Change to the directory corresponding to the Ubuntu version of the disk image you are building: -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. + ```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 + ``` -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`. +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: -## Changes from the base Ubuntu image + ```sh + ./copy_modules_to_host.sh + ``` -- 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`. +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: -### Customization of the boot Processes + - `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`. -- **`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. +### **Generating the EFI Boot File** -### Details of the After-Boot Script +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. -- **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: +To generate `flash0.img` manually, run the following commands in the `files/` directory: -```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 +```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 ``` -This ensures `after-boot.sh` runs only once per session by setting an environment variable. +## Building the Disk Image -### Adjusting File Permissions +- **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. -- **Setting Permissions for `gem5-bridge`**: Since the default user is not root, `gem5-bridge` requires root permissions. Apply setuid to grant these permissions: +- **For ARM**: + Run `build-arm.sh` with `22.04` or `24.04` to build the respective ARM disk image in `ubuntu-generic-diskimages`. - ```sh - chmod u+s /path/to/gem5-bridge + **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: + + ```bash + ./packer build -var "use_kvm=false" -var "ubuntu_version=${ubuntu_version}" ./packer-scripts/arm-ubuntu.pkr.hcl ``` -## Extending the disk image with custom files and scripts + 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: -- 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. + ```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 + ``` -```hcl -provisioner "file" { - destination = "/home/gem5/" - source = "path/to/files" - } -``` + The `build-arm.sh` script downloads the Packer binary, initializes Packer, and builds the disk image. -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. +## Kernel Extraction (x86 Only) -**NOTE:** You can extend this disk image by modifying the `post-installation.sh` script, but it requires building the image from scratch. +For **x86 disk images**, the kernel is extracted as part of the post-installation process. -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). +- 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`. -## Creating a Disk Image from Scratch +This kernel can be used as a resource for **gem5 simulations** and is not restricted to this disk image. -### Automated Ubuntu Installation +## Changes from the Base Ubuntu Image -- **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. +- **Default User**: + - Username: `gem5` + - Password: `12345` -### Configuration and Directory Structure +- **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**: -- **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. + ```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 + ``` + +- **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`. + +## Extending the Disk Image + +- 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 + 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 the packer file 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 `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 -To see what `packer` is doing, you can use the environment variable `PACKER_LOG=INFO` when running `./build.sh`. +- **Enable Packer Logs**: This causes Packer to print additional debug messages. -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 + ```sh + PACKER_LOG=INFO ./build.sh + ``` -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. +- **Common Packer Bug**: + - VM build may abort after **2-5 minutes**, even with `ssh_timeout` set. + - Workaround: **Increase `ssh_handshake_attempts`** (e.g., `1000`). -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") +- **Monitor Installation**: + - Use a **VNC viewer** to watch installation. The port is displayed in the terminal. + The output may appear as follows: -```sh -mkdir x86-ubuntu/mount -sudo mount -o loop,offset=2097152,norecovery x86-ubuntu/x86-ubuntu-image/x86-ubuntu x86-ubuntu/mount -``` + ```bash + ==> qemu.initialize: Waiting 10s for boot... + ==> qemu.initialize: Connecting to VM via VNC (127.0.0.1:5995) + ``` -Useful documentation: +For further details, refer to: +[Ubuntu Autoinstall Documentation](https://ubuntu.com/server/docs/install/autoinstall). 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..94719272e 100755 --- a/src/ubuntu-generic-diskimages/files/arm/gem5_init.sh +++ b/src/ubuntu-generic-diskimages/files/arm/gem5_init.sh @@ -15,11 +15,27 @@ 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. 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 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 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..e421f8a2d 100755 --- a/src/ubuntu-generic-diskimages/files/x86/gem5_init.sh +++ b/src/ubuntu-generic-diskimages/files/x86/gem5_init.sh @@ -15,11 +15,27 @@ 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. 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 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..88d59da74 --- /dev/null +++ b/src/ubuntu-generic-diskimages/kernel-and-modules/arm-ubuntu-22.04/Dockerfile @@ -0,0 +1,48 @@ +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 && \ + cd scripts && \ + chmod +x pahole-version.sh && \ + cd .. && \ + make defconfig && \ + 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 && \ + 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.168 && \ + 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..b8e817a46 --- /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="Dockerfile" +OUTPUT="my-arm-5.15.168-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..737adaf1a --- /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 $(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 && \ + 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 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..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,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.168-kernel/5.15.168" } "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,35 @@ 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/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", + "scripts/install-user-packages.sh", + ] environment_vars = ["ISA=arm64"] 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-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 3d88dce63..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,19 +93,36 @@ 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" - 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/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/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..245f54c2d --- /dev/null +++ b/src/ubuntu-generic-diskimages/scripts/increase-system-entropy-for-arm-disk.sh @@ -0,0 +1,37 @@ + +#!/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 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 +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!" 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 1f37ac98b..000000000 --- a/src/ubuntu-generic-diskimages/scripts/post-installation.sh +++ /dev/null @@ -1,126 +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=stable -pushd gem5 -# Checkout just the files we need -git sparse-checkout add util/m5 -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 -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..68b1d6a6f --- /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.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 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