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)

November 18, 2007

Using Servlets in Ubuntu Gutsy Gibbon

Filed under: Ubuntu — Roshan @ 3:48 pm
Tags: , , , , ,

All commands and descriptions are CASE SENSITIVE

 

 

STEP 1: INSTALLATION

 

 

First of all, install Java6, Apache, Tomcat5.5 and all related packages:

 

Use Synaptic Manager(recommended)

OR

Run these following commands at the terminal:

$ sudo apt-get install apache2-mpm-prefork apache2-common apache2-utils

$ sudo apt-get install sun-java6-jdk tomcat5.5 tomcat5.5-admin tomcat5.5-webapps

$ sudo apt-get install libapache2-mod-jk

 

 

STEP 2: SETTING UP

 

 

Run this command at the terminal:

$ sudo a2enmod

Then a prompt for a module comes. There type “jk” and enter:

Module name? jk

Prompt comes back.

Edit the “jk.load” file using the following command:

$ sudo gedit /etc/apache2/mods-enabled/jk.load

A file will open with the following line in it:

LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so

Append the following lines in it:

JkWorkersFile /etc/apache2/workers.properties

JkLogFile /var/log/apache2/mod_jk.log

JkLogLevel debug

JkLogStampFormat “[%a %b %d %H:%M:%S %Y] “

JkMount /jsp-examples worker1

JkMount /jsp-examples/* worker1

JkMount /servlets-examples worker1

JkMount /servlets-examples/* worker1

Save and close the file.

Edit the “workers.properties” file using the following command:

$ sudo gedit /etc/apache2/workers.properties

An empty file will open. There paste these contents:

workers.tomcat_home=/usr/share/tomcat5

workers.java_home=/usr/lib/jvm/java-1.5.0-sun

ps=/

worker.list=worker1

worker.worker1.port=8009

worker.worker1.host=localhost

worker.worker1.type=ajp13

worker.worker1.lbfactor=1

Save and close the file.

Edit the “environment” file using the following command:

$ sudo gedit /etc/environment

A file will open with the following lines in it:

PATH=”/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games”

LANG=”en_IN.UTF-8″

LANGUAGE=”en_IN:en”

Append the following lines in it:

CLASSPATH=.:/usr/lib/jvm/java-6-sun/bin:/usr/share/tomcat5.5/common/lib/servlet-api.jar

JAVA_HOME=/usr/lib/jvm/java-6-sun

Save and close the file.

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

$ gedit $HOME/.bashrc

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

export JAVA_HOME=/usr/lib/jvm/java-6-sun

export CATALINA_HOME=/usr/share/tomcat5.5

export CLASSPATH=/usr/share/tomcat5.5/common/lib/servlet-api.jar

export PATH=$PATH:$JAVA_HOME/bin:$CLASSPATH:$CATALINA_HOME

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 run this command at the terminal:

$ sudo cp web.xml /etc/tomcat5.5/

Setup is done.

 

 

STEP 3: RESTART

 

 

Restart Apache and Tomcat by running the following commands at the terminal:

$ sudo /etc/init.d/apache2 stop

$ sudo /etc/init.d/tomcat5.5 stop

$ sudo /etc/init.d/tomcat5.5 start

$ sudo /etc/init.d/apache2 start

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:8180

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:8180/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 servlet-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:

$ sudo mkdir /usr/share/tomcat5.5-webapps/ROOT/WEB-INF/classes/

(If it already exists, no problem!)

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

For example:

$ cd /usr/share/tomcat5.5-webapps/ROOT/WEB-INF/classes/

$ sudo gedit HelloWorld.java

PS: It is a MUST to use “sudo” before each command as this folder is “writable” only with administrative privileges(Instead of typing it each time, you can also use the super-user shell by running the command “su”)

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

$ sudo javac HelloWorld.java

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

http://localhost:8180/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 /usr/share/tomcat5.5-webapps/ROOT

$ sudo gedit HelloWorld.html

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

Open this link in your browser:

http://localhost:8180/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/997deb96-203b-42fd-85aa-755be8ca5244/web-ubuntu

 

 

 

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 🙂

 

Create a free website or blog at WordPress.com.