Freely Scripted Soul

February 3, 2008

Reinstalling Grub boot loader

Filed under: Software and Technology,Ubuntu — Roshan @ 8:41 am
Tags: , , , ,

REASONS:

 

  • Grub, by default, resides in the Master Boot Record(MBR). When you try to install some other boot loader or try to install/reinstall Windows, the grub information in the MBR will be overwritten. So, Grub might have to be reinstalled.
  • When some/any part of partition information is changed, the grub configuration won’t be automatically notified of it and so, the grub configuration will remain as it is. There maybe many cases in which the partition information maybe changed like when you create an extra partition, which is something trivial and may or may not affect the grub boot loader. However, most of the times, changes in the partition information will result in errors when the grub boot loader is loaded. So, the grub configuration has to be updated and the easiest way is to reinstall Grub.

 

There are many such cases and in these cases, people tend to treat the effect, more than the cause. By this, I mean people tend to usually reinstall Ubuntu or Fedora or whichever GNU/Linux operating system they are using, through which Grub will be automatically reinstalled. But is it necessary? No, Grub can be reinstalled without reinstalling the entire operating system! In fact, Fedora CD/DVD does offer to reinstall Grub if you choose to upgrade your system. However, I have tried to use that option in many of my friends’ computers and it has never worked! I have no idea why it doesn’t work. So I resort to the easiest fool-proof method I know – COMMANDS @ TERMINAL

 

COMMANDS TO REINSTALL GRUB:

 

All you need to do is access the terminal using the installation CD/DVD of your GNU/Linux operating system. Ubuntu installation CD is a live CD and so, when it loads, you can run the terminal from there. Fedora installation CD/DVD offers options through which you will have to choose to upgrade the system using commands(rescue mode).

 

Once you are at the terminal, you will have to access the ‘grub’ shell to change the grub configuration. So, give this command at the terminal:

$ grub

If it says that you don’t have the permission, in which case you will not have logged in as root(as in Ubuntu), give this command at the terminal:

$ sudo grub

You will get the grub-shell prompt:

grub>

 

Now, you will have to find out in which partition Grub had been installed before, so that you reinstall in that partition only. Give this command at the terminal:

grub> find /boot/grub/stage1

(returns value)

It returns the number of the partition in which Grub i.e your GNU/Linux had been installed.

e.g.,

grub> find /boot/grub/stage1

(hd0,2)

 

NOTE:

Sometimes, when Grub has not been installed properly, the file “/boot/grub/stage1” may not exist. So, the output will be “Error 15: File not found”. In such a case, come out of the grub-shell by pressing “Ctrl+c”. Then, at the shell prompt, give this command at the terminal:

$ fdisk -l

Again, if you are not logged in as root, give this command at the terminal:

$ sudo fdisk -l

The output will list all the partitions and it’s properties, including the file system type.

e.g.,

Device Boot Start End Blocks Id System
/dev/sda1   1 654 5253223+ b W95 FAT32
/dev/sda2 * 655 1962 10506510 7 HPFS/NTFS
/dev/sda3   1963 3924 15759765 83 Linux

The “System” attribute of your GNU/Linux operating system will be “Linux”. So note down that partition number.

e.g., sda3

Since it’s array numbering, sdaN is mapped to (hd0,N-1).

Just (hd0) will be the Master Boot Record(MBR).

sda1 will be (hd0,0) and so on.

So, sda3 will be (hd0,2)

Now, log into the grub-shell prompt again.

 

Before reinstalling Grub, you will have to notify the partition that your Grub i.e. GNU/Linux is resided in. So, give this command at the terminal:

grub> root (returned value)

e.g.,

grub> root (hd0,2)

 

Now, reinstall grub in the MBR i.e. the returned value without number part.

e.g., (hd0)

So, give this command at the terminal:

grub> setup (returned value without number part)

e.g.,

grub> setup (hd0)

 

Exit the grub-shell prompt using “Ctrl+c”.

Exit the shell prompt using “Ctrl+d”.

 

PS:

You can also reinstall Grub in your GNU/Linux partition, only if this GNU/Linux partition is “primary” and you have another boot loader installed at the MBR(in case of more than one GNU/Linux operating systems) through which you can boot this primary partition. To do that, give this command at the terminal:

grub> setup (returned value)

e.g.,

grub> setup (hd0,2)

Advertisements

November 24, 2007

Using Servlets in Fedora Core 3

Filed under: Software and Technology — Roshan @ 9:21 am
Tags: , , , ,

All commands and descriptions are CASE SENSITIVE

 

 

STEP 1: INSTALLATION

 

 

First of all, while installing Fedora, be sure to tick the optional packages of “Web Servers” and “Mysql Servers” (or after installation, boot from your CD and “upgrade” your system by selecting the required packages).

Download Java6 and Apache-Tomcat5.5.

Copy both the downloaded files – “jdk-6u3-linux-i586.bin” and “apache-tomcat-5.5.25.tar.gz” – to “/opt”.

