Linux runlevels and boot process

March 5th, 2007

I always see lots of directories in /etc/rc.d/ like rc.0, rc.1, rc.2, rc.3, rc.4, rc.5, and rc.6. Once I tried to find out what are all these. Then I came to know these are runlevels. Then the question came how do they get triggered and whats the difference between these runlevels. Here is what I found :

When you turn on the system following things happens :

1. Boot loader finds the kernel image from disk and loads it in to memory.

2. Kernel initializes the devices and its drivers

3. Kernel mounts the root file system

4. Kernel starts a program called init.

5. init start all the rest processes.

init

There is nothing special about init. It is a program just like any other on the Linux system, and you’ll find it in /sbin along with other system binaries. The main purpose of init is to start and stop other programs in a particular sequence. All you have to know is how this sequence works.

Most linux system are System V (derived from AT&T System V) based . Another is based on BSD (Berkeley Software Distribution). What’s the difference between the two? Basically BSD doesn’t have any runlevels. This means that System V are more flexible

Most Linux distros put startup scripts in the rc subdirectories (rc1.d, rc2.d, etc.), whereas BSD systems house the system scripts in /etc/rc.d. Slackware’s init setup is similar to BSD systems, though Slackware does have runlevels and has had System V compatibility since Slackware 7.

Runlevels :

At any given time on a Linux system, a certain base set of processes is running. This state of the machine is called its runlevel, and it is denoted with a number from 0 through 6. The system spends most of its time in a single runlevel.
You will also find a file named /etc/inittab. The system uses these files (and/or directories) to control the services to be started. If you look in the file /etc/inittab you will see something like:

id:5:initdefault:

l0:0:wait:/etc/rc.d/rc.0

l6:6:wait:/etc/rc.d/rc.6

x1:4:wait:/etc/rc.d/rc.4

