Search This Blog

Friday, June 20, 2008

Linux From Scratch

What is Linux From Scratch?

Linux From Scratch (LFS) is a project that provides you with step-by-step instructions for building your own customized Linux system entirely from source.

Why would I want an LFS system?

Many wonder why they should go through the hassle of building a Linux system from scratch when they could just download an existing Linux distribution. However, there are several benefits of building LFS. Consider the following:

LFS teaches people how a Linux system works internally
Building LFS teaches you about all that makes Linux tick, how things work together and depend on each other. And most importantly, how to customize it to your own tastes and needs.

Building LFS produces a very compact Linux system
When you install a regular distribution, you often end up installing a lot of programs that you would probably never use. They're just sitting there taking up (precious) disk space. It's not hard to get an LFS system installed under 100 MB. Does that still sound like a lot? A few of us have been working on creating a very small embedded LFS system. We installed a system that was just enough to run the Apache web server; total disk space usage was approximately 8 MB. With further stripping, that can be brought down to 5 MB or less. Try that with a regular distribution.

LFS is extremely flexible
Building LFS could be compared to a finished house. LFS will give you the skeleton of a house, but it's up to you to install plumbing, electrical outlets, kitchen, bath, wallpaper, etc. You have the ability to turn it into whatever type of system you need it to be, customized completely for you.

LFS offers you added security
You will compile the entire system from source, thus allowing you to audit everything, if you wish to do so, and apply all the security patches you want or need to apply. You don't have to wait for someone else to provide a new binary package that (hopefully) fixes a security hole. Often, you never truly know whether a security hole is fixed or not unless you do it yourself.

What can I do with my LFS system?

A by-the-book LFS system is fairly minimal, but is designed to provide a strong base on which you can add any packages you want. See the BLFS project for a selection of commonly used packages.

Who's who:

  • Project Leader: Gerard Beekmans
  • Project Co-leader: Matthew Burgess
  • Editor: Jeremy Huntwork
  • Editor: Ken Moffat
  • Editor: Dan Nicholson
  • Editor: Bryan Kadzban
  • Editor: Alexander Patrakov
  • XML/XSL Editor: Manuel Canales Esparcia
  • Plus numerous people who contribute to the book and its side projects.

Linux From Scratch

Welcome to Linux From Scratch!

Linux From Scratch (LFS) is a project that provides you with step-by-step instructions for building your own custom Linux system, entirely from source code.

Currently, the Linux From Scratch organization consists of the following subprojects:

  • LFS :: Linux From Scratch is the main book, the base from which all other projects are derived.
  • BLFS :: Beyond Linux From Scratch helps you extend your finished LFS installation into a more customized and usable system.
  • ALFS :: Automated Linux From Scratch provides tools for automating and managing LFS and BLFS builds.
  • CLFS :: Cross Linux From Scratch provides the means to cross-compile an LFS system on many types of systems.
  • HLFS :: Hardened Linux From Scratch focuses on building an LFS system with heightened security.
  • Hints :: The Hints project is a collection of documents that explain how to enhance your LFS system in ways that are not included in the LFS or BLFS books.
  • LiveCD :: The LiveCD project provides a CD that is useful as an LFS build host or as a general rescue CD.
  • Patches :: The Patches project serves as a central repository for all patches useful to an LFS user.

Good Article About Linux

