Thursday, September 30, 2010

Success! Creating my own spec file for NLED

Success! 


I finally got around to finishing my own spec file for NLED. I can tell you this - I learned quite a lot going through each one of the errors and trying to research and fix it. I'll admit it was quite frustrating at first. Getting it to finally work was good, but the best part was gaining a MUCH better understanding of how the .spec file works.

The Fedora How to pointed me in all the right directions, and of course, can't forget man's new best friend - Google. I just needed to spend some time going through the sections and understand what each is supposed to do.

I will attach my RPM file here as well as the SPEC file for those of you who are interested. Please see below:

Spec file: http://asdesigned.ca/nled.spec
Please Right-click and use "Save as" to download the nled.spec file or just simply click on it to view it in the browser

RPM File: http://asdesigned.ca/nled-2.52-8.fc12.i686.rpm 


A Few Notes

  • NLED does not require any ./configure or make install commands, instead it is simply compiled using the make command, where it will create the nled binary that can be placed into /usr/bin/ and executed anywhere on the command line.
  • Therefore, you will have to remove the ./configure option from the %build section of the spec file and also remove the make install option from the %install section
  • I took a look at the original NLED Makefile and at the top it showed that the make options were CCOPTIONS=–O –c and LDOPTIONS=–lcurse

# AIX: CCOPTIONS=-qnoro -O -c
# some Linuxes: CCOPTIONS=-O -c -I /usr/include/ncurses
# other Linuxes (try this first):
CCOPTIONS=-O -c

# AIX: LDOPTIONS=-lcurses
# some Linuxes: LDOPTIONS=-lncurses
# other Linuxes:
LDOPTIONS=-lcurses
So I added to the %build section:   
make %{?_smp_mflags} CCOPTIONS="-O -c" LDOPTIONS="-lcurses"
  • Next, the installation needs to be done "by hand" and the files need to be copied to the correct locations. Therefore, we need to create the directories (using mkdir -p) and then copy the files from inside the build directory to the buildroot directory (using cp -p). So following the Fedora How To resource, I added:
%install 
rm -rf %{buildroot} 
mkdir -p %{buildroot}%{_bindir}/ 
cp -p nled %{buildroot}%{_bindir}/
  •  After doing that, I got an error when running rpmbuild:
error: Installed (but unpackaged) file(s) found:
       /usr/bin/nled
This just means that I did not count those files under the %files section, as the %files section identifies what files and directories were added by the package - and thus, which files and directories are owned by the package.

