Monday, 28 November 2011

Restoring GRUB

Restoring GRUB on Ubuntu

How many times have you lost your GRUB after installing Windows on a system that has Ubuntu (or any other distro) already installed?

The bootloader sector of the hard disk stores the information about all the operating systems installed on your system. When you install Linux, it probes for any existing operating system and adds an entry in the GRUB list. On the other hand, when you install Windows, it overwrites the bootloader and erases all the entries, leaving no way to access your Linux.

To restore GRUB, you will need Ubuntu mounted on any removable drive (CD/DVD/Pen drive) will can be used as a live CD. After booting from the external media, select "Use as Live CD" option. Open the terminal and type the following commands:

Also, you should know where you have installed Ubuntu (in this example sda3)

~$ su # mount /dev/sda3 /mnt
# mount --bind /dev /mnt/dev
# mount --bind /proc /mnt/proc
# mount --bind /sys /mnt/sys
# chroot /mnt
# grub-install /dev/sda

Close the terminal and reboot. Your GRUB should be restored.

Monday, 21 November 2011

How to fix ‘$MFTMirr does not match $MFT (record 0)’

Sometimes, when you are executing a file transfer between your computer hard drive and an external drive and your computer shutdowns for some reason it’s pretty common to get some errors on external drives that uses NTFS as their file system.

The error message may be:

Error mounting: mount exited with exit code 13: $MFTMirr does not match $MFT (record 0).
Failed to mount ‘/dev/sdc1′: Input/output error
NTFS is either inconsistent, or there is a hardware fault, or it’s a
SoftRAID/FakeRAID hardware. In the first case run chkdsk /f on Windows
then reboot into Windows twice. The usage of the /f parameter is very
important! If the device is a SoftRAID/FakeRAID then first activate
it and mount a different device under the /dev/mapper/ directory, (e.g.
/dev/mapper/nvidia_eahaabcc1). Please see the ‘dmraid’ documentation
for more details.

The easiest solution is to use 'ntfsfix' command from the terminal
~$ sudo ntfsfix /dev/partitionName

The output should be similar to:

~$ sudo ntfsfix /dev/sdc1
Mounting volume... FAILED
Attempting to correct errors...
Processing $MFT and $MFTMirr...
Reading $MFT... OK
Reading $MFTMirr... OK
Comparing $MFTMirr to $MFT... FAILED
Correcting differences in $MFTMirr record 0...OK
Processing of $MFT and $MFTMirr completed successfully.
Setting required flags on partition... OK
Going to empty the journal ($LogFile)... OK
NTFS volume version is 3.1.
NTFS partition /dev/sdc1 was processed successfully.

And you are done!

After this step you should be able to access your external drive partition as usual, mount or use nautilus to access your files.

Saturday, 19 November 2011

JSP and MySQL Connectivity

I remember when I first started using Tomcat, it took me a while to make my JSP script connect to MySQL using Connector/J.

1. Tomcat is a free, open-source implementation of Java Servlet and JavaServer Pages technologies developed under the Jakarta project at the Apache Software Foundation. Download and install Tomcat.

2. Install MySQL.

3. Create a database, say 'ProductSpec', and a table 'products' with three fields- id, name, brand.

CREATE DATABASE  `ProductSpec` ;

CREATE TABLE  `products` (
 `name` VARCHAR( 50 ) NOT NULL ,
 `brand` VARCHAR( 50 ) NOT NULL

4. I populate the the database with a few values next:

INSERT INTO  `ProductSpec`.`products`
VALUES ( 1 ,  'Hard Disk',  'Seagate');

INSERT INTO  `ProductSpec`.`products`
VALUES ( 2 ,  'iPhone 3G',  'Apple');

5. Set up two environment variables as follows:
(a) Right click on Computer, go to Properties. Click on 'Advanced System Settings on the left. A dialog box appears as shown below. Go to the 'Advanced Tab' and click on 'Environment Variables'.

(b)Under User Variables, add the two new variables. The first is the path to your jre folder, the second is the path to the the Tomcat folder. For instance, if your jre folder path is D:/jdk1.6.0_12/jre, add the following-

Variable Name: JAVA_HOME, Variable Value: D:/jdk1.6.0_12/jre

Variable Name: TOMCAT_HOME, Variable Value: C:\Program Files\Apache Software Foundation\Tomcat 7.0

6. Download Connector/J at "">
Unzip or Untar the file, and copy the file mysql-connector-java-5.1.6-bin.jar to Tomcat/lib or Tomcat/common/lib

This completes the setup! Now for the jsp program that connects to the database and retrieves and displays values. Make sure Tomcat and wamp are running!

7. Here's db.jsp:

<%@ page import="java.sql.*" %>


String connectionURL = "jdbc:mysql://localhost:3306/ProductSpec?username=root;password=";

Connection connection = null;

Statement statement = null;

ResultSet rs = null;





connection = DriverManager.getConnection(connectionURL, "root", "");

statement = connection.createStatement();

rs = statement.executeQuery("SELECT * FROM products");

while ( {

out.println(rs.getString("name")+" "+rs.getString("brand")+"<br />");





Change your database name, username and password on line 3: (Default username for wamp is root and password is blank.

String connectionURL = "jdbc:mysql://localhost:3306/ProductSpec?username=root;password=";

8. Add db.jsp to Tomcat\webapps\ROOT folder.

9. Now go to your browser and type localhost/db.jsp
If you had set a port number for Apache during installation like I had (8088), type localhost:8088/db.jsp