Install Java6 and Apache-Tomcat5.5 by running the following commands at the terminal:

$ cd /opt

$ ./jdk-6u3-linux-i586.bin

$ tar -xvzf apache-tomcat-5.5.25.tar.gz

 

 

STEP 2: SETTING UP

 

 

Create symbolic links for the “java” and “tomcat” folders in “/opt” only by running these commands at the terminal:

$ ln -s apache-tomcat-5.5.25 tomcat

$ ln -s jdk1.6.0_03 java

Edit the “profile” file using the following command:

$ gedit /etc/profile

A file will open with the a number of lines in it. Append the following lines in it:

export JAVA_HOME=/opt/java

export CATALINA_HOME=/opt/tomcat

export CLASSPATH=.:/opt/tomcat/common/lib/servlet-api.jar

PATH=$PATH:$JAVA_HOME:$CATALINA_HOME:$CLASSPATH:.

Save and close the file.

Download this web.xml file to your HOME folder (or change your directory to the folder in which you have stored this downloaded file), rename it as “web.xml” and copy it to the folder “/opt/tomcat/conf”:

$ cp web.xml /opt/tomcat/conf/

Setup is done.

 

 

STEP 3: RESTART

 

 

Go to Applications->System Settings->Server Settings->Services

The “Services” window will open. On the left-side pane, one-by-one, “tick” the boxes and click on the “Start” button for the following services: httpd, mysqld

You should get appropriate messages that the services have been started successfully.

Click on the “Save” button to save these settings permanently.

Restart the system for the changes to take effect.

 

 

STEP 4: TESTING

 

 

Run this command at the terminal to start Tomcat: (This has to be done each time you start a new session i.e. each time you login and want to use Tomcat)

$ sh /opt/tomcat/bin/startup.sh

The output will show the Tomcat’s environment variables and their values.

To test whether Tomcat has been set up properly, open this link in the browser:

http://localhost:8080

If you get the Apache Tomcat Homepage, it means that Apache and Tomcat has been set up properly.

To check whether Servlets has been set up properly, open this link in the browser:

http://localhost:8080/servlets-examples/

It opens the Servlets examples page of Apache Tomcat. Run the examples on the page. If they execute properly, Servlets have been set up properly.

Copy the source code of the example “Hello World” there. Open a file in your home folder:

$ gedit HelloWorld.java

Paste the contents of the example in this file. Save and close the file.

Compile this file:

$ javac HelloWorld.java

If it doesn’t give any errors and the byte-compiled “.class” file is created, then Java has been set up properly.

 

 

STEP 5: USING

 

 

Run this command at the terminal to start Tomcat: (This has to be done each time you start a new session i.e. each time you login and want to use Tomcat)

$ sh /opt/tomcat/bin/startup.sh

The output will show the Tomcat’s environment variables and their values.

Run this command at the terminal:

$ mkdir /opt/tomcat/webapps/ROOT/WEB-INF/classes

(If it already exists, no problem!)

Store all your “.java” and “.class” files in this “classes” folder.

For example:

$ cd /opt/tomcat/webapps/ROOT/WEB-INF/classes

$ gedit HelloWorld.java

A file will open. Write your Servlet code in it. Save and close the file.

$ javac HelloWorld.java

Now to run this Servlet, open this link in your browser:

http://localhost:8080/servlet/HelloWorld

This should work provided your Servlet code is right.

Now, suppose you want to write a HTML file which will use your Servlet program. Then you need to store it in your “ROOT” folder of Tomcat.

For example:

$ cd /opt/tomcat/webapps/ROOT

$ gedit HelloWorld.html

A file will open. Write your HTML code in it, which will interact with “HelloWorld.class” file in the “classes” folder. Save and close the file.

Open this link in your browser:

http://localhost:8080/HelloWorld.html

This should work provided your HTML code is right and provided your Servlet code in the “classes” folder has been byte-compiled(“.class” file).

 

DOWNLOAD LINKS:

Java6 – https://sdlc4a.sun.com/ECom/EComActionServlet;jsessionid=87D3A2EB1CF3330672A9619B88690488

“Accept” License Agreement and click on Linux self-extracting file “jdk-6u3-linux-i586.bin”.

Apache-Tomcat5.5 – http://www.apache.org/dist/tomcat/tomcat-5/v5.5.25/bin/

 

 

 

Click on “apache-tomcat-5.5.25.tar.gz “.

Web.xml – http://www.esnips.com/doc/128015cf-4006-48b9-a640-dcd6db5b7748/web-fedora3

 

 

PS: If something doesnt work, please check for missing or erroneous case-sensitive letters or slashes. If you face some problem and are unable to find a solution, feel free to add a comment here or mail me. I ll do my level best to find a solution.

 

 

PPS: Thanks to Madhusudan C S for the wonderful research 🙂

 

November 18, 2007

Using Servlets in Fedora Core 7

