Skip to content
This repository was archived by the owner on Mar 3, 2025. It is now read-only.

Commit 29a788a

Browse files
authored
Dev 0.7.2 (#7)
* Added example scripts for qemu installation/running. * Update README.md * Create README.md Some basic how-to
1 parent e861e41 commit 29a788a

File tree

6 files changed

+125
-0
lines changed

6 files changed

+125
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ specify which extensions to disable via the `-cpu` flag in QEMU, e.g.
277277
... -cpu host,-avx2,-bmi1,-bmi2 ...
278278
```
279279

280+
We have provided some example scripts in the [scripts][scripts] directory.
281+
280282
2. Not all checkpoints run successfully. For example, checkpoints that attempt
281283
to invoke syscalls generally end up crashing.
282284

@@ -317,3 +319,4 @@ any and all feedback and would like to make this tool as useful as possible.
317319
[gem5]: http://gem5.org/Main_Page
318320
[blog]: https://medium.com/@iangneal/lapidary-crafting-more-beautiful-gem5-simulations-4bc6f6aad717
319321
[smarts]: https://dl.acm.org/citation.cfm?id=859629
322+
[scripts]: scripts/

scripts/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Look at `common-vars.sh` for some variables that can be changed (disk name, amount of memory).
2+
3+
Run `install-vm.sh` to create a new VM.
4+
- Install with the basic Ubuntu server configuration. I recommend LVM if you decide to resize the image later.
5+
6+
Run `extract-kernel.sh` to get the linux kernel/initrd from the install disk image. This should work for LVM qcow2 images. You'll need to install `libguestfs-tools`.
7+
8+
Run `run-vm.sh` every time you want to start the VM. `^a-x` to kill qemu.
9+
10+
Once you get the VM working, reinstall Lapidary inside the VM and do all of your gem5 work within the VM.
11+
12+
_I know that there are many ways to do this, but I find the raw qemu approach to work the best across a variety of setups._

scripts/common-vars.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
# CPU Features
3+
4+
# -- These two configurations don't seem to boot.
5+
#CPU_FEATURES_DISABLE="-avx,-avx2,-bmi1,-bmi2,-sse,-sse2,-ssse3,-sse4_1,-sse4_2"
6+
#CPU_FEATURES_DISABLE="-avx,-avx2,-bmi1,-bmi2,-sse4_2,-sse4_1,-ssse3"
7+
CPU_FEATURES_DISABLE="-avx2,-bmi1,-bmi2"
8+
echo "CPU_FEATURES_DISABLE=$CPU_FEATURES_DISABLE"
9+
10+
UBUNTU_VERSION=18.04.4
11+
UBUNTU_ISO=./iso/ubuntu-$UBUNTU_VERSION-server-amd64.iso
12+
UBUNTU_URL=http://cdimage.ubuntu.com/releases/$UBUNTU_VERSION/release/ubuntu-$UBUNTU_VERSION-server-amd64.iso
13+
14+
NETBOOT_URL=http://archive.ubuntu.com/ubuntu/dists/bionic-updates/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64
15+
16+
BOOT_DIR="./boot"
17+
KERNEL=$BOOT_DIR/linux
18+
KERNEL_URL=$NETBOOT_URL/linux
19+
INITRD=$BOOT_DIR/initrd.gz
20+
INITRD_URL=$NETBOOT_URL/initrd.gz
21+
22+
# Installation parameters
23+
24+
DISK_SIZE_GB=100
25+
26+
VM_DIR=$(realpath ~/workspace/vms)
27+
VM_NAME=lapidary-vm
28+
IMG_NAME=$VM_DIR/$VM_NAME.qcow2
29+
30+
# Runtime parameters
31+
32+
# -- This gives you 75% of the system memory for the VM.
33+
MEM_FRAC=0.75
34+
MEM=$(cat /proc/meminfo | grep MemTotal | awk '$3=="kB"{$2='$MEM_FRAC'*$2/1024;$3=""} 1' | tr -d " " | cut -d ":" -f 2 | cut -d "." -f 1)
35+
echo "MEM=$MEM"
36+
37+

scripts/extract-kernel.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#! /usr/bin/sudo /bin/bash
2+
set -e
3+
4+
source common-vars.sh
5+
6+
# Borrowed from https://gist.github.com/pshchelo/6ffabbffaedc46456b39c037d16e1d8c
7+
8+
echo "Note: this works if you install linux with LVM"
9+
10+
modprobe nbd max_part=8
11+
qemu-nbd --connect=/dev/nbd0 $IMG_NAME
12+
mkdir -p /tmp/mnt
13+
mount /dev/nbd0p1 /tmp/mnt
14+
15+
cp /tmp/mnt/boot/initrd.img-* $BOOT_DIR
16+
cp /tmp/mnt/boot/vmlinuz-* $BOOT_DIR
17+
18+
umount /tmp/mnt
19+
qemu-nbd -d /dev/nbd0

scripts/install-vm.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#! /usr/bin/sudo /bin/bash
2+
set -e
3+
4+
source common-vars.sh
5+
6+
mkdir -p boot
7+
if [ ! -f $KERNEL ]; then
8+
wget $KERNEL_URL -O $KERNEL
9+
fi
10+
if [ ! -f $INITRD ]; then
11+
wget $INITRD_URL -O $INITRD
12+
fi
13+
14+
mkdir -p iso
15+
if [ ! -f $UBUNTU_ISO ]; then
16+
wget $UBUNTU_URL -O $UBUNTU_ISO
17+
fi
18+
19+
if [ ! -f $IMG_NAME ]; then
20+
qemu-img create -f qcow2 $IMG_NAME $DISK_SIZE_GB"G"
21+
fi
22+
23+
exec qemu-system-x86_64 \
24+
-kernel $KERNEL \
25+
-initrd $INITRD \
26+
-nographic \
27+
-enable-kvm \
28+
-boot d \
29+
-cdrom $UBUNTU_ISO \
30+
-hda $IMG_NAME \
31+
-m $MEM \
32+
--append "console=ttyS0,115200n8" \
33+
-balloon virtio \
34+
-smp $(nproc) \
35+
-cpu host,$CPU_FEATURES_DISABLE \
36+
-no-reboot

scripts/run-vm.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#! /usr/bin/sudo /bin/bash
2+
set -e
3+
4+
source common-vars.sh
5+
6+
exec qemu-system-x86_64 \
7+
-kernel $VM_DIR/vmlinuz-* \
8+
-initrd $VM_DIR/initrd.img-* \
9+
-nographic \
10+
-enable-kvm \
11+
-hda $IMG_NAME \
12+
-m $MEM \
13+
--append "console=ttyS0,115200n8, root=/dev/sda1" \
14+
-balloon virtio \
15+
-smp $(nproc) \
16+
-cpu host,$CPU_FEATURES_DISABLE \
17+
-net user,hostfwd=tcp::5000-:22 \
18+
-net nic

0 commit comments

Comments
 (0)