Mario Badr

Oct 19, 2016

Ubuntu 14.04 Disk Images for gem5

There is an excellent post by Jason on creating disk images for gem5. Unfortunately I ran into several issues while trying to reproduce his work. The first set of issues stemmed from using the util/gem5img.py script to create a new disk image. The second set of issues stemmed from the fact that Ubuntu Core no longer exists -- the thousands of links to Ubuntu Core that currently exist on the internet will 404. I eventually discovered that Ubuntu Core is now Ubuntu Base. If your current O.S. is Ubuntu 14.04, you can follow Jason's tutorial without much trouble if you use ubuntu-base instead of ubuntu-core.

If you have Ubuntu 16.04 or some other version that has updated sfdisk then you won't be able to use util/gem5img.py. The reason is that several options for sfdisk, such as -D, -C-, -H, and -S have been removed. The script uses sfdisk to create a partition on the newly created disk image. So I had to go about creating my own disk image the old fashioned way. The old fashioned way involves using dd to create an image of all 0s then using GParted GUI to create a partition. GParted allows you to create an MBR partition (select msdos for the partition table type) and will allow you to choose the ext2 filesystem (which util/gem5img.py defaults to).

Once I had created my disk image and partitioned it, I needed to mount it before I could continue with Jason's tutorial. For this we need to know the offset at which the partition starts, which we can do using parted. For an image called ubuntu-14.04.img, we (1) launch parted, (2) specify the units to be Bytes, and (3) print information on the partition:

> parted ubuntu-14.04.img
WARNING: You are not superuser.  Watch out for permissions.
GNU Parted 3.2
Using /home/badrmari/Projects/uoft-comp-arch/gem5/disks/ubuntu-14.04.img
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) unit
Unit?  [compact]? B
(parted) print
Model:  (file)
Disk /home/badrmari/Projects/uoft-comp-arch/gem5/disks/ubuntu-14.04.img: 8589934592B
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start     End          Size         Type     File system  Flags
 1      1048576B  8589934591B  8588886016B  primary  ext2

We can see from above that the Start is at 1048576 Bytes. So now we need to mount the device at that specific offset:

> mount -o loop,rw,offset=1048576 ubuntu-14.04.img mnt/

You may now proceed with Jason's tutorial and extract Ubuntu Core into mnt, et cetera. I also removed the plymouth-upstart-bridge.conf from the image's /etc/init to avoid some error/warning messages. Placing the image into your $M5_PATH/disks directory, you can then load it in gem5 (with the kernel created in the previous post):

> ./build/X86_MESI_Two_Level/gem5.opt configs/example/fs.py --kernel=x86_64-vmlinux-3.4.112 --disk-image=ubuntu-14.04.img

Oct 18, 2016

Updating the gem5 Linux Kernel for x86

I was recently pointed to a GitHub repository for setting up a disk image for gem5 that contains the PARSEC Benchmarks. Unfortunately the steps listed to create a disk image did not work for me when booting with gem5. However, the repo does contain a kernel configuration for linux version 3.4.112, which I have saved in a gist just in case.

To compile the kernel, head over to The Linux Kernel Archives and download the appropriate version (in this case 3.4.112). Extract the kernel, and copy over the kernel configuration into the extracted directory with the .config filename. Now typing make vmlinux should give you a kernel that you can boot just fine with gem5, even while using their (very old) disk images.

The following steps should produce a binary called vmlinux:

> wget https://cdn.kernel.org/pub/linux/kernel/v3.x/linux-3.4.112.tar.xz
> tar -xJf linux-3.4.112.tar.xz
> cd linux-3.4.112
> wget https://gist.githubusercontent.com/mariobadr/8f12d7fd5794e6b219d8cc9c193c0874/raw/3e529e91b341597697ec1364a0a7766296e54632/X86_64-vmlinux-3.4.112
> mv X86_64-vmlinux-3.4.112 .config
> make vmlinux

In order to load the kernel add it to your binaries directory in M5_PATH -- I renamed it to x86_64-vmlinux-3.4.112. Because of the way the full system python scripts work, you'll need to add the full system files from the gem5 website to their respective binaries and disks folders. That is, $M5_PATH/binaries should contain x86_64-vm-linux-2.6.22.9 and in addition to the kernel we created above. Also, M5_PATH/disks should contain x86root.img and linux-bigswap2.img (the latter is actually in the ALPHA full system tarball) disk images. Ideally the python scripts should be updated... but that's a different post entirely. Assuming your directories are setup as above and you have compiled an X86 version of gem5, you can run gem5 in full system mode like so:

> ./build/X86_MESI_Two_Level/gem5.opt configs/example/fs.py --kernel=x86_64-vmlinux-3.4.112