Friday, February 22, 2008

Open-Solaris Kernel Building and Installation

HOW TO Build and Install Open-Solaris Kernel
====================================
First clear some idea about Solaris and Open-Solaris.
Solaris: Solaris is based on Open -Solaris, and the other parts that have not been yet open sourced.
No full Solaris release based on Open -Solaris available yet.
The next Solaris release (currently codenamed “Nevada”) will be the first release based on Open- Solaris.

Prerequisite:
i-386 Solaris Machine,Compiler Toolchain.
Here I will discuss for x86 machine,but its same for the SPARC and AMD64.

Following are the steps to Build and Install Open-Solaris Kernel:
----------------------------------------------------------------------------

STEP 1: Download the Source code from opensolaris.org
if any one already have the following tar file please skip this step

Tools needed to build Open-Solaris are following:
1. Sun Studio 10 or Sun Studio 11 (compiler),named:
sunstudio10-ii-20050912-sol-x86.tar.bz2
2. ON-specific build tools(SUNWonbld),named:
on-closed-bins-DATE.PLATFORM.tar.bz2
example: SUNWonbld-b47.i386.tar.bz2
3. The Closed Binaries?OS/Networking (ON) Components, named:
on-closed-bins-DATE.PLATFORM.tar.bz2
Example: on-closed-bins-b47.i386.tar

Open -Solaris Source code(onsrc) :
* The Source. For build-synchronized deliveries, you can download a source tarball named:
on-src-DATE.tar.bz2
example:on-src-b47.tar.bz2

Download the above tar files from opensolaris.org in the /var/tmp area,this is used to avoid using space in the working directories.
Following are two link which directed from opensolaris.org to download the above tar files.
http://dlc.sun.com/osol/on/downloads/
This contains a list of archive date wise and b47,b60 etc
http://dlc.sun.com/osol/on/downloads/current/
This contains the latest (current date)source code for download.

Now install all the above one by one:

Untar and Install Sun Studio Compiler:
# cd /opt
# bzip2 -dc /var/tmp/sunstudio10-ii-20050912-sol-x86.tar.bz2(if you have cop)
# tar xvf /var/tmp/sunstudio10-ii-20050912-sol-x86.tar -C .
You will see two directories to be built in the /opt directory
1. netbeans
2. SUNWspro

Untar and Install SUNWonbld:
# bzip2 -d SUNWonbld-b47.i386.tar.bz2
(You will get SUNWonbld-b47.i386.tar file as the result of above)

# tar xvf SUNWonbld-b47.i386.tar -C .
# su (if you haven’t logged in as root)
Password:
# pkgadd -d onbld SUNWonbld
Note that if you have installed a previous version of the tools, you will need to use pkgrm(1m)
to remove them first.


Untar and Install The Closed Binaries?OS/Networking (ON) Components:
Make a work space for you named as : /export/home/open_solaris
$ mkdir /export/home/open_solaris
$cd /export/home/open_solaris
$ bzip2 -d on-closed-bins-b47.i386.tar.bz2
You will get the file on-closed-bins-b47.i386.tar
$ tar xvf on-closed-bins-b47.i386.tar -C .
This operation will create a directory closed inside /export/home/open_solaris/


Untar Open-Solaris Source code(onsrc):
$cd /export/home/open_solaris
$bzip2 -d on-src-b47.tar.bz2
$tar xvf on-src-b47.tar -C .
The sources will unpack into:
/export/home/open_solaris/usr/src



STEP 2: Setting your environment
------------------------------------------
1. cd /export/home/open_solaris
2. cp usr/src/tools/env/opensolaris.sh .
3. edit opensolaris.sh
4. set GATE to open_solaris
5. set CODEMGR_WS to /export/home/open_solaris
6. set STAFFER to your login
7. set VERSION to whatever you want to call it

Step 3 . Kernel Building
-----------------------------
There are two steps to build Open-Solaris:

