ChorusOS 4.0 File System Administration Guide

6.2 Making a RAM Disk the Main System Disk

You can use RAM to house the root file system. This example shows you how. It is assumed that you have already been able to mount a root directory through NFS. See "6.1 Mounting a Root File System over NFS" for details.

Before you get started, you must add RAM disk support to your system image. The following commands add that support, build the system image, copy the image to the download directory and reboot the ChorusOS system running on an x86 target:


$ cd build_dir
$ configurator -c conf/ChorusOS.xml -set RAM_DISK=true
$ configurator -c conf/ChorusOS.xml -set iom.ramdisk0.size=0x1600000
$ configurator -c conf/ChorusOS.xml -set iom.ramdisk.sizeMax=0x1600000
$ make chorus
$ cp chorus.bmon /tftpboot
$ rsh target reboot

In order to use RAM to house the root file system, you must first label part of the available space using disklabel(1M). disklabel uses entries in disktab(4CC) to label the disk. The following disktab entry serves to label a 16 megabyte area of RAM as a disk:

# This label can be used for a 16 megabyte RAM disk. The corresponding
# newfs command to be used with this RAM disk is:
# rsh target arun /bin/newfs -o space -c 2048 -m 0 /dev/rrd0a

rd16Meg:\
	:ns#4:nt#4:nc#32768 \
	:pa#32768:oa#0:ta=4.2BSD: \
	:pc#32768:oc#0:tc=unused:

The default system initialization file, sysadm.ini(4CC), creates special files to access the RAM, so you probably do not need to create them yourself. The entries to create special files may appear as follows in sysadm.ini:

# Create special files for RAM disk
mknod /dev/rrd0a c 13 0
mknod /dev/rrd0b c 13 1
mknod /dev/rrd0c c 13 2
mknod /dev/rd0a  b 13 0
mknod /dev/rd0b  b 13 1
mknod /dev/rd0c  b 13 2

The above example creates both raw and block mode special files for two user-accessible partitions, a and b, and one partition, c, for use by the system only.

Assuming the special files exist, you can proceed to label the disk and so forth. The following commands label the disk, read the label, create a file system on the disk and check the file system:


$ rsh target arun /bin/disklabel -w -r rd0 rd16Meg
started aid = 22
$ rsh target arun /bin/disklabel -r rd0
started aid = 22
# /dev/rrd0c:
type: unknown
disk: rd16Meg
label: 
flags:
bytes/sector: 512
sectors/track: 4
tracks/cylinder: 4
sectors/cylinder: 16
cylinders: 32768
rpm: 3600
interleave: 1
trackskew: 0
cylinderskew: 0
headswitch: 0		# milliseconds
track-to-track seek: 0	# milliseconds
drivedata: 0 

3 partitions:
#        size   offset    fstype   [fsize bsize   cpg]
  a:    32768        0    4.2BSD        0     0     0 	# (Cyl.    0 - 2047)
  c:    32768        0    unused        0     0       	# (Cyl.    0 - 2047)
$ rsh target arun /bin/newfs /dev/rrd0a
started aid = 22
/dev/rrd0a:	32768 sectors in 8 cylinders of 1 tracks, 4096 sectors
	16MB in 1 cyl groups (16 c/g, 32MB/g, 7680 i/g)
super-block backups (for fsck -b #) at:
 32,
$ rsh target arun /bin/fsck -y /dev/rrd0a
started aid = 22
** /dev/rrd0a
** Last Mounted on 
** Phase 1 - Check Blocks and Sizes
** Phase 2 - Check Pathnames
** Phase 3 - Check Connectivity
** Phase 4 - Check Reference Counts
** Phase 5 - Check Cyl groups
1 files, 1 used, 15390 free (14 frags, 1922 blocks, 0.1% fragmentation)

Once you have checked the new file system and it is ready to use, mount it in the current file system hierarchy. As the current root file system is located on the host workstation, create the mount point on the host and then mount the RAM file system there:


$ cd target_root_dir
$ mkdir ram
$ rsh target mount -t ufs /dev/rd0a /ram
/dev/rd0a on /ram

Next, populate the RAM file system with the contents of all file systems except the /dev, /image, /tmp and /ram directories. Create mount points for the /dev, /image and /tmp file systems:


$ rsh target arun /bin/cp -R bin etc lib ram/
started aid = 22
$ rsh target arun /bin/mkdir /ram/dev
$ rsh target arun /bin/mkdir /ram/image
$ rsh target arun /bin/mkdir /ram/tmp

The RAM file system, mounted under the /ram directory, now contains everything needed to serve as the main system disk. Take advantage of the fact that the mount command is built into the C_INIT system actor.

Unmount the root file system.

The following commands unmount the root file system on the target and remount the RAM file system in its place:


$ rsh target umount /ram
$ rsh target umount /
$ rsh target mount -t ufs /dev/rd0a /
$ rsh target arun /bin/fsck /dev/rrd0a
$ rsh target mount -t ufs -o update /dev/rd0a /

The target is now independent of the host, using the RAM disk as the main disk:


$ rsh target arun /bin/ls
started aid = 22
bin             dev             etc             image           lib
tmp

Note that the ls actor used above is located in the RAM disk file system.

The following script is meant to run on the host workstation (or other system) and summarizes the above scenario:

#!/bin/sh

#
# Reboot the target and give it some time to come up.
#
rsh target reboot
sleep 60
# 
# While the host 'sleeps', the target downloads the system image, and
# executes system initialization commands in sysadm.ini, mounting
# the root file system through NFS.
#

#
# Label the RAM disk, then create the file system and check it.
#
rsh target arun /bin/disklabel -w -r rd0 rd16Meg MyRamDisk
rsh target arun /bin/newfs /dev/rrd0a
rsh target arun /bin/fsck -y /dev/rrd0a

#
# Mount the RAM file system and populate it with the rest of the root
# directory.
#
rsh target mount -t ufs /dev/rd0a /ram
rsh target arun /bin/cp -R bin etc lib ram/
rsh target arun /bin/mkdir /ram/dev
rsh target arun /bin/mkdir /ram/image
rsh target arun /bin/mkdir /ram/tmp

#
# Unmount everything, then mount the RAM file system at the root.
#
rsh target umount /ram
rsh target umount /
rsh target mount -t ufs /dev/rd0a /
rsh target arun /bin/fsck /dev/rrd0a
rsh target mount -t ufs -o update /dev/rd0a /

After adapting the above script for your environment, run it to make your ChorusOS target self-sufficient.