Ubuntu Disk Image for ARM Full System

From gem5
Revision as of 14:48, 26 June 2012 by Gwblake (talk | contribs) (Update the page to account for changes in Ubuntu since 11.04)
Jump to: navigation, search

This page describes how to build a serial-console filesystem of Ubuntu Linux for ARM ISA simulation after the bare image file is created. An example Ubuntu Natty ARM image is available on the Download page.


Using Rootstock and Qemu to build the filesystem

The easiest way to create a disk image is to use the rootstock tool provided in Ubuntu to build an ARM filesystem. To create a base 2GB filesystem that can be booted to the serial console, run the following command:

%>rootstock --fqdn gem5sim --login gem5 --password 5meg --imagesize 2G --seed build-essential

Other packages can be added to the --seed option list to be installed by rootstock. Rootstock will create a tar file containing the file system. Unpack this tar file into the blank disk image. Packages can also be installed at a later date by mounting the filesystem to a loop device, mounting its proc filesystem and chroot'ing into the filesystem. Qemu will be used to emulate the binaries within the ARM filesystem to install additional packages using apt-get. For the below to work you need to have installed the rootstock packages so the various qemu emulators are available. For example

Attention: Rootstock has been deprecated by Ubuntu for making ARM disk images from x86 machines. They now offer core file system image tarballs for download.

Using Ubuntu CoreFS and Qemu to build an Ubuntu file system for 12.04LTS+

Ubuntu Core offers pre-compiled base file systems in a tarball for used instead of using rootstock. To use these tarballs, make sure to first install the qemu-arm-static package to be able to install packages to the file-system. First, download the image, mount your disk image and then unpack the tarball to the disk image to get a basic ubuntu install. Then copy the qemu-arm-static binary to the usr/bin directory of your disk image to allow ARM emulation for installing packages. Then perform the following operations to get a functional Ubuntu file system that can run hardfloat and softfloat binaries.

 
 // if you have not mounted the disk image, do so now, make sure to unpack the core
 // fs to this disk image before continuing
 mount -oloop,offset=32256 /tmp/Ubuntu-arm.img /mnt
 cd /mnt 
 mount -o bind /proc /mnt/proc
 mount -o bind /dev /mnt/dev
 mount -o bind /sys /mnt/sys
 cp /etc/resolv.conf /mnt/etc/
 chroot .
 
 // enable the universe repo in etc/apt/sources.list 
 apt-get update
 apt-get install ubuntu-minimal
 apt-get install build-essential
 apt-get install vim
 apt-get install gcc-multilib
 apt-get install g++-multilib
 apt-get install <what ever packages you want>
 

If you transfer the file system created by here to another computer make sure resolv.conf in /etc of the filesystem is updated to match the resolv.conf of the host system, otherwise apt-get will fail to function properly.

Setting up Upstart to be Gem5 friendly

Instead of the old SysV and init.d, Ubuntu uses Upstart for mounting filesystems and loading the various daemons upon boot. To speed up the process and subsequent simulations the following upstart scripts should be removed from the /etc/init folder in the new filesystem:

  • console.conf
  • console-setup.conf
  • container-detect.conf
  • cron.conf
  • dmesg.conf
  • hwclock.conf
  • hwclock-save.conf
  • mounted-debugfs.conf
  • mounted-tmp.conf
  • mountall-net.conf
  • network-interface-container.conf
  • network-interface-security.conf
  • plymouth.conf
  • plymouth-log.conf
  • plymouth-splash.conf
  • plymouth-stop.conf
  • plymouth-upstart-bridge.conf
  • rsyslog.conf
  • setvtrgb.conf
  • tty[x].conf (only need tty1.conf)
  • udev-fallback-graphics.conf
  • ureadahead.conf
  • ureadahead-other.conf

The following changes should be made to the mountall.conf script:

  • Remove the fsck checks at the beginning of the script declaration
  • Remove the fsck checks in the post-script declaration
  • Remove the exec mountall --daemon declaration so total control of what filesystems are mounted and when is retained

To the script field on the mountall.conf file, add at least the following:

 # Mount appropriate file systems from fstab and remount root.
 mount /proc
 mount /tmp
 mount /sys
 mount -o remount,rw /dev/sda1 /
 swapon /swapfile # if present

 # Make sure to emit all events that mountall would have
 initctl emit virtual-filesystems
 initctl emit local-filesystems
 initctl emit remote-filesystems
 initctl emit all-swaps
 initctl emit filesystem
 initctl emit mounting
 initctl emit mounted
 

Additionally, one of the tty.conf scripts should be modified like below to get a login prompt within m5term or load an .rcS job script with multi-user and job-control enabled:

 script
   if [ ! -c /dev/ttyAMA0 ]
   then
     mknod /dev/ttyAMA0 c 204 64
   fi
   if [ ! -c /dev/ttySA0 ]
   then
     if [ ! -L /dev/ttySA0 ]
     then
       ln -s /dev/ttyAMA0 /dev/ttySA0
     fi
   fi 

   /sbin/m5 readfile > /tmp/script
   chmod 755 /tmp/script
   if [ -s /tmp/script ]
   then
     exec su root -c '/tmp/script' # gives script full privileges as root user in multi-user mode
     exit 0
   else
     exec /sbin/getty -L ttySA0 38400 vt100 # login prompt
   fi
 end script
 

By default a modules.dep file will not be created by rootstock, this file is needed to prevent certain upstart scripts from failing. To create this file, add the following to the beginning of the script declaration in init/modules-init-tools.conf, or simply add your own custom modules.dep file in the appropriate directory for your kernel.

 if [ ! -e /lib/modules/`uname -r`/modules.dep ]
 then
   mkdir /lib/modules/`uname -r`
   echo "#No modules for this run of Gem5" > /lib/modules/`uname -r`/modules.dep
 fi
 

To allow passwordless login to the filesystem, edit the /etc/shadow file to have the gem5 and root entries look like the following.

 
 root::15201:0:99999:7:::
 gem5::15201:0:99999:7:::
 

Ensure that the tty that will be used as the login tty is contained within the /etc/securetty file. In most cases this will probably be ttyAMA0. Go through the mounted-proc.conf, mounted-dev.conf, mounted.tmp.conf and mounted-varrun.conf and verify all use the clause

 start on mounted 
 

so the scripts start running.

The rc-sysinit.conf file should have most of the script body commented out except for these lines:

 [ -n "${FROM_SINGLE_USER_MODE}" ] || /etc/init.d/rcS
 telinit "${DEFAULT_RUNLEVEL}"
 

Finally the /etc/hosts file must contain the following to get proper behavior for programs that use sockets to do RPC:

 127.0.0.1 localhost
 ::1 localhost ip6-localhost ip6-loopback
 fe00::0 ip6-localnet
 ff00::0 ip6-mcastprefix
 ff02::1 ip6-allnodes
 ff02::2 ip6-allrouters
 ff02::3 ip6-allhosts