First line means that the default runlevel on the system is 5. All lines in the inittab file take this form, with four fields separated by colons occurring in the following order:

  • A unique identifier (a short string, such as id in the preceding example)
  • The applicable runlevel number(s)
  • The action that init should take (in the preceding example, the action is to set the default runlevel to 5)
  • A command to execute (optional)
  • Run Level Generic Linux/Fedora Core Slackware Debian
    0 Halt Halt Halt Halt
    1 Single-user mode Single-user mode Single-user mode Single-user mode
    2 Basic multi-user mode (without networking) User definable (Unused) User definable – configured the same as runlevel 3 Multi-user mode
    3 Full (text based) multi-user mode Multi-user mode Multi-user mode – default Slackware runlevel
    4 Not used Not used X11 with KDM/GDM/XDM (session managers) Multi-user mode
    5 Full (GUI based) multi-user mode Full multi-user mode (with an X-based login screen) – default runlevel User definable – configured the same as runlevel 3 Multi-user mode
    6 Reboot Reboot Reboot Reboot

    How to get a date or timestamp of a file in perl.

    January 29th, 2007

    Once i was trying to get the date when the file is written in perl. I found the following solutions all of them are giving the complete timestamp of the file but i needed only the date.
    You can get the timestamp of a file in following ways in perl :

    First Method :

    $write_secs = (stat($file))[9];
    print “file $file updated at “, scalar(localtime($file)), “\n”;

    Second Method :
    Using standard module File::stat and Time::locatime(bundled with all 5.x perl installations)

    use File::stat;
    use Time::localtime;
    $date_string = ctime(stat($file)->mtime);
    print “file $file updated at $date_string\n”;

    To get only the data of file I used this solution :

    $tm = localtime(stat($path)->mtime);
    #get only the data from time object
    $date_string = $tm->mday.”-”.(($tm->mon)+1).”-”.(($tm->year)+1900);
    print “file $file updated at $date_string\n”;

    Test

    January 10th, 2007

    Firefox is already running, but is not responding. To open a new window, you must first close the existing Firefox process, or restart the system.

    December 14th, 2006

    Sometimes when you try to start firefox, it gives error “Firefox is already running, but is not responding. To open a new window, you must first close the existing Firefox process, or restart the system” and exits. This problem occur generally because of unclean shutdown or power reboots. Whenever we start firefox it creates a lock or .parentlock file in your firefox profile directory(~.mozilla/firefox/profile/.parentlock etc) and because of unclean shutdown not able to delete the file. This problem persists even if you try to reinstall the firefox.
    Simple solutions to this problem is remove the lock or .parentlock file :

    > rm -rf .mozilla/firefox/lprrz8oe.default/.parentlock or
    > rm -rf .mozilla/firefox/lprrz8oe.default/lock

    ENJOY BROWSING !!!!!

    Hidden surprises in Windows XP

    December 8th, 2006

    Want to win a game of Solitaire with tapping on just three keys on your keyboard? While no one’s looking, simply jab the magic combination ‘Alt + Shift + 2’ and whoosh! All your cards will obediently go in their appropriate places. Chanting a little mumbo-jumbo as mantra will create the right effect.

    If it’s FreeCell that you plan to work on, then switch to using ‘Ctrl + Shift + F10’ immediately after you start the game. You’ll get a box that gives you three options: Abort, Retry or Ignore. Simply click on ‘Abort’ and move any card to win.

    Pinball in another fun game in Windows XP. To get extra balls type 1max at the start of a new game. Better still, to increase your ranking without even playing the game, simply type ‘rmax’ at the beginning of a new game to go up in ranks.

    Windows XP has a secret application that lets you create and edit fonts. To access it, go to ‘Start > Run’ and type ‘eudcedit’. This will open an application called ‘Private Character Editor’.

    The beta version of Microsoft Office 2007 has this interesting egg; Open Word and create a blank document. Now type =rand(200,99) anywhere and watch as 556 pages get filled with text on help about inserting tabs and lots more.

    Source : Times of India (Dec-8-2006)

    Search Engine Optimztion

    December 4th, 2006

    We daily hear about SEO. Once I thought lets find out what is this search engine optimization, why and how we do search engine optimization.

    What is SEO (Search Engine Optimztion) : Search engine optimization is the process of increasing traffic to your site by making it rank high in search engines like google, yahoo, msn, a9 or altavista. The way people find information on the internet is by entering “KEYWORDS” in the popular search engines and click on the top results. So if your site have a high ranking in the search engine for given keywords, there are better chances of getting more users to your site.

    Why SEO : People rarely read the past first page search results. If they dont find something usefull on first page of their result, they generally modify the “Keyword”. So if your site have a good rank of search engines for the specific keywords, there are chances that your site will appear on the first page and it will help you to :

    1. increase your sales
    2. increase traffic to your site
    3. dominate your competition
    4. increase your profit with increase in traffic

    How we do seo : Following are the ways to increase rank of your site in search engines :

    1. Submission to search engines and directories : Submit your site to search engines like yahoo, google, msn, alexa, a9. When you submit site to search engines it will be crawled and indexed by them.
    2. Keyword optimizaion : Find out key pharses related to your site and business and optimize your site based on them
    3. Link Building : Create inbound and outbound links to your site.

    How do I find the geographical location from ip address

    December 4th, 2006

    Generally it is imposible to find location from ip address. There is no connection between IP address and the location of some host. Here are following tricks to guess the IP address of a host. Some companies maintain database using these tricks.

    1. Using reverse DNS find out hosts name and hosts name can provide some information about country. Like take a examle of IP address 125.22.0.188 and do a nslookup on that “nslookup 125.22.0.188″ it give something like broadband.airtel.co.in so from the last .in we can figure out that this ip address belongs to INDIA. But reverse DNS does not works all the times it depends upon servers configuration. I domain can be hosted in another country even when it have name have .in in domain name.
    2. Visit the hosts web site like www.geo-location.com and find out the location. Some sites mention their location on the web pages.
    3. More to be added

    Besan ki sondhi roti par

    November 13th, 2006

    I like this song from my childhood, from the time when I hate the songs when they came between the movies.

    Besan ki sondhi roti par
    Khatti chatni jaisi maa
    Yaad aati hai chauka-baasan
    Chimta phukani jaisi maa

    Baans ki khurri khaat ke oopar
    Har aahat par kaan dhare
    Aadhi soyee aadhi jaagi
    Thaki dopahari jaisi maa
    Chirdiyon ke chahakaar mein gunjey
    Raadha-mohan ali-ali
    Murghe ki awaaz se khulti
    Ghar ki kundi jaisi maa

    Biwi, beti, behan, pardosan
    Thordi thordi si sab mein
    Din bhar ek rassi ke oopar
    Chalati natni jaisi maa

    Baant ke apna chehra, maatha,
    Aankhien jaane kahaan ga-yin
    Phatey puraane ek album mein
    Chanchal lardki jaisi maa

    How to start openoffice faster in linux

    November 2nd, 2006

    I have a system with 1GB ram but the openoffice takes a long time to start up. Once I thought do some “googling and find out what is the solution to this problem.

    This is because by default the application only uses 9MB of the RAM for it’s graphic cache. To increase the Graphic Cache, go to “Tools > Options > OpenOffice.org > Memory” and increase the “Graphics Cache” from 9M to about 128MB (or whatever you want). Restart OpenOffice and you will notice that the latency has now dissapeared.

    While you are at it, the Memory per object setting allocates memory for each object. The default is 2.4 MB which may need to be increased if you are working with high quality images or decreased if you are not really using images and you need to save on memory resources.

    Enjoy!!!!

    Simple redirection in Java Script

    October 8th, 2006

    Once I am trying to redirect a cgi script with cookies or after writing the cookies header. I searched a lot of stuff and found that in cgi redirection can be done only before writing the header information. Digging in to the problem I found this simple solution….