Difference between revisions of "Ramdisk"

From ZeptoOS
Jump to navigationJump to search
Line 4: Line 4:
 
==Introduction==
 
==Introduction==
  
Both CN Linux kernel and ION Linux kernel requires ramdisk to
+
Both the CN and 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.
boot.  Ramdisk images basically contain minimum Linux utilities, init
 
scripts , configuration files, kernel modules, etc, which are required
 
by OS boot process.
 
  
ION ramdisk is an ELF file that contains a cpio format archive of
+
ION ramdisk is an ELF file that contains a cpio archive of system files. Two ION ramdisk images are currently generated:
system files. Two ION ramdisk images are currently generated.
 
  
* BGP-ION-ramdisk-for-CNL.elf
+
; BGP-ION-ramdisk-for-CNL.elf
** Default ION ramdisk for ZeptoOS
+
: Default ION ramdisk for ZeptoOS.
* BGP-ION-ramdisk-for-CNK.elf  
+
; BGP-ION-ramdisk-for-CNK.elf  
** Use this one if you need to run IBM CNK on Compute node
+
: Use this one if you need to run IBM CNK on the compute nodes (uses IBM CIOD instead of ZOID)
** IBM CIOD is used instead of ZOID
 
  
Our ION ramdisks are similar to IBM default ION ramdisk but we add some
+
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 <tt>ramdisk/ION/ramdisk-add/</tt>. The <tt>build-ramdisk</tt> script from IBM BGP driver is used to create the ION ramdisks.
extra files to support our features. The extra files are located in
 
ramdisk/ION/ramdisk-add. The build-ramdisk script from IBM BGP driver is used to create
 
ION ramdisk. The default path of the build-ramdisk script is
 
/bgsys/drivers/ppcfloor. The build-ramdisk script path can be
 
configured by the main configure script.
 
  
CN ramdisk is also a gzip'ed cpio format archive of system files, but
+
The CN ramdisk is also a gzip'ed cpio archive of system files, but CN ramdisk is embedded into the CN kernel image (<tt>BGP-CN-zImage-with-initrd.elf</tt>).  The CN ramdisk is created by a custom ramdisk build script (<tt>ramdisk/CN/create-bgp-cn-linux-ramdisk.pl</tt>). Both <tt>build-ramdisk</tt> and <tt>create-bgp-cn-linux-ramdisk.pl</tt> are wrappers of the Linux kernel's <tt>gen_init_cpio</tt> command.
CN ramdisk is embedded into CN kernel
 
image(BGP-CN-zImage-with-initrd.elf).  CN ramdisk is created by our
 
local ramdisk build script( ramdisk/CN/create-bgp-cn-linux-ramdisk.pl
 
). Both build-ramdisk and create-bgp-cn-linux-ramdisk.pl is a wrapper script of the  
 
Linux kernel's gen_init_cpio command.
 
  
==How to create ramdisk images==
+
==Creating ramdisk images==
  
CN kernel image, ION kernel image and ION ramdisk images are always (re-)created from prebuild
+
The ramdisk images are always (re-)created from prebuild objects if one types <tt>make</tt> at the top level directory (without any make target).
objects if you type make at the top level directory (without any make target),
+
 
 +
If one wants to create an ION ramdisk individually (without rebuilding other images), type:
  
In case you actually need to create ION ramdisk individually (without rebuilding other images),
 
you can do:
 
 
<pre>
 
<pre>
 
$ make bgp-ion-ramdisk-cnl
 
$ make bgp-ion-ramdisk-cnl
 
</pre>
 
</pre>
  
If you want to create CN ramdisk(technically create CN kernel image
+
If one wants to create a CN ramdisk (technically, create a CN kernel image with new ramdisk contents), type:
with new ramdisk contents), type:
 
  
 
<pre>
 
<pre>
Line 50: Line 33:
 
</pre>
 
</pre>
  
NOTE: ramdisk/CN/bgp-cn-ramdisk.cpio.gz is a newly built CN ramdisk.
+
'''Note:''' the newly built CN ramdisk can be found in <tt>ramdisk/CN/bgp-cn-ramdisk.cpio.gz</tt>, but it is not useable until it is embedded into the kernel image.
 +
 
 +
