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
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
> 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