The Best Linux Distribution of them all A few weeks back, my friend Tom asked me a question regarding Linux - that is - Which is the best Linux distribution of them all. And following is the lively conversation we had about this topic which I am sharing with you. Tom: Ravi, There is a lot of talk going on about Linux which I have read in websites, newspapers and articles in magazines. I am aware of quite a few names floating around like debian, ubuntu, fedora and so on. Which Linux distribution according to you would be the best one around ? Me: Tom, you have asked a really simple question which has no single/simple answer. But I will try and explain it as best as I can. You should know that Linux is just a kernel. When all the necessary tools like the word processors, image editors, compilers and likes are added so that they seamlessly work on top of the Linux kernel, it becomes a distribution. I need not tell you that different people have different likes and dislikes. With respect to computers and OSes too this holds true. The versatility of Linux is that there is a Linux distribution which commits to cater to individual likes. Tom: I didn't get you. Could you explain it a little bit more clearly ? Me: Sure. You see, people can be categorised according to their tastes in computing. For example, one person may be newbie who is just getting introduced to computers who expects some hand holding. Another may be a Linux Guru who likes to do all his work using command line utilities. The beauty of Linux (or should I say the GNU movement) is that there is a distribution tailor made for each of these people. Tom: So you are saying that the correct answer to my question is that it depends on the individual. Right? Me: You are bang on target when you say that. :) Lets look at a few scenarios. Suppose you are a student of computer science. Your main motive in installing Linux on your machine would be to study the inner working of the OS. About what happens under the hood of the OS so to speak. A person with such an inclination will find it ideal to build your own Linux distribution compiling from source. In fact, there is a project called Linux From Scratch which precisely lets one build a Linux distribution grounds up. Another distribution which caters to this segment of people could be Gentoo. Tom: Well not all people are computer science students. How about a newbie like me ? Me: For new users like you (and there are quite a lot of them too), there are Linux distributions which come bundled with nice GUI front-ends which makes your Linux experience really enjoyable. But before we go into it, I would like to say something. Linux distributions can be broadly classified according to the package management they support. Package manager is a program similar to a setup installer in windows. There are two main players in this arena. One is deb package, the other being rpm (short for Redhat Package Manager). Most Linux distributions follow one or the other of the above said package format to install applications. For example, Linux distributions like Debian and Ubuntu follow the 'deb' package format where as Redhat, Mandriva, SuSe and the likes follow the 'rpm' format. Coming back to your question, a newbie will feel right at home in installing and using any of the distributions like Ubuntu, Fedora, Debian and so on. But there is an important factor. Because of licensing restrictions, these distributions exclude support for popular file formats like Mp3, Quicktime, wmv (windows media player), viewing encrypted DVDs and so on. Tom: What? You mean, I would not be able to play my favourite mp3 music on these distributions ? Me: Not at all. All I implied was that you have to download the codecs and install it by yourselves if you want the support for these file formats. For example, I use a versatile media player called mplayer to view all my mp3 audio and video. And it works flawlessly. Tom: Is there a distribution that has these codecs installed by default ? Me: Of course there are. For example, distributions like Linspire and Xandros comes with support for these formats. But you will have to shell out some money and buy first in order to use them. Tom: What if I wanted to use Linux as a server ? Me: If you are exclusively using Linux on the server side, then the GUI will lose its significance. You will be better off trying Debian. This Linux distribution gives stress on security and is considered to enjoy a large share of the Linux server market. Of course, you can also try RedHat or SuSe for the same. But the situation at your work place also play an important role in selecting a distribution for the server. Did you know, Debian is the only Linux distribution that supports architectures other than x86/IA32, Intel 64 bit, AMD 64 bit and PowerPC ? More over, Debian is not controlled by any corporation or single entity and it is maintained exclusively through donations and volunteer support. Tom: Ravi, you know Manish, my friend from school days ? He tried installing SuSe on a Pentium II machine with 32 MB RAM. And he said that he ran into problems in running GUI applications. Me: That is because he doesn't have enough memory to run GUI applications. Anyway, SuSe is targeted at more recent machines having at least 128 MB RAM. But tell him he need not despair. There are Linux distributions which cater to this segment too. Like you have the Damn Small Linux which runs easily even on machines with just 32 MB memory. Did you know that Damn small Linux takes up only 50 MB space on your harddisk in its uncompressed state? Another linux distribution in this category is Puppy Linux. Tom: Really? I wonder how they accomplish this extraordinary feat. Me: If you are impressed by that, then there are Linux distributions that fit inside a floppy. Tom: No Kidding ? Me: Seriously Tom. I am not pulling your leg. Tombsrtbt is a Linux distribution that fits inside a single floppy. It can be used for troubleshooting purposes. Tom: And it has my name too ;) . But seriously how is all this possible ? It is a bit overwhelming to have this discussion itself. Me: All these forks are possible because of the GNU movement. If Linux was released as a closed source project, these forks would not have seen the light of day. Tom: I am just curious. Which distribution will a geek favour ? Me: Heh heh, So you are aspiring to be a geek is it ? I have heard that Slackware and Gentoo are favoured by geeks. Slackware needs some mention here. It is one of the oldest distribution around. Earlier I talked about Deb and RPM formats. But Slackware uses an entirely different format called TGZ - which is gzipped tape archive, to install applications. There are many die hard slackware users who swear by this distribution for its ease of configuration and use. But it is not suitable for new users because most of the configuration is done by editing text files. Tom: But I always hear of Fedora, Ubuntu and the likes but seldom do I hear about Slackware, Xandros, CentOs or any others. Why is that ? Me: Tom, you have to understand that somebody who makes the loudest noise need not always be right. Firms like RedHat and Novell (SuSe) are multinational corporations which have millions of $ at their disposal. They gain all the publicity by running advertisements, conducting certifications and so on. Then there are some distributions like Debian and Ubuntu which grab the public's fancy because of their social ideals and commitment towards GNU movement and essentially because they are free as in freedom as well as beer. That doesn't mean they are the only good distributions around. Ultimately the choice filters down to the ideals, tastes and necessities of the user. Tom: Going by our discussion, I have arrived at the conclusion that I want a Linux distribution which is easy to install, easy for newbies and support all proprietary file formats out of the box (I definitely want to hear mp3 music). It has to have good customer support. And I am willing to pay money for it (though within limits). I guess I will go for Xandros, Mepis or Linspire. What do you think ? Me: Go for it Tom. I have always known that you have a penchant for spreading your money around ;) . But on a serious note, I think you have taken a good decision because when you pay money for the distribution, they include addons like support for propritery file formats and the user is saved from the job of installing them himself. Some of these distributions like Linspire also ship with non-free softwares like Win4Lin which helps you to run popular windows programs like photoshop and games like Age of Empire. So it is money well spent. It may be worthwhile if you visit Distrowatch.com and read some reviews about what people have to say regarding a particular distribution before you make the choice. Tom: Ravi, thanks for clearing my doubts regarding the Linux distributions. This discussion has helped me a lot. I do not know what I would have done without friends like you. Me: No problem Tom. And God speed ahead. A note to Readers Tom and Manish are fictitious characters and this whole train of thought took place inside my mind. I hope this conversation has helped clear the air about which Linux distribution is ideal for you.