1.The nightly script is used to perform the actual build (note that nightly builds everything, not just the kernel):
to build the entire ON tree run nightly:
$cd /export/home/open_solaris
$nightly ./opensolaris.sh &

This will take some time so take rest for some hour with a cup of tea or coffee .

The log file is also available (in a slightly different location) during the build; to monitor the progress of
your build in real time, you can do:

$ tail -f /export/home/open_solaris/log/nightly.log

The location of the log is controlled by the LOGFILE and ATLOG variables; see nightly(1) for more details.
If your build fails, you can correct the problem, then use the '-i' option to nightly to run an incremental build,
bypassing the initial clobber. See the nightly(1) manual and Building OpenSolaris for more information on opensolaris.org
http://www.opensolaris.org/os/community/on/devref_toc/devref_4/


2.OR make the kernel manually by dmake as following:
The first thing we need to do is make sure that all the required environment variables are set to the correct values,by running the bldenv script:
1. bldenv -d ./opensolaris.sh
2. cd /usr/src/uts
3. dmake all

Because we didn't do nightly ./opensolaris & before, /src/tools/proto isn't built.
So just go there and build it.
Building the tools
1. cd /usr/src/tools
2. dmake all
this makes proto dir in tools


Step 3: Booting new kernel
--------------------------------
1. cd usr/src/uts
2. Install -G myos.kernel -k i86pc
Example :
bash-3.00# Install -G myos.kernel -k i86pc
WARNING: kmdb isn't built, and won't be included
Creating tarfile /tmp/Install.root/Install.i86pc.tar

3. su (if not root login)
4. cd /
5. tar xf /tmp/Install.root/Install.i86pc.tar .
6. vi /boot/solaris/filelist.ramdisk
add platform/i86pc/myos.kernel to the end of file

7. vi /boot/grub/menu.lst
add an entry pointing kernel to myos.kernel
platform/i86pc/myos.kernel
Example:
#--------------------------------
title my_open_solaris
kernel /platform/i86pc/myos.kernel
module /platform/i86pc/boot_archive
#-----------------------------------
You can skip this step if you wants to reboot the kernel directly from command line(Please see following 8th step )

8. reboot using following commands if you have changed menu.list in the above 7th step
$reboot

if you have not changed menu.list in the above 7th step,fire following command for booting new x86 kernel:
$reboot -- 'myos.kernel/unix'

Note that you will need to use either this reboot syntax (reboot -- 'myos.kernel/unix' ) each time you wish to boot the test kernel, or use similar arguments to the bootloader(7 point) or OBP. Otherwise, the normal kernel installed by BFU or the regular installation will be booted.

First steps towards kernel development:
1. vi/usr/src/uts/common/main.c
2. add printf("Hello Kernel World!\n"); in main()[in the middle of the main() code]
3. recompile, install and reboot.

To build a specific component
------------------------------------
To build a specific component, first use bldenv(1) to set up various environment variables,
then cd to the subtree that you want to build. For example to build the sgs:
$ cd /export/home/open_solaris/
$ bldenv ./opensolaris.sh
[status information from bldenv]
$ cd /export/home/open_solaris/usr/src/cmd/sgs
$ dmake all




In short story we can say that following are the steps to recompile, build and intall new kernel
------------------------------------------------------------------------------------------------

1. Obtain the source code, closed binaries, compilers and build tools from www.opensolaris.org or one of its mirrors.
2. Install the ON build tools and Sun Studio compilers into /opt and add their directories to our PATH.
3. Unpack the source and closed binaries tar balls.
4. Copy and edit the opensolaris.sh script.
5. Build the source code using the nightly script or using dmake in usr/src/uts
6. Install the resulting new kernel using the Install script.
7. Reboot using the new kernel.

For more information please visit the following sites
http://www.opensolaris.org
http://www.opensolaris.org/os/community/on/devref_toc/devref_4/

That all from my side.Thanks for reading this article.
Happy Kernel Building and Have a nice Day.

No comments: