SITE SEARCH

Google
 

Sunday, February 14, 2010

Reinstall Ubuntu Grub Bootloader After Windows Wipes it Out

If you run a dual-boot system with Linux and Windows, this has happened to you. You had to do your monthly reinstall of Windows, and now you don’t see the linux bootloader anymore, so you can’t boot into Ubuntu or whatever flavor of linux you prefer.

Here’s the quick and easy way to re-enable Grub.

1) Boot off the LiveCD

2) Open a Terminal and type in the following commands, noting that the first command will put you into the grub “prompt”, and the next 3 commands will be executed there. Also note that hd0,0 implies the first hard drive and the first partition on that drive, which is where you probably installed grub to during installation. If not, then adjust accordingly.

sudo grub

> root (hd0,0)

> setup (hd0)

> exit

Reboot (removing the livecd), and your boot menu should be back.



Only read below if Windows is now missing from the boot menu

If you installed Ubuntu before you installed Windows, then Ubuntu will not have anything in the grub configuration for Windows. This is where you’ll have to do a bit of manual editing to the grub boot menu file.

If you open the file /boot/grub/menu.lst with the following command:

sudo gedit /boot/grub/menu.lst

You’ll see a sample section for Windows, which you’ll want to uncomment and add to the boot menu list in whatever position you want it in. (uncomment by removing the #’s)

# title Windows 95/98/NT/2000
# root (hd0,0)
# makeactive
# chainloader +1

Note that you should also verify that hd0,0 is the correct location for Windows. If you had installed Windows on the 4th partition on the drive, then you should change it to (hd0,3)

Tuesday, February 9, 2010

Ubuntu JavaInstallation

Prerequisites

To install OpenJDK, you must have the Universe repository enabled and be running Ubuntu 8.04 or later.

/!\ To install proprietary Java, you must have the Multiverse repository enabled. Keep in mind that this repository is different from the backports Multiverse repository. That is, do not simply uncomment the "multiverse" line for backports. Instead, you will need to add "multiverse" to the existing main line in /etc/apt/sources.list.

To install IcedTea, you must have the Universe repository enabled and be running Ubuntu 7.10 or later.

For more information about the Multiverse and Universe repositories, please visit the following guide:

Managing Repositories.

Introduction

Java is a technology from Sun Microsystems. There are several implementations, of which five will be talked about here:

*

OpenJDK: The primary goal of the OpenJDK project is to produce an open-source implementation of the Java SE 6 Platform. As of Ubuntu 8.04, it is located in the universe repository.
*

Free Java: GNU classpath and others, these are already included in Ubuntu as of Ubuntu 5.10. These implementations are available for all supported Ubuntu architectures.
*

IcedTea: IcedTea is a build of OpenJDK from Red Hat that is composed of free software. As of Ubuntu 7.10, it is located in the universe repository.
*

Sun Java: Sun Java is the reference implementation. As of Ubuntu 6.06, it is included in multiverse
*

Blackdown Java: Blackdown Java, a port of the Sun JDK to Linux which pre-dates Sun's official port, is included in multiverse of Ubuntu 5.10 and later
*

IBM Java: IBM Java is a reimplementation with a Just-In-Time Compiler. It is only available from IBM's website. It is the preferred Java solution on PowerPC machines, and instructions for Ubuntu on PowerPC are below. It is also available for i386 and AMD64, but use on such installations is not discussed here.

Java is also very different based on your processor architecture. Most computers are i386, Mac are PowerPC (although newer MacBooks and MacBook Pros are i386) and some newer computers are AMD64. Use the following chart to see which version of Java you should install:

Release



Free Java


Proprietary Java



8.04


7.04


6.10


6.06


7.04


6.10


6.06

i386


OpenJDK or GCJ


Sun Java

PPC


GCJ


IBM Java

AMD64


OpenJDK or GCJ


Sun Java *

SPARC


GCJ


-

*

There is no browser plugin for the SPARC platform. On the AMD64 platform, the icedtea-gcjwebplugin is a browser plugin without LiveConnect support. For a more complete plugin, you will have to install a 32bit version of Firefox. See below.
*

Starting with Ubuntu 6.10 (EdgyEft), you can install the experimental java-gcj-compat-plugin from the universe archive. It is available on all architectures. Note however, that the plugin currently runs with no security manager. This means that applets you load can do anything a java application that you download and run can do. Be **very** careful which applets you run.

Installing OpenJDK

OpenJDK is available on Ubuntu 8.04 in the Universe repository. The runtime environment is located in the openjdk-6-jre package.

Installing GCJ

Free Java is already installed in the default installation java-gcj-compat. To install the development environment, install the java-gcj-compat-dev package.

Installing IcedTea

IcedTea is available on Ubuntu 7.10 in the Universe repository. The runtime environment is located in the icedtea-java7-jre package.

Installing Sun Java

Ubuntu 7.04 or later

*

Sun Java6: sun-java6-bin, sun-java6-jre
*

Blackdown Java2 1.4: j2re1.4

Ubuntu 6.06 / 6.10

*

Sun Java5: sun-java5-bin, sun-java5-jre
*

Blackdown Java2 1.4: j2re1.4

Kubuntu 6.06 / 6.10

* Sun Java5: Load up Konsole, and type:

sudo apt-get install sun-java5-bin

Accept the licence agreement that appears.

{i} Note: The license may not come up and will cause the package installation to fail, to fix this, do the following:

* In a terminal, type

sudo apt-get install libqt-perl
sudo dpkg-reconfigure debconf

* The first command will install the needed package for debconf-kde counterpart. The second command will ask a few questions: For the first step, choose "kde". For the second step, choose "high". Then, to fix the packages that did not correctly install, do:

sudo apt-get -f install

* then you are done.

*

Blackdown Java2 1.4: j2re1.4

{i} Note: Scroll down to "Selecting the default Java version" section to enable the JRE you have installed.

Sun Java SDK (Software Development Kit)

Ubuntu 8.04

*

OpenJDK: openjdk-6-jdk

Ubuntu 7.10

*

IcedTea: icedtea-java7-jdk

Ubuntu 7.04

*

Sun Java6: sun-java6-jdk

Ubuntu 6.06 / 6.10

*

Sun Java5: sun-java5-jdk

Kubuntu 6.06 / 6.10

* Sun Java5: Load up Konsole, and type:

sudo apt-get install sun-java5-jdk

Accept the licence agreement that appears.

*

Blackdown Java2 1.4 packages: Install the j2re1.4 package, available in the multiverse repositories. Install it from the Applications -> Add/Remove... menu, or install the j2re1.4 package.

Selecting the default Java version

If you want to use Sun's Java instead of the open source GIJ (GNU Java bytecode interpreter) you need to set it as default. To list installed JVMs:

update-java-alternatives -l

To select, for example, Sun's JVM as provided in Ubuntu 6.06, run:

sudo update-java-alternatives -s java-1.5.0-sun

You should also edit /etc/jvm and move /usr/lib/jvm/java-1.5.0-sun to the top of JVMs offered.

Adding JDK 1.4 as an alternative

The Blackdown JDK 1.4 does not automatically appear as an alternative upon installation. In order to make it appear, you'll need to create a file such as /usr/lib/jvm/.java-1.4.2-sun.jinfo as described in the man page for update-java-alternatives. Note: the default install location is /usr/lib/j2se/1.4

Manual method: Run:

sudo update-alternatives --config java

and select your preference from the list.

{i} Note: You probably want to do the same with jar, javac, javadoc, javah, javap and javaws:

sudo update-alternatives --config jar

To get common java applications (installed using .deb-packages) to run under your JVM of choice, make sure you also edit the JVM configuration file:

sudo nano /etc/jvm

and add the line:

/usr/lib/j2sdk1.5-sun

Packages such as ant starts the first JVM found in this file.

Running Java under Ubuntu

In order to run Java programs and Java applets, you must have a Java environment installed. The GCJ flavor of Java is installed as default, and is usually fine for most purposes. If it is not installed, JavaInstallation describes how to install some opensource flavors of Java. You may, however, have a need to run the Sun flavor of Java if something does not work correctly.

To get Sun Java under Ubuntu 7.04 or later running on Intel or PowerPC platform, you should enable the Universe repository in Add/Remove programs, and install either the openjdk-6-jre package or the sun-java6-bin package. (Note: PowerPC version is slow).

To get Sun Java under Ubuntu 6.06 or 6.10 running on Intel x86 platform, you should enable the Universe repository in Add/Remove programs, and install the sun-java5-bin package.

Note: The same commands will work under Xubuntu/Kubuntu (using Add/Remove or the Adept Package Installer).

Choosing the default Java to use

Just installing new Java flavours does not change the default Java pointed to by /usr/bin/java. You must explicitly set this:

* Open a Terminal window
*

Run sudo update-java-alternatives -l to see the current configuration and possibilities.
*

Run sudo update-java-alternatives -s XXXX to set the XXX java version as default. For Sun Java 6 this would be sudo update-java-alternatives -s java-6-sun
*

Run java -version to ensure that the correct version is being called.

You can also use the following command to interactively make the change;

* Open a Terminal window
*

Run sudo update-alternatives --config java
* Follow the onscreen prompt

Ubuntu Linux Install Sun Java Development Kit ( JDK ) and Java Runtime Environment ( JRE )

=> sun-java6-bin : Sun Java Runtime Environment (JRE) 6

=> sun-java6-demo : Sun Java Development Kit (JDK) 6 demos

=> sun-java6-jdk : Sun Java Development Kit (JDK) 6

=> sun-java6-jre : Sun Java Runtime Environment (JRE) 6

Install Sun Java 6

To install proprietary Java, you must have the Multiverse repository enabled. Click on System > Administration > Software Source > Select Multisource > Close
Adding the Universe and Multiverse Repositories

Open a shell prompt (terminal) and type the following to install JDK and JRE:
$ sudo apt-get install sun-java6-bin sun-java6-jre sun-java6-jdk
Setup the default Java version

Ubuntu Linux comes with update-java-alternatives utility to updates all alternatives belonging to one runtime or development kit for the Java language. To select, Sun's JVM as provided in Ubuntu 7.10, enter:
$ sudo update-java-alternatives -s java-6-sun
You also need to edit a file called /etc/jvm. This file defines the default system JVM search order. Each JVM should list their JAVA_HOME compatible directory in this file. The default system JVM is the first one available from top to bottom. Open /etc/jvm
$ sudo vi /etc/jvm
Make sure /usr/lib/jvm/java-6-sun is added to the top of JVM list
/usr/lib/jvm/java-6-sun
At the end your file should read as follows:
/usr/lib/jvm/java-6-sun
/usr/lib/jvm/java-gcj
/usr/lib/jvm/ia32-java-1.5.0-sun
/usr/lib/jvm/java-1.5.0-sun
/usr
Save and close the file.
Setup the environment variable

You also need to setup JAVA_HOME and PATH variable. Open your $HOME/.bash_profile or /etc/profile (system wide) configuration. Open your .bash_profile file:
$ vi $HOME/.bash_profile
Append following line:
export JAVA_HOME=/usr/lib/jvm/java-6-sun
export PATH=$PATH:$JAVA_HOME/bin
Save and close the file.
Test your new JDK

Type the following command to display version:
$ java -version
Output:

java version "1.6.0_03"
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Java HotSpot(TM) Server VM (build 1.6.0_03-b05, mixed mode)