For other ramdisk-related make targets, please refer to [[Configuration#Building|Configuration]].
  
==How to modify ramdisk contents==
+
==Modifying ramdisk contents==
  
You can customize ramdisk contents for your purpose, i.e., debugging,  
+
You can customize ramdisk contents for your purpose, i.e., debugging, running your custom system software on BGP, etc.
running your system software to BGP.
 
  
 
===CN ramdisk===
 
===CN ramdisk===
  
You can customize CN ramdisk by editing our CN ramdisk build script, which is
+
The CN ramdisk can be customized by editing the CN ramdisk build script, which is <tt>ramdisk/CN/create-bgp-cn-linux-ramdisk.pl</tt>The build script allows to set the permission bits, create device files, etc.
ramdisk/CN/create-bgp-cn-linux-ramdisk.pl.   
 
You can add files with permission, delete files, creating device files, etc.
 
  
While we keep our CN ramdisk contents in ramdisk/CN/tree, you can add any file to the ramdisk as long as they are accessible from the script. You may be able to add login node's executables if they are a 32-bit PPC binaries and you copy all required files such as shared libraries, config files, etc.
+
Most of the contents of the CN ramdisk is kept in <tt>ramdisk/CN/tree/<tt>, 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 <tt>file</tt> command to verify) and all their dependencies are also copied.
  
Here is an useful example. Supposed that you need the od command in CN ramdisk.
+
Here is a practical example. Suppose that you need the <tt>od</tt> 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:
You can build the od command from source code from source code for CN ramdisk.
 
If you want to do something quick, you can check see if login node's od command works or not.
 
  
 
<pre>
 
<pre>
 
$ file /usr/bin/od
 
$ file /usr/bin/od
/usr/bin/od: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1 (SYSV),  
+
/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
 
for GNU/Linux 2.6.4, dynamically linked (uses shared libs), for GNU/Linux 2.6.4, stripped
 
$ ldd /usr/bin/od
 
$ ldd /usr/bin/od
Line 79: Line 59:
 
</pre>
 
</pre>
  
It is a 32-bit PPC executable and the current CN ramdisk has all necessary shared libraries, so you simply can use login node's od command.
+
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 <tt>@cmdlists</tt> in <tt>ramdisk/CN/create-bgp-cn-linux-ramdisk.pl</tt> script and type <tt>make</tt> to recreate the CN ramdisk:
What you need to do is to add one command to a perl array named @cmdlists in ramdisk/CN/create-bgp-cn-linux-ramdisk.pl
 
and type make to recreate the CN ramdisk.
 
  
 
<pre>
 
<pre>
$ vi ramdisk/CN/create-bgp-cn-linux-ramdisk.pl # the following line to @cmdlists  
+
$ vi ramdisk/CN/create-bgp-cn-linux-ramdisk.pl
 +
# add the following line to @cmdlists  
 
     "file /bin/od  /usr/bin/od 0755  0  0",
 
     "file /bin/od  /usr/bin/od 0755  0  0",
 
$ make bgp-cn-linux
 
$ make bgp-cn-linux
 
</pre>
 
</pre>
  
Now the CN ramdisk has /bin/od with file permission 0755, uid=0 and gid=0.
+
Now the CN ramdisk has <tt>/bin/od</tt> with file permissions <tt>0755</tt>, uid=0, and gid=0.
  
The line that you added is a gen_init_cpio command. You can also
+
The added line is a command for the <tt>gen_init_cpio</tt> tool. One can also create directories, device files, symbolick links, pipe files, socket files, etc:
create a directory, device file, symbolick link, pipe file, socket
 
file as well.
 
  
 
<pre>
 
<pre>
Line 114: Line 91:
 
</pre>
 
</pre>
  
The order of the gen_init_cpio commands in @cmdlists is matter.They are interpreted and executed from top to bottom.
+
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.
You can't add a file to the directory that has not been created.
 
  
 
====CN Linux startup script====
 
====CN Linux startup script====
  
The first thing that Linux kernel does after kernel successfully boots
+
The first thing that the Linux kernel does after it boots is to execute the <tt>init</tt> program. The <tt>init</tt> program is usually in <tt>/sbin/</tt>, and in the CN ramdisk case it is part of the busybox. <tt>init</tt> reads in a config file from <tt>/etc/inittab</tt>, which in our case instructs it to execute the <tt>/etc/init.d/rc.sysinit</tt> startup script.
is to execute an executable called the init program.
 
The init program is usually /sbin/init that is internally busybox.  
 
Then /sbin/init executes a startup script defined in /etc/inittab,
 
which is /etc/init.d/rc.sysinit.
 
  
Our startup script is a very small shell script and do minimum setup, starts telnetd to allow users to login from ION and
+
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 <tt>control</tt> process which takes care of IP forwarding and job control.
starts the Zoid control process which takes care of job control.
 
  
In case you need to start your software at CN boot time,  
+
In case you need to start some process at the CN boot time, you can add its invocations to <tt>ramdisk/CN/tree/etc/init.d/rc.sysinit</tt>, ''before'' <tt>/sbin/control</tt> is invoked.
you can add command invocations to ramdisk/CN/tree/etc/init.d/rc.sysinit.
 
  
 
===ION ramdisk===
 
===ION ramdisk===
  
Unlike CN ramdisk, the range of customization is limited on ION ramdisk.
+
Unlike with 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 <tt>build-ramdisk</tt> script by specifying an add-on tree which contains our extra files.
You have no permission control. You can't create device nodes, etc.
 
Currently we build the ION ramdisk using IBM build-ramdisk script by specifying  
 
add-on tree which contains our extra files.
 
  
 
What you can do are basically:
 
What you can do are basically:
* Add files
+
* add files,
* Overwrite files that are in the ramdisk created by build-ramdisk
+
* overwrite default ramdisk files by adding custom files with the same names.
  
Once you add files under ramdisk/ION/ramdisk-add/, they will be automatically added to the ramdisk.  
+
Once files have been added under <tt>ramdisk/ION/ramdisk-add/</tt>, 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:
Here is an example to add a file to the ION ramdisk.
 
  
 
<pre>
 
<pre>
Line 150: Line 116:
 
</pre>
 
</pre>
  
If you need more than file adding, you might need to edit the build-ramdisk script itself.
+
If you need more than file adding, you might need to edit the <tt>build-ramdisk</tt> script itself. The script is located in <tt>/bgsys/drivers/ppcfloor/</tt>. Copy the script to your working directory, edit it and change the script path in <tt>ramdisk/ION/Makefile</tt>.
The script's default location is /bgsys/drivers/ppcfloor/build-ramdisk. Copy  
 
the script to your working directory, edit it and change the script path in ramdisk/ION/Makefile.
 
  
 
====ION startup script====
 
====ION startup script====
Line 243: Line 207:
 
specifically, BGP-ION-ramdisk-for-CNL.elf and BGP-CN-zImage-with-initrd.elf.
 
specifically, BGP-ION-ramdisk-for-CNL.elf and BGP-CN-zImage-with-initrd.elf.
  
==How to extract files from existing ramdisk image==
+
==Extracting files from an existing ramdisk image==
  
If you want to extract file from existing ramdisk image, do the
+
To extract file from an existing ramdisk image, do the following (ION ramdisk only):
following steps (ION ramdisk only).
 
  
 
<pre>
 
<pre>
$ ./packages/tools/z-extract-cpio-from-ramdisk.sh  existingramdisk.elf  ramdisk.cpio
+
$ ./packages/tools/z-extract-cpio-from-ramdisk.sh  <existing_ramdisk_image> ramdisk.cpio
 
$ mkdir treeroot && cd treeroot
 
$ mkdir treeroot && cd treeroot
 
$ cpio -idv < ../ramdisk.cpio
 
$ cpio -idv < ../ramdisk.cpio

Revision as of 16:07, 6 May 2009

Kernel | Top | ZOID


Introduction

Both the CN and 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.
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 of the Linux kernel's gen_init_cpio command.

Creating ramdisk images

The ramdisk images are always (re-)created from prebuild 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 useable 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 type 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, symbolick links, pipe files, 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 process at the CN boot time, you can add its invocations to ramdisk/CN/tree/etc/init.d/rc.sysinit, before /sbin/control is invoked.

ION ramdisk

Unlike with 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.

What you can do are basically:

  • add files,
  • overwrite 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 your 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/ since rc.sysinit is provided from IBM ramdisk tree. i.e., /bgsys/drivers/ppcfloor/ramdisk/etc/init.d/rc.sysinit is default one. You can copy the default one to ramdisk/etc/init.d/rc.sysinit (local) and modify it to change the startup behaviour but it is not recommended.

In most cases, what you need is to start your software at ION boot time. For such purpose, you can add your ION RC script to ramdisk-add/etc/init.d/rc3.d to do some action.

RC script has own naming convention.

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

It starts with S or K. Scritps with S are boot time script and scripts with K are shut down scripts. A two-digit number is followed by 'S' or 'K' is used to decide execution order ; a smaller number script is executed before a larger number script. Then script name follows. The init scripts passes "start" as the 1st argument to boot time scripts when it is executed. Similarly, "stop" is passed to shut down script. If you parse the argument, one rc script can serve as both boot time and shut down script. Here is a template of 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


Default Zepto ION ramdisk contains the following rc scripts.

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

On regular Linux environment, ramdisk size is basically limited by free memory size at the time when ramdisk is loaded into memory. However, on BGP, the system software(non-opensource) can not handle bigger image. We don't have the exact number on the boot image size limitation but 100MB or bigger ramdisk might fail to boot with the current environment. If you add bigger files to ramdisk, please make sure the ramdisk file size, specifically, BGP-ION-ramdisk-for-CNL.elf and BGP-CN-zImage-with-initrd.elf.

Extracting files from an existing ramdisk image

To extract file 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