Ramdisk

From ZeptoOS
Jump to: navigation, search

Kernel | Top | ZOID


Introduction

Both the CN and the ION Linux kernels require a ramdisk to boot. Ramdisk images contain minimal Linux utilities, init scripts, configuration files, kernel modules, etc, which are required by the OS boot process.

ION ramdisk is an ELF file that contains a cpio archive of system files. Two ION ramdisk images are currently generated:

BGP-ION-ramdisk-for-CNL.elf
Default ION ramdisk for ZeptoOS compute node Linux.
BGP-ION-ramdisk-for-CNK.elf
Use this one if you need to run IBM CNK on the compute nodes (uses IBM CIOD instead of ZOID)

Our ION ramdisks are similar to the default ION ramdisk from IBM, but we add some extra files to support ZeptoOS features. The extra files are located in ramdisk/ION/ramdisk-add/. The build-ramdisk script from IBM BGP driver is used to create the ION ramdisks.

The CN ramdisk is also a gzip'ed cpio archive of system files, but CN ramdisk is embedded into the CN kernel image (BGP-CN-zImage-with-initrd.elf). The CN ramdisk is created by a custom ramdisk build script (ramdisk/CN/create-bgp-cn-linux-ramdisk.pl). Both build-ramdisk and create-bgp-cn-linux-ramdisk.pl are wrappers around the Linux kernel's gen_init_cpio command.

Creating ramdisk images

The ramdisk images are always (re-)created from prebuilt objects if one types make at the top level directory (without any make target).

If one wants to create an ION ramdisk individually (without rebuilding other images), type:

$ make bgp-ion-ramdisk-cnl

If one wants to create a CN ramdisk (technically, create a CN kernel image with new ramdisk contents), type:

$ make bgp-cn-linux

Note: the newly built CN ramdisk can be found in ramdisk/CN/bgp-cn-ramdisk.cpio.gz, but it is not usable until it is embedded into the kernel image.

For other ramdisk-related make targets, please refer to Configuration.

Modifying ramdisk contents

You can customize ramdisk contents for your purpose, i.e., debugging, running your custom system software on BGP, etc.

CN ramdisk

The CN ramdisk can be customized by editing the CN ramdisk build script, which is ramdisk/CN/create-bgp-cn-linux-ramdisk.pl. The build script allows to set the permission bits, create device files, etc.

Most of the contents of the CN ramdisk is kept in ramdisk/CN/tree/, but this is not a hard rule. Source files can reside anywhere as long as they are accessible from the script. It may be possible to use binaries and libraries from the login nodes, as long as they are a 32-bit PPC files (use the file command to verify) and all their dependencies are also copied.

Here is a practical example. Suppose that you need the od command in CN ramdisk. You could build the command from source code, but if you want to do something quick, you can try using the login node's version:

$ file /usr/bin/od
/usr/bin/od: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1 (SYSV),
for GNU/Linux 2.6.4, dynamically linked (uses shared libs), for GNU/Linux 2.6.4, stripped
$ ldd /usr/bin/od
linux-vdso32.so.1 =>  (0x00100000)
libc.so.6 => /lib/ppc970/libc.so.6 (0x0fe8b000)
/lib/ld.so.1 (0xf7fe1000)

It is a 32-bit PPC executable and the current CN ramdisk has all the necessary shared libraries, so it can be used. Now add the command to a perl array named @cmdlists in ramdisk/CN/create-bgp-cn-linux-ramdisk.pl script and invoke make to recreate the CN ramdisk:

$ vi ramdisk/CN/create-bgp-cn-linux-ramdisk.pl
# add the following line to @cmdlists 
     "file /bin/od   /usr/bin/od 0755  0  0",
$ make bgp-cn-linux

Now the CN ramdisk has /bin/od with file permissions 0755, uid 0, and gid 0.

The added line is a command for the gen_init_cpio tool. One can also create directories, device files, symbolic links, named pipes, socket files, etc:

file <name> <location> <mode> <uid> <gid>
dir <name> <mode> <uid> <gid>
nod <name> <mode> <uid> <gid> <dev_type> <maj> <min>
slink <name> <target> <mode> <uid> <gid>
pipe <name> <mode> <uid> <gid>
sock <name> <mode> <uid> <gid>

<name>      name of the file/dir/nod/etc in the archive
<location>  location of the file in the current filesystem
<target>    link target
<mode>      mode/permissions of the file
<uid>       user id (0=root)
<gid>       group id (0=root)
<dev_type>  device type (b=block, c=character)
<maj>       major number of nod
<min>       minor number of nod

