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.
This section outlines the installation of CentOS 6.4 on your favorite simulated platform using a virtual disk image with a capacity of 20GB.
$iso_image = /tmp/CentOS-6.4-x86_64-minimal.iso
$bootmedia = (new-file-cdrom file = $iso_image)
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.
$disk_image = "centos-6.4.craff"
$disk_files = [["centos-6.4.craff", "rw", 0, 20496236544]]
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.
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.
craff -d centos-6.4.craff -o disk.img
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.
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.
sudo umount /mnt/tmp
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