Simics Disk Images Cheat Sheet

Simics Disk Images Cheat Sheet

Posted on 2013-07-02 by Ed Braaten

This article is a quick-reference of commands I’ve found helpful while installing OS’s and manipulating Simics hard-drive images. Simics is a simulation environment that allows you to run simulations of all kinds of hardware including entire platforms or combinations of platforms on a Linux host.

Installing an OS

This section outlines the installation of CentOS 6.4 on your favorite simulated platform using a virtual disk image with a capacity of 20GB.

  1. Add the following lines to your launch script to instantiate a cdrom connection to the installation iso file image. This example points Simics to use the CentOS 6.4 minimal installation ISO file stored in the /tmp directory:
    $iso_image = /tmp/CentOS-6.4-x86_64-minimal.iso
    $bootmedia = (new-file-cdrom file = $iso_image)
  2. Prior to running the OS install in your Simics simulation, create a blank, zeroed craff image that is only 512 bytes long. This dummy image will be the target for your installation. Do this in your current Simics workspace directory:
    dd if=/dev/zero of=centos-6.4.craff bs=512 count=1

    Note that Simics will store all changes to this disk image as diff files which would normally be lost when you end your Simics session. We’ll save the results of our install in step 4 below.

  3. Add the following lines to your launch script to connect the simulation model to your target and to make the target disk image writeable:
    $disk_image = "centos-6.4.craff"
    $disk_files = [["centos-6.4.craff", "rw", 0, 20496236544]]
  4. Do the complete installation and a clean shutdown of your new OS. Before closing out Simics, use the following command within Simics to write out a raw image of the state your target disk as a result of the install:
    <simulation_model>.disk.hd_image.save filename=centos-6.4.img
  5. The image saved in step 4 will be a raw image of the simulation’s current disk state. In our example case it will be a full 20GB in size. Use the following Simics CLI command to convert this raw image to a compressed craff-type file:
    craff centos-6.4.img -o centos-6.4-fresh-install.craff

    The resulting .craff file is only about 2GB in size. You can point your simulation scripts to use this resulting craff image as the starting point for the simulation rather than the dummy file we created in step 2. The centos-6.4.img file can probably be deleted as soon as the conversion has been successfully completed.

Updating/Changing files on an existing .craff image

This section describes how you can update an existing .craff file containing a Linux filesystem completely outside of a Simics session. An alternative method to the one outlined in the steps below would be to run a Simics session using the .craff file in question, make your filesystem updates, and then follow steps 4 and 5 of the OS installation section above.

  1. Use the Simics CLI craff command to expand the .craff file into a raw disk image:
    craff -d centos-6.4.craff -o disk.img
  2. Use the Linux fdisk utility to determine the layout of the disk image:
    fdisk -c disk.img

    Use the “u” command in fdisk to switch the units to sectors instead of cylinders, and then use the “p” command to print the partition table. You’ll need to multiply the beginning sector of the partition you want to look at by the sector size.

  3. Now mount the desired partition of the disk image using the loop device with an appropriate offset value:
    sudo mount -o loop,offset=1048576 disk.img /mnt/tmp

    In my example, fdisk reported that the first partition started at offset 2048 and the sector size was 512 bytes, hence the offset value for the loop option of mount was 1048576. Once this mount command is completed you can make any necessary changes to the files in the mounted file system, /mnt/tmp.

  4. Unmount the modified filesystem:
    sudo umount /mnt/tmp
  5. Convert the raw image back into a compressed .craff file for use in Simics:
    craff disk.img -o centos-6.4-updated.craff

    The resulting .craff file contains all the changes you made to the raw image – the disk.img file can be safely deleted to save disk space.

Simics is a registered trademark of Wind River Systems, Inc. Follow Wind River on Twitter @WindRiver or visit their website at http://windriver.com.


Copyright (C) 2013 by Ed Braaten.  All rights reserved.
Other Blog Entries
https://ed.braaten.net/