Monday, June 16, 2008

DEFINING VARIABLES IN OCTAL AND HEXADECIMAL

Often, when writing systems programs, the programmer needs to use a different number base rather than the default decimal. Integer constants can be defined in octal or hex by using the associated prefix, e.g., to define an integer as an octal constant use %o int sum = %o567; To define an integer as a hex constant use %0x int sum = %0x7ab4; int flag = %0x7AB4; /* Note upper or lowercase hex ok */

Tuesday, June 10, 2008

Object-Oriented Programming Concepts

Object-oriented programming (OOP) is a programming paradigm that uses "objects" and their interactions to design applications and computer programs. Programming techniques may include features such as encapsulation, modularity, polymorphism, and inheritance. It was not commonly used in mainstream software application development until the early 1990s. Many modern programming languages now support OOP. What is an Object? An object is a software bundle of related state and behavior. Software objects are often used to model the real-world objects that you find in everyday life. This lesson explains how state and behavior are represented within an object, introduces the concept of data encapsulation, and explains the benefits of designing your software in this manner. What Is a Class? A class is a blueprint or prototype from which objects are created. This section defines a class that models the state and behavior of a real-world object. It intentionally focuses on the basics, showing how even a simple class can cleanly model state and behavior. What Is Inheritance? Inheritance provides a powerful and natural mechanism for organizing and structuring your software. This section explains how classes inherit state and behavior from their superclasses, and explains how to derive one class from another using the simple syntax provided by the Java programming language.

Linux Verify crond Daemon And Cronjobs Are Running

Q. How do I verify or check cronjob is running or not under CentOS / RHEL / Fedora Linux from a shell prompt? A. cron / crond is daemon to execute scheduled commands (Vixie Cron). Usually, it is started automatically from /etc/init.d on entering multi-user runlevels. RHEL / CentOS / Fedora Linux Verify Cron Service You can simply use any one of the following command to see if crond is running or not, enter: # pgrep crond OR # service crond status Sample output: crond (pid 4370) is running... If it is not running type the following two command to start crond: # chkconfig crond on # service crond start Verify cron is running by viewing log file, enter: # tail -f /var/log/cron A note about Debian / Ubuntu Linux Cron service Under Debian and Ububtu Linux cron logs its action logged to the syslog facility i.e. use /var/log/messages file: # tail -f /var/log/messages Find out if cron daemon is running or not, enter: # pgrep cron

Allow a normal user to run commands as root under Linux / UNIX operating systems