To fix it, I just needed to add %{_bindir}/* under the %files section, and the rest is history.

Wednesday, September 29, 2010

Revisited: Testing RPM build times - Part 1

In my last post, Testing RPM Build times, I had used different -j values in the ~/.rpmmacros file to find the best value that resulted in the fastest build time for NLED, which is a very small package and the build time was relatively fast at around 6 seconds. However, after reading Chris Tyler's email today and chatting with him on IRC (irc.freenode.net, #seneca channel), it came to my attention that
"most of that time is spent in unpacking the tarball and packing the RPMs, which are unaffected by the -j value"
In addition, Chris informed us of a build log file that contained a list of packages and build times that we could use to find a solid package to rebuild and test the -j value properly. This file can be found at http://scotland.proximity.on.ca/sbr600/buildall.log

Therefore, I am rebuilding SNORT, which I had compiled from source here, to finally get the proper results of the -j values.

Oh and lucky me! According to the build log file, SNORT typically takes approximately 433 seconds to build!

Regardless, I am using a script to let it run overnight and I will post the results tomorrow evening.

Friday, September 24, 2010

Testing RPM build times

The rpmmacros file
This week we were experimenting with the rpmbuild macros configuration file: ~/.rpmmacros.
The –j value of the smp_mflags in the ~/.rpmmacros file controls how many simultaneous jobs make starts and thus we can change it to see which value would give us the fastest build time.

The Setup
For the first test, I used my laptop, which is running Fedora12 in an Oracle VM VirtualBox virtual machine with 1GB of RAM allocated.
My laptop specifications are shown below:
CPU: Intel Core 2 Duo Mobile T5800 @ 2.00GHz
Ram: 4.00 GB

The package I chose to build was NLED.

The Test
The following command was used to gather the results: 
time rpmbuild -ba nled.spec

The Results
Values: -j1, -j3 (default), -j4, -j5
This resulted in an elapsed time of 15.8 seconds. Keeping in mind that this test is on Fedora running in a virtual machine, I ran it again. This time the result was16.9 seconds which I attributed to factors such as the CPU being used for other processes on the host machine. Values 1, 4 and yielded similar results of times between 15.8 - 16.9 seconds and value 5 yielded close to 18 seconds.

Best Value: -j2
However, using a value of j2 yielded an elapsed build time of 14.3 seconds, so it seems that this is the optimal value to use, at least in a virtual machine.

I re-did the test a second time after restarting the machine, and all the times dropped about 40% for each of the respective values!


Unsatisfied
I couldn't just have my cake and eat it too. I wanted seconds. So I pulled out the big guns and used my desktop with Fedora 13 installed.

The Setup Revisited
CPU:   Intel i7 920 Overclocked
Ram:   6GB

The Results Revisited
Blazing. 
No, really. The best value was a -j4 which yielded 3 seconds to build NLED.


I would definitely say that the benefits of changing the -j values of the smp_mflags would be more noticeable when compiling larger builds, but it was still interesting to test out the build times.

A Prequel: Rebuilding an Existing Fedora SRPM

Rebuilding an Existing Fedora SRPM:
I chose to rebuild the NLED package on my machine which was quite simple.

Steps:
  1. Install the necessary packages: rpm-build, rpmdevtools, rpmlint, yum-utils 
  2. Setup your system, see here
  3. Download the source file wget http://cdot.senecac.on.ca/software/nled/nled_2_52_src.tgz
  4. Install it, rpm -ivh nled_2_52_src.tgz
  5. Go in the: cd ~/rpmbuild/SPECS directory
  6. Run the command rpmbuild -ba packagename.spec
The .spec file was fairly straightforward. This took about 15 seconds to complete (also see Testing Build Times), and was done without breaking a sweat - unlike the next section below.


Creating my own .spec file
In the second week of the course, I had built Snort from source using ./configure, make and make install, which can be found here.

A few nights ago, I tried building my own spec file for Snort but ran into a few problems. Thus I took a look at the original Snort spec file after installing the source (To see how, click here), and it was filled with information that I am unfamiliar with (for nowcan’t emphasize that enoughfor now). However, I did take some time to go over it to try to understand out what each line was doing.

Next, I figured I can write my own (much) simpler snort spec file and get it to build into an rpm package – but I’ll do that at a later time. Since this was my first attempt at creating my own spec file, I wanted to try something much easier at first and get practice, understand it more.

I will post my experience of creating my rpm build via a spec file in the coming days along with a link to download the respective spec file, source and package for your perusal or curiosity.

Heck, I’m still going through SourceForge looking at all the goodies available.

Sunday, September 12, 2010

Compiling NLED and Snort from source


The instructions were to build two software packages from their source files, of which one must be NLED and any other software of your choice.

First let’s begin wiith NLED:

Compiling NLED from Source

Download and extract the Tarball:

$ wget http://cdot.senecac.on.ca/software/nled/nled_2_52_src.tgz
$ tar -xvz nled_2_52_src.tgz

Next, run make and make install to compile and install:
$ make
$ make install

Incidentally, this installation ran without issues and I am successfully using NLED.


For the second software, I decided to install Snort
"Snort® is an open source network intrusion prevention and detection system (IDS/IPS) developed by Sourcefire. Combining the benefits of signature, protocol and anomaly-based inspection, Snort is the most widely deployed IDS/IPS technology worldwide."


Compiling Snort from Source


You can download the Source snort package from:


Untar the Source file:
$ tar -xvf snort-2.8.6.1.tar.gz
$ cd snort-2.8.6.1/


The Snort website (www.snort.org) showed that before installing Snort you need have a number of software packages installed such as Libpcap, PCRE, Libnet and Barnyard.

I ran the following commands to see if these packages are installed:
rpm -q libpcap               - Yes, installed
rpm -q pcre                      - Yes, installed
rpm -q libnet                 - No, not installed (or at least rpm did not find it)
rpm -q barnyard            - No, not installed (or at least rpm did not find it)

However, I decided to run the configure file to see what would happen.

$ ./configure

But alas, I got the following error:
Snort Error:

   ERROR!  Libpcap library/headers (libpcap.a (or .so)/pcap.h)not found, go get it from http://www.tcpdump.org  or use the --with-libpcap-* options, if you have it installed in unusual place.  Also check if your libpcap depends on another shared library that may be installed in an unusual place


But wait, the latest lipbcap package WAS installed according to rpm (as I had run rpm –q libpcap above).
Perhaps, I was missing something else. I checked the www.tcpdump.org website but it had the same libcap I had installed. I ran the command:

$ yum search libpcap

Loaded plugins: presto, refresh-packagekit
=================Matched: libpcap ================= libpcap.i686 : A system-independent interface for user-level packet capture
libpcap-devel.i686 : Libraries and header files for the libpcap library

Since libpcap was installed, I figured I needed the development libpcap library as well so I installed it using:

$ yum install libpcap-devel


Then I ran ./configure again, as it was going through I noticed:

./configure: line 13616: pcre-config: command not found
./configure: line 13622: pcre-config: command not found
checking pcre.h usability... no
checking pcre.h presence... no
checking for pcre.h... no


I knew what was coming and then BAM! Another error: 
ERROR!  Libpcre header not found. 


So I checked www.pcre.org and found the same pcre library I have installed already. Now I know there must be a pcre development library like libpcap so I ran yum search pcre and it came back with:
Loaded plugins: presto, refresh-packagekit
==========Matched: pcre ============
pcre.i686 : Perl-compatible regular expression library
pcre-devel.i686 : Development files for pcre
Of course, I then ran yum install prce-devel


Finally, I ran ./configure again, and voila! It completed (although I didn’t seem to have barnyard or libnet according to rpm –q)


If you need to run ./configure with special options, then please see this resource I found on the configuration options you can use:
http://204.152.191.100:8080/wiki/index.php/Configure_options_-_snort


Next I ran make as my current user, followed by make install as root

Snort is successfully installed. Time to start snortin’…or not (insert fail comment here).

Friday, September 10, 2010

SBR600 Communication Lab

Hello,
My name is Andrew Singh. I am currently a 6th (and final) semester student at Seneca College in the Computer Systems Technology course. I plan to graduate with high honours so here's to the start of another to-be-great semester (and with that: raises a glass of beer)!

This blog was created for two purposes:
  1. For my current Software Build and Release course SBR600, and
  2. as a blog for my web and graphic designs.

A few thing about me:
  • I love programming (PERL, PHP and learning JavaScript and AJAX. I am willing to learn any programming language!) 
  • My flavour of Linux would definitely be Fedora
  • I create web and graphic designs, currently for my (own) company ASDesigned (Site will be up shortly)