Skip to content

Commit

Permalink
resources: Update arm image to ubuntu 22.04 (#32)
Browse files Browse the repository at this point in the history
- Update building image using packer.
- Add scripts and exot events to the image.
  • Loading branch information
Harshil2107 authored May 13, 2024
1 parent 4204f14 commit 5ea3e56
Show file tree
Hide file tree
Showing 15 changed files with 364 additions and 221 deletions.
94 changes: 94 additions & 0 deletions src/arm-ubuntu/arm-ubuntu.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
packer {
required_plugins {
qemu = {
source = "github.com/hashicorp/qemu"
version = "~> 1"
}
}
}

variable "image_name" {
type = string
default = "arm-ubuntu"
}

variable "ssh_password" {
type = string
default = "12345"
}

variable "ssh_username" {
type = string
default = "gem5"
}

source "qemu" "initialize" {
boot_command = [
"c<wait>",
"linux /casper/vmlinuz autoinstall ds=nocloud-net\\;s=http://{{.HTTPIP}}:{{.HTTPPort}}/ --- ",
"<enter><wait>",
"initrd /casper/initrd",
"<enter><wait>",
"boot",
"<enter>",
"<wait>"
]
cpus = "4"
disk_size = "4600"
format = "raw"
headless = "true"
http_directory = "http"
iso_checksum = "sha256:c209ab013280d3cd26a344def60b7b19fbb427de904ea285057d94ca6ac82dd5"
iso_urls = ["https://old-releases.ubuntu.com/releases/jammy/ubuntu-22.04-live-server-arm64.iso"]
memory = "8192"
output_directory = "disk-image"
qemu_binary = "/usr/bin/qemu-system-aarch64"
qemuargs = [ ["-boot", "order=dc"],
["-bios", "./files/flash0.img"],
["-cpu", "host"],
["-enable-kvm"],
["-machine", "virt"],
["-machine", "gic-version=3"],
["-vga", "virtio"],
["-device","virtio-gpu-pci"],
["-device", "qemu-xhci"],
["-device","usb-kbd"],

]
shutdown_command = "echo '${var.ssh_password}'|sudo -S shutdown -P now"
ssh_password = "${var.ssh_password}"
ssh_username = "${var.ssh_username}"
ssh_wait_timeout = "60m"
vm_name = "${var.image_name}"
ssh_handshake_attempts = "1000"
}

build {
sources = ["source.qemu.initialize"]

provisioner "file" {
destination = "/home/gem5/"
source = "files/exit.sh"
}

provisioner "file" {
destination = "/home/gem5/"
source = "files/gem5_init.sh"
}

provisioner "file" {
destination = "/home/gem5/"
source = "files/after_boot.sh"
}

provisioner "file" {
destination = "/home/gem5/"
source = "files/serial-getty@.service"
}

provisioner "shell" {
execute_command = "echo '${var.ssh_password}' | {{ .Vars }} sudo -E -S bash '{{ .Path }}'"
scripts = ["scripts/post-installation.sh"]
}

}
13 changes: 13 additions & 0 deletions src/arm-ubuntu/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
PACKER_VERSION="1.10.0"

if [ ! -f ./packer ]; then
wget https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_arm64.zip;
unzip packer_${PACKER_VERSION}_linux_arm64.zip;
rm packer_${PACKER_VERSION}_linux_arm64.zip;
fi

# Install the needed plugins
./packer init arm-ubuntu.pkr.hcl

# Build the image
./packer build arm-ubuntu.pkr.hcl
83 changes: 0 additions & 83 deletions src/arm-ubuntu/disk-image/arm-ubuntu/arm-ubuntu.json

This file was deleted.

9 changes: 0 additions & 9 deletions src/arm-ubuntu/disk-image/arm-ubuntu/cloud.txt

This file was deleted.

23 changes: 0 additions & 23 deletions src/arm-ubuntu/disk-image/arm-ubuntu/gem5_init.sh

This file was deleted.

15 changes: 0 additions & 15 deletions src/arm-ubuntu/disk-image/arm-ubuntu/init.gem5

This file was deleted.

14 changes: 0 additions & 14 deletions src/arm-ubuntu/disk-image/arm-ubuntu/post-installation.sh

This file was deleted.

76 changes: 0 additions & 76 deletions src/arm-ubuntu/disk-image/build.sh

This file was deleted.

57 changes: 57 additions & 0 deletions src/arm-ubuntu/files/after_boot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

# Copyright (c) 2022,2024 The University of California.
# Copyright (c) 2021 The University of Texas at Austin.
# SPDX-License-Identifier: BSD 3-Clause

# This file is executed at the end of the bashrc for the gem5 user.
# The script checks to see if we should run in interactive mode or not.
# If we are in interactive mode, the script will drop to a shell.
# If we are not in interactive mode, the script will check if we should
# run a script from the gem5-bridge. If so, it will run the script and
# exit. If there is no script and we are not in interactive mode, it will
# exit. This last option is used for testing purposes.

# 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.

# Read /proc/cmdline and parse options

cmdline=$(cat /proc/cmdline)
interactive=false
IGNORE_M5=0
if [[ $cmdline == *"interactive"* ]]; then
interactive=true
fi

printf "Interactive mode: $interactive\n"

if [[ $interactive == true ]]; then
printf "Interactive mode enabled, dropping to shell."
/bin/bash
else
# Try to read the file from the host when running with gem5
if ! [ -z $IGNORE_M5 ]; then
printf "Starting gem5 init... trying to read run script file via readfile.\n"
if ! gem5-bridge readfile > /tmp/script; then
printf "Failed to run gem5-bridge readfile, exiting!\n"
rm -f /tmp/script
# If we can't read the script exit the simulation. If we cannot exit the
# simulation, this probably means that we are running in QEMU. So, ignore
# future calls to gem5-bridge.
if ! gem5-bridge exit; then
# Useful for booting the disk image in (e.g.,) qemu for debugging
printf "gem5-bridge exit failed, dropping to shell.\n"
IGNORE_M5=1 /bin/bash
fi
else
printf "Running script from gem5-bridge stored in /tmp/script\n"
chmod 755 /tmp/script
/tmp/script
printf "Done running script from gem5-bridge, exiting.\n"
rm -f /tmp/script
gem5-bridge exit
fi
fi
fi
6 changes: 6 additions & 0 deletions src/arm-ubuntu/files/exit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

# Copyright (c) 2020 The Regents of the University of California.
# SPDX-License-Identifier: BSD 3-Clause

m5 exit
Loading

0 comments on commit 5ea3e56

Please sign in to comment.