Filed under: Software and Technology — Roshan @ 4:07 pm
Tags: , , , ,

All commands and descriptions are CASE SENSITIVE

 

 

STEP 1: INSTALLATION

 

 

First of all, install Java6, Apache, Tomcat5.5 and all related packages by using your installation DVD(while installing Fedora itself or after installation, boot from the DVD and “upgrade” your system by selecting the required packages).

NOTE: Tomcat is an optional package under “Web Servers”. So click on “Web Servers” and then on “Option Packages”. Browse the list and “tick” all Tomcat related packages.

 

 

STEP 2: SETTING UP

 

 

Edit the “.bashrc” file using the following command:

$ gedit $HOME/.bashrc

A file will open with the a number of lines in it. Append the following lines in it:

export JAVA_HOME=/usr/share/java

export CATALINA_HOME=/etc/tomcat5

export CLASSPATH=.:/var/lib/tomcat5/common/lib/[servlet].jar

PATH=$PATH:$JAVA_HOME:$CATALINA_HOME:$CLASSPATH:.

Save and close the file.

Download this web.xml file to your HOME folder(or change your directory to the folder in which you have stored this downloaded file), rename it as “web.xml” and copy it to the folder “/etc/tomcat5”:

$ cp web.xml /etc/tomcat5/

Setup is done.

 

 

STEP 3: RESTART

 

 

Go to System->Administration->Server Settings->Services

The “Services” window will open. On the left-side pane, one-by-one, “tick” the boxes and click on the “Start” button for the following services: httpd, mysqld, tomcat5

You should get appropriate messages that the services have been started successfully.

Click on the “Save” button to save these settings permanently.

Restart the system for the changes to take effect.

 

 

STEP 4: TESTING

 

 

To test whether Tomcat has been set up properly, open this link in the browser:

http://localhost:8080

If you get the Apache Tomcat Homepage, it means that Apache and Tomcat has been set up properly.

To check whether Servlets has been set up properly, open this link in the browser:

http://localhost:8080/servlets-examples/

It opens the Servlets examples page of Apache Tomcat. Run the examples on the page. If they execute properly, Servlets have been set up properly.

Copy the source code of the example “Hello World” there. Open a file in your home folder:

$ gedit HelloWorld.java

Paste the contents of the example in this file. Save and close the file.

Compile this file:

$ javac HelloWorld.java

If it doesn’t give any errors and the byte-compiled “.class” file is created, then Java has been set up properly.

 

 

STEP 5: USING

 

 

Store all your “.java” and “.class” files this “classes” folder:

/var/lib/tomcat5/webapps/servlets-examples/WEB-INF/classes

For example:

$ cd /var/lib/tomcat5/webapps/servlets-examples/WEB-INF/classes

$ gedit HelloWorld.java

A file will open. Write your Servlet code in it. Save and close the file.

$ javac HelloWorld.java

Before running it, you need to TWEAK the “web.xml” file. Run this command at the terminal:

$ gedit /var/lib/tomcat5/webapps/servlets-examples/WEB-INF/web.xml

Click on the “Replace” button or press “Ctrl+H” from the keyboard.

You need to replace all instances of “HelloWorldExample” with your filename i.e. “HelloWorld”.

So enter “HelloWorldExample” in “Search For” box and “HelloWorld” in “Replace with” box and click “Replace All”.

Save and close the file.

IMPORTANT: This TWEAKING is necessary for ONLY the first time you are executing a Servlet in your system. Once you tweak this file and execute your Servlet successfully, just FORGET about this file. (I don’t quite understand the logic behind this. It quite illogical! However, servlets work only if you tweak web.xml in this way! Maybe a bug in Fedora7 😉 )

Now to run this Servlet, open this link in your browser:

http://localhost:8080/servlets-examples/servlet/HelloWorld

This should work provided your Servlet code is right.

Now, suppose you want to write a HTML file which will use your Servlet program. Then you need to store it in your “servlets-examples” folder of Tomcat.

For example:

$ cd /var/lib/tomcat5/webapps/servlets-examples

$ gedit HelloWorld.html

A file will open. Write your HTML code in it, which will interact with “HelloWorld.class” file in the “classes” folder. Save and close the file.

Open this link in your browser:

http://localhost:8080/servlets-examples/HelloWorld.html

This should work provided your HTML code is right and provided your Servlet code in the “classes” folder has been byte-compiled(“.class” file).

 

DOWNLOAD LINK:

Web.xml – http://www.esnips.com/doc/ca71aa2c-ec61-4fbb-8b0e-85a670ef6c2f/web-fedora7

 

 

 

PS: If something doesnt work, please check for missing or erroneous case-sensitive letters or slashes. If you face some problem and are unable to find a solution, feel free to add a comment here or mail me. I ll do my level best to find a solution.

 

 

PPS: Thanks to Uday S Athreya for the wonderful research 🙂

 

Blog at WordPress.com.