Q>. I would like to run few commands such as stop or start web server as a root user. How do I allow a normal user to run these commands as root? You need to use sudo command which is use to execute a command as another user. It allows a permitted user to execute a command as the superuser or another user, as specified in the /etc/sudoers (config that defines or list of who can run what) file. i.e. the sudo command allows users to do tasks on a Linux system as another user. sudo is more more secure then su command. By default it logs sudo usage, command and arguments in /var/log/secure (Red Hat/Fedora / CentOS Linux) or /var/log/auth.log (Ubuntu / Debian Linux). If the invoking user is root or if the target user is the same as the invoking user, no password is required. Otherwise, sudo requires that users authenticate themselves with a password by default (NOTE: in the default configuration this is the user's password, not the root password). Once a user has been authenticated, a timestamp is updated and the user may then use sudo without a password for a short period of time (15 minutes unless overridden in sudoers). /etc/sudoers Syntax Following is general syntax used by /etc/sudoers file: USER HOSTNAME=COMMAND Where, * USER: Name of normal user * HOSTNAME: Where command is allowed to run. It is the hostname of the system where this rule applies. sudo is designed so you can use one sudoers file on all of your systems. This space allows you to set per-host rules. * COMMAND: A simple filename allows the user to run the command with any arguments he/she wishes. However, you may also specify command line arguments (including wildcards). Alternately, you can specify "" to indicate that the command may only be run without command line arguments. How do I use sudo? For example, you want to give user rokcy access to halt/shutdown command and restart apache web server. 1) Login as root user 2) Use visudo command edit to edit the config file: # visudo 3) Append the following lines to file: rokcy localhost=/sbin/halt rokcy dbserver=/etc/init.d/apache-perl restart 4) Save the file and exit to shell prompt. 5) Now rokcy user can restart apache server by typing the following command: $ sudo /etc/init.d/apache-perl restart Output: Password: Restarting apache-perl 1.3 web server.... The sudo command has logged the attempt to the log file /var/log/secure or /var/log/auth.log file: # tail -f /var/log/auth.log Output: May 13 08:37:43 debian sudo: rokcy : TTY=pts/4 ; PWD=/home/rokcy ; USER=root ; COMMAND=/etc/init.d/apache-perl restart If rokcy want to shutdown computer he needs to type command: $ sudo /sbin/halt Output: Password: Before running a command with sudo, users usually supply their password. Once authenticated, and if the /etc/sudoers configuration file permits the user access, then the command is run. sudo logs each command run and in some cases has completely supplanted the superuser login for administrative tasks. More examples a) Specify multiple commands for user jadmin: jadmin ALL=/sbin/halt, /bin/kill, /etc/init.d/httpd b) Allow user jadmin to run /sbin/halt without any password i.e. as root without authenticating himself: jadmin ALL= NOPASSWD: /sbin/halt c) Allow user charvi to run any command from /usr/bin directory on the system devl02: charvi devl02 = /usr/bin/*

Thursday, June 5, 2008

IP Tables and Net filter

iptables - administration tool for IPv4 packet filtering and NAT DESCRIPTION ----------- Iptables is used to set up, maintain, and inspect the tables of IP packet filter rules in the Linux kernel. Several different tables may be defined. Each table contains a number of built-in chains and may also contain user-defined chains. Each chain is a list of rules which can match a set of packets. Each rule specifies what to do with a packet that matches. This is called a ‘target’, which may be a jump to a user-defined chain in the same table. TARGETS ------- A firewall rule specifies criteria for a packet, and a target. If the packet does not match, the next rule in the chain is the examined; if it does match, then the next rule is specified by the value of the target, which can be the name of a user-defined chain or one of the special values ACCEPT, DROP, QUEUE, or RETURN. ACCEPT means to let the packet through. DROP means to drop the packet on the floor. QUEUE means to pass the packet to userspace. (How the packet can be received by a userspace process differs by the particular queue handler. 2.4.x and 2.6.x kernels up to 2.6.13 include the ip_queue queue handler. Kernels 2.6.14 and later additionally include the nfnetlink_queue queue handler. Packets with a target of QUEUE will be sent to queue number ’0’ in this case. Please also see the NFQUEUE target as described later in this man page.) RETURN means stop traversing this chain and resume at the next rule in the previous (calling) chain. If the end of a built-in chain is reached or a rule in a built-in chain with target RETURN is matched, the target specified by the chain policy determines the fate of the packet. What are iptables and netfilter ? --------------------------------- * iptables is implemented at the lowest level in the kernel as KLMswhere it is called netfilter [NetFilter Organisation] * iptables does not operate at the Appln Layer; it can only decide the fate of a pkt based on its headers, not its payload [contents] * Better integration with the Linux kernel with the capability of loading iptables-specific KLMs designed for improved speed and reliability. * Stateful packet inspection. Also referred to as dynamic packet filtering. Stateful inspection is a firewall architecture that works at the network layer. Unlike static packet filtering, which examines a packet based on the information in its header, stateful inspection tracks each connection traversing all interfaces of the firewall and makes sure they are valid. An example of a stateful firewall may examine not just the header information but also the contents of the packet up through the application layer in order to determine more about the packet than just information about its source and destination. A stateful inspection firewall also monitors the state of the connection and compiles the information in a state table. Because of this, filtering decisions are based not only on administrator-defined rules (as in static packet filtering) but also on context that has been established by prior packets that have passed through the firewall. * Filtering packets based on a MAC address and the values of the flags in the TCP header. This is helpful in preventing attacks using malformed packets and in restricting access from locally attached servers to other networks in spite of their IP addresses * System logging that provides the option of adjusting the level of detail of the reporting * Better network address translation * Support for transparent integration with such Web proxy programs as Squid * A rate limiting feature that helps iptables block some types of (DoS) attacks
Click here for more info on IPTABLES
IpTables Basic:
  1. Any packet entering your computer goes through the INPUT chain. Any packet that your computer sends out to the network goes through the OUTPUT chain. Any packet that your computer picks up on one network and sends to another goes through the FORWARD chain. The chains are half of the logic behind iptables themselves.

Wednesday, June 4, 2008

Sending mail in python

def send_mail(destination, source, subject, text, smtp_addr='localhost'): """Simple function to send an email. destination The email address that the message should be sent to. source The 'From' address that will be used for the email. subject The subject/ title of the email. text The actual message/ content of the email. smtp_addr The hostname or IP address of the SMTP server that will deliver the email. Example usage: send_mail('my_friend@test.com', 'bgates@microsoft.com', 'Hi!', 'Just checking in.') """ import email.Message import smtplib mail = email.Message.Message() mail['To'] = destination mail['From'] = source mail['Subject'] = subject mail.set_payload(text) server = smtplib.SMTP(smtp_addr) server.sendmail(source, destination, mail.as_string()) server.quit()

Tuesday, June 3, 2008

Dot Net

What is .NET ? # It is a platform neutral framework. # Is a layer between the operating system and the programming language. # It supports many programming languages, including VB.NET, C# etc. # .NET provides a common set of class libraries, which can be accessed from any .NET based programming language. There will not be separate set of classes and libraries for each language. If you know any one .NET language, you can write code in any .NET language!! # In future versions of Windows, .NET will be freely distributed as part of operating system and users will never have to install .NET separately. What is Not ?

Monday, June 2, 2008

Get command line parameters for a program in PYTHON

Example of a function by which you can get command line parameters for a program in python Note : Kindly do the indentatoin of your own.........
def GetCommandLineParameters(commandline_temp):

   position = 0
   fcrontmpfile,entrytoignore,fcronsourcefile = '','',''
   length = len(commandline_temp)

   while position < fcrontmpfile =" commandline_temp[position]" entrytoignore =" commandline_temp[position]" fcronsourcefile =" commandline_temp[position]" style="font-weight: bold;">Example of a Usage Function
def Usage():
   print "\nPlz go through the USAGE."
   print "Note : \n\t*\tThis suid can read or write in a fcron file. ignoreprogram is the entry which \n\t\tyou would like
to remove to avoid duplication. \n\n\t*\tIt would be prefered to give the full program name with the path so that \n\t\tther
e is no duplication with the new entry. \n\n\t*\t--fcrontempfile and --ignoreprogram are mandatory if you want to read the \
n\t\tfcron or --fcronsourcefile is mandatory if u want to change the fcron of the firewall."
   print "\nUSAGE: python writeinfcron.py [OPTION...]"
   print "-------------------------------------------------------------------------------------------------"
   print "\n--fcrontempfile          ------->        A temp file with path where the fcrondata will be written."
   print "--ignoreprogram          ------->        An entry which you would like to ignore."
   print "--fcronsourcefile        ------->        Fcron Source file which will be wriiten in the cron file"
   print "-------------------------------------------------------------------------------------------------"