The order of the commands in @cmdlists matters. They are executed from top to bottom, so one cannot add a file to a directory that has not yet been created.

CN Linux startup script

The first thing that the Linux kernel does after it boots is to execute the init program. The init program is usually in /sbin/, and in the CN ramdisk case it is part of the busybox. init reads in a config file from /etc/inittab, which in our case instructs it to execute the /etc/init.d/rc.sysinit startup script.

Our startup script is very minimalistic; its two most important actions are to start the telnet daemon to allow users to login from the I/O nodes and then to start the ZOID control process which takes care of IP forwarding and job control.

In case you need to start some processes at the CN boot time, you can add their invocations to ramdisk/CN/tree/etc/init.d/rc.sysinit, before /sbin/control is invoked.

ION ramdisk

Unlike the CN ramdisk, the range of customization is limited on the ION ramdisk. There is no control over file permission bits, one cannot create device nodes, etc. Currently we build the ION ramdisk using IBM's build-ramdisk script by specifying an add-on tree which contains our extra files.

Essentially, customization is limited to:

  • adding new files,
  • overwriting default ramdisk files by adding custom files with the same names.

Once files have been added under ramdisk/ION/ramdisk-add/, they will be automatically added to the ramdisk on the next rebuild. Here is an example of how to add a file to the ION ramdisk:

$ vi ramdisk/ION/ramdisk-add/etc/yourfile
$ make bgp-ion-ramdisk-cnl

If you need more than file adding, you might need to edit the build-ramdisk script itself. The script is located in /bgsys/drivers/ppcfloor/. Copy the script to a working directory, edit it and change the script path in ramdisk/ION/Makefile.

ION startup script

There is no rc.sysinit in ramdisk/ION/ramdisk-add/, because rc.sysinit is provided in the IBM ramdisk tree (i.e., /bgsys/drivers/ppcfloor/ramdisk/etc/init.d/rc.sysinit is the default one). If needed, copy the default one to the ZeptoOS ramdisk/etc/init.d/rc.sysinit and modify it to change the startup behaviour, but this is in general not recommended.

In most cases, what one is looking for is to start a process at the ION boot time. For such purpose, one can add a custom ION RC script to ramdisk-add/etc/init.d/rc3.d/.

RC scripts have the following naming convention:

  • S##xxxx : boot-time scripts
  • K##xxxx : shut-down scripts

The script names start with S or K; those starting with S are the boot-time scripts and those starting with K are the shut-down scripts. The two-digit number following the S or K is used to determine the execution order; scripts with lower numbers are executed earlier. The number is followed by the script name. On execution, "start" is passed as the first argument to boot-time scripts, and "stop" to shut-down scripts, so the same script can be used for both purposes. Here is a template of an RC script:

#!/bin/sh
. /etc/rc.status

rc_reset
case "$1" in
    start)
        # fill here #
        ;;
    stop)
        # fill here #
        ;;
    restart)
        # fill here #
        ;;
    status)
        # fill here #
        ;;
    *)
	echo "Usage: $0 {start|stop|restart|status}"
	exit 1
	;;
esac
rc_exit

The ZeptoOS ION ramdisk contains the following RC scripts by default (some of these are ZeptoOS-specific, others come from the IBM ramdisk tree):

boot scripts:

S00zepto
S01bootsysctl
S02syslog
S05ntp
S11sshd
S12zepto
S40gpfs
S43ibmcmp
S46essl
S50ciod
S51zoid
S99zepto

shutdown scripts:

K05ntp
K10sshd
K15ciod
K20gpfs
K30syslog
K50bgsys.64

Ramdisk size limitation

In regular Linux environments, ramdisk size is limited by free memory size at the time when ramdisk is loaded into memory. However, on BGP, closed-source partition booting software cannot handle images of arbitrary sizes. We do not have an exact number on the boot image size limitation, but we have seen with the current software stack that images of 100 MB or larger might fail to boot. After adding large files to the ramdisk, please check the size of the generated image files, specifically BGP-ION-ramdisk-for-CNL.elf and BGP-CN-zImage-with-initrd.elf.

Extracting files from an existing ramdisk image

To extract files from an existing ramdisk image, do the following (ION ramdisk only):

$ ./packages/tools/z-extract-cpio-from-ramdisk.sh  <existing_ramdisk_image> ramdisk.cpio
$ mkdir treeroot && cd treeroot
$ cpio -idv < ../ramdisk.cpio

Kernel | Top | ZOID