Difference between pages "Grub-install" and "Installing Java"

From Funtoo
(Difference between pages)
Jump to: navigation, search
(I corrected a typo.)
 
(Sources)
 
Line 1: Line 1:
This is an annotation about what grub-install does. This is based on the <code>=sys-boot/grub-1.98-r1</code> version.
+
== What is Java? What purpose does it serve? ==
 +
==== Definition ====
 +
"Java is a programming language and computing platform first released by Sun Microsystems in 1995. There are lots of applications and websites that will not work unless you have Java installed, and more are created every day. Java is fast, secure, and reliable. From laptops to datacenters, game consoles to scientific supercomputers, cell phones to the Internet, Java is everywhere!" ([http://www.java.com/en/download/faq/whatis_java.xml Oracle page on Java])
 +
== Installing java ==
 +
==== Editing your make.conf ====
 +
To tell portage that we would like java pulled in the next time it is updated, we need to do the following:
 +
<console>
 +
##r## # ##b##nano /etc/portage/make.conf
 +
</console>
 +
Running that command should present you with a file containing something similar to this:
 +
[[File:Make conf example.png|thumbnail|left|An example make.conf]]
  
<syntaxhighlight lang="bash">
+
In the file, if it does not exist, create a line like the following:
#! /bin/sh
+
<console>
</syntaxhighlight>
+
##b##USE="java"
This tells the Linux kernel that this script will be executed with <code>/bin/sh</code>.
+
</console>
<syntaxhighlight lang="bash">
+
Press Ctrl+X , then y, then enter to write the changes to the file.
  
# Install GRUB on your drive.
+
==== Emerging java ====
# Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009  Free Software Foundation, Inc.
+
To install java, run the following command:
#
+
<console>
# GRUB is free software: you can redistribute it and/or modify
+
##r## # ##b##emerge --ask --update --newuse --deep @world
# it under the terms of the GNU General Public License as published by
+
# the Free Software Foundation, either version 3 of the License, or
+
# (at your option) any later version.
+
#
+
# GRUB is distributed in the hope that it will be useful,
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+
# GNU General Public License for more details.
+
#
+
# You should have received a copy of the GNU General Public License
+
# along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+
</syntaxhighlight>
+
This section tells that this script falls under the GNU General Public License.
+
<syntaxhighlight lang="bash">
+
  
# Initialize some variables.
+
##g##These are the packages that would be merged, in order:
transform="s,x,x,"
+
  
prefix=/usr
+
Calculating dependencies... done!
exec_prefix=${prefix}
+
[ebuild  N    ] dev-java/java-config-wrapper-0.16  8 kB
sbindir=/sbin
+
[ebuild  N    ] sys-apps/baselayout-java-0.1.0  71 kB
bindir=/bin
+
[ebuild  N    ] dev-java/java-config-2.2.0-r1000:2  PYTHON_ABIS="2.7 3.3 -2.6 -3.1 -3.2 (-3.4)" 51 kB
libdir=/lib64
+
[ebuild  N    ] app-admin/eselect-java-0.1.0  71 kB
PACKAGE_NAME=GRUB
+
[ebuild  N    ] dev-java/icedtea-bin-7.2.3.9:7  USE="X alsa cups -cjk -doc -examples -nsplugin -source" 47,781 kB
PACKAGE_TARNAME=grub
+
[ebuild  N    ] virtual/jdk-1.7.0:1.7  0 kB
PACKAGE_VERSION=1.98
+
[ebuild  N    ] virtual/jre-1.7.0:1.7  0 kB
target_cpu=i386
+
Would you like to merge these packages? [Yes/No] ##b##yes
platform=pc
+
</console>
host_os=linux-gnu
+
font=/usr/share/grub/ascii.pf2
+
pkglibdir=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${transform}`
+
</syntaxhighlight>
+
These are some variables set when Grub was configured for the system.
+
<syntaxhighlight lang="bash">
+
  
grub_setup=${sbindir}/`echo grub-setup | sed ${transform}`
+
== Testing to see if it emerged ==
if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] || [ "${target_cpu}-${platform}" = "mips-yeeloong" ] ; then
+
To check that java installed on your system, run the following command:
    grub_mkimage=${bindir}/`echo grub-mkimage | sed ${transform}`
+
<console>
else
+
##b##java -version
    grub_mkimage=${bindir}/`echo grub-mkelfimage | sed ${transform}`
+
</console>
fi
+
If you get something like this, you are ready to use java!:
grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}`
+
<console>
grub_probe=${sbindir}/`echo grub-probe | sed ${transform}`
+
java version "1.7.0_21"OpenJDK Runtime Environment (IcedTea 2.3.9) (Gentoo build 1.7.0_21-b02)OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)
grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}`
+
</console>
rootdir=
+
== Using the java command ==
grub_prefix=`echo /boot/grub | sed ${transform}`
+
==== Overview of the command ====
modules=
+
The java command can be run like so:
 +
* '''java [options] class [argument ...]'''
 +
* '''java [options] -jar file.jar [argument ...]'''
  
install_device=
+
==== Example command usage ====
no_floppy=
+
Compiling code:
force_lba=
+
<console>
recheck=no
+
##bl##$ ##b##javac -d bin -sourcepath src -cp lib/lib1.jar;lib/lib2.jar src/com/example/Application.java
debug=no
+
</console>
  
if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then
+
Running code:
    disk_module=biosdisk
+
<console>
elif [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then
+
##bl##$ ##b##java -cp bin;lib/lib1.jar;lib/lib2.jar com.example.Application
    disk_module=
+
</console>
else
+
    disk_module=ata
+
fi
+
</syntaxhighlight>
+
Further variables were initialized some of which were done so in a platform-dependent manner such as <code>disk_module</code> being set to <code>biosdisk</code> on i386-pc systems.
+
<syntaxhighlight lang="bash">
+
  
# Usage: usage
+
Running a jarfile:
# Print the usage.
+
<console>
usage () {
+
##bl##$ ##b##java -jar Application.jar
    cat <<EOF
+
</console>
Usage: grub-install [OPTION] install_device
+
Install GRUB on your drive.
+
  
  -h, --help              print this message and exit
+
== Sources ==
  -v, --version          print the version information and exit
+
([http://www.sergiy.ca/how-to-compile-and-launch-java-code-from-command-line/ Information provided for example command usage])
  --modules=MODULES      pre-load specified modules MODULES
+
  --root-directory=DIR    install GRUB images under the directory DIR
+
                          instead of the root directory
+
  --grub-setup=FILE      use FILE as grub-setup
+
  --grub-mkimage=FILE    use FILE as grub-mkimage
+
  --grub-mkdevicemap=FILE use FILE as grub-mkdevicemap
+
  --grub-probe=FILE      use FILE as grub-probe
+
  --no-floppy            do not probe any floppy drive
+
  --recheck              probe a device map even if it already exists
+
  --force                install even if problems are detected
+
EOF
+
if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then
+
    cat <<EOF
+
  --disk-module=MODULE    disk module to use
+
EOF
+
fi
+
if [ "${target_cpu}-${platform}" = "mips-yeeloong" ] ; then
+
    cat <<EOF
+
  --font=FILE            font file to use
+
EOF
+
fi
+
    cat <<EOF
+
  
INSTALL_DEVICE can be a GRUB device name or a system device filename.
+
[[Category:System]]
 
+
grub-install copies GRUB images into /boot/grub (or /grub on NetBSD and
+
OpenBSD), and uses grub-setup to install grub into the boot sector.
+
 
+
If the --root-directory option is used, then grub-install will copy
+
images into the operating system installation rooted at that directory.
+
 
+
Report bugs to <bug-grub@gnu.org>.
+
EOF
+
}
+
</syntaxhighlight>
+
This sets up the usage message that <code>grub-install</code> prints if it doesn't understand what arguments it was given.
+
<syntaxhighlight lang="bash">
+
# Check the arguments.
+
for option in "$@"; do
+
    case "$option" in
+
    -h | --help)
+
usage
+
exit 0 ;;
+
    -v | --version)
+
echo "grub-install (GNU GRUB ${PACKAGE_VERSION})"
+
exit 0 ;;
+
    --modules=*)
+
modules=`echo "$option" | sed 's/--modules=//'` ;;
+
    --font=*)
+
font=`echo "$option" | sed 's/--font=//'` ;;
+
    --root-directory=*)
+
rootdir=`echo "$option" | sed 's/--root-directory=//'` ;;
+
    --grub-setup=*)
+
grub_setup=`echo "$option" | sed 's/--grub-setup=//'` ;;
+
    --grub-mkimage=*)
+
grub_mkimage=`echo "$option" | sed 's/--grub-mkimage=//'` ;;
+
    --grub-mkdevicemap=*)
+
grub_mkdevicemap=`echo "$option" | sed 's/--grub-mkdevicemap=//'` ;;
+
    --grub-probe=*)
+
grub_probe=`echo "$option" | sed 's/--grub-probe=//'` ;;
+
    --no-floppy)
+
no_floppy="--no-floppy" ;;
+
    --recheck)
+
recheck=yes ;;
+
    --disk-module=*)
+
if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then
+
          disk_module=`echo "$option" | sed 's/--disk-module=//'`
+
        fi ;;
+
    # This is an undocumented feature...
+
    --debug)
+
debug=yes ;;
+
    -f | --force)
+
        setup_force="--force" ;;
+
    -*)
+
echo "Unrecognized option \`$option'" 1>&2
+
usage
+
exit 1
+
;;
+
    *)
+
if test "x$install_device" != x; then
+
    echo "More than one install_devices?" 1>&2
+
    usage
+
    exit 1
+
fi
+
install_device="${option}" ;;
+
    esac
+
done
+
</syntaxhighlight>
+
This section parses the command line arguments and sets variables appropriately.
+
<syntaxhighlight lang="bash">
+
 
+
# for make_system_path_relative_to_its_root()
+
. ${libdir}/grub/grub-mkconfig_lib
+
 
+
if test "x$install_device" = x && test "${target_cpu}-${platform}" != "mips-yeeloong"; then
+
    echo "install_device not specified." 1>&2
+
    usage
+
    exit 1
+
fi
+
</syntaxhighlight>
+
 
+
This block ensures that a destination device was specified to <code>grub-install</code> as an argument.
+
 
+
<syntaxhighlight lang="bash">
+
 
+
# If the debugging feature is enabled, print commands.
+
setup_verbose=
+
if test $debug = yes; then
+
    set -x
+
    setup_verbose="--verbose"
+
fi
+
</syntaxhighlight>
+
 
+
This block makes <code>grub-install</code> more verbose if grub was built with debugging enabled.
+
 
+
<syntaxhighlight lang="bash">
+
 
+
# Initialize these directories here, since ROOTDIR was initialized.
+
case "$host_os" in
+
netbsd* | openbsd*)
+
    # Because /boot is used for the boot block in NetBSD and OpenBSD, use /grub
+
    # instead of /boot/grub.
+
    grub_prefix=`echo /grub | sed ${transform}`
+
    bootdir=${rootdir}
+
    ;;
+
*)
+
    # Use /boot/grub by default.
+
    bootdir=${rootdir}/boot
+
    ;;
+
esac
+
</syntaxhighlight>
+
Set up the location where Grub will be installed.
+
<syntaxhighlight lang="bash">
+
 
+
grubdir=${bootdir}/`echo grub | sed ${transform}`
+
device_map=${grubdir}/device.map
+
 
+
grub_probe="${grub_probe} --device-map=${device_map}"
+
 
+
# Check if GRUB is installed.
+
if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then
+
    set $grub_setup dummy
+
    if test -f "$1"; then
+
        :
+
    else
+
        echo "$1: Not found." 1>&2
+
        exit 1
+
    fi
+
fi
+
 
+
set $grub_mkimage dummy
+
if test -f "$1"; then
+
    :
+
else
+
    echo "$1: Not found." 1>&2
+
    exit 1
+
fi
+
 
+
set $grub_mkdevicemap dummy
+
if test -f "$1"; then
+
    :
+
else
+
    echo "$1: Not found." 1>&2
+
    exit 1
+
fi
+
</syntaxhighlight>
+
These blocks ensure that grub components are installed.
+
<syntaxhighlight lang="bash">
+
# Create the GRUB directory if it is not present.
+
test -d "$bootdir" || mkdir "$bootdir" || exit 1
+
test -d "$grubdir" || mkdir "$grubdir" || exit 1
+
 
+
# If --recheck is specified, remove the device map, if present.
+
if test $recheck = yes; then
+
    rm -f $device_map
+
fi
+
 
+
# Create the device map file if it is not present.
+
if test -f "$device_map"; then
+
    :
+
else
+
    # Create a safe temporary file.
+
    test -n "$mklog" && log_file=`$mklog`
+
 
+
    $grub_mkdevicemap --device-map=$device_map $no_floppy || exit 1
+
fi
+
</syntaxhighlight>
+
This creates the device map by calling <code>grub-mkdevicemap</code>. That program will create a mapping from the Grub device names to the Linux device nodes.
+
<syntaxhighlight lang="bash">
+
 
+
# Make sure that there is no duplicated entry.
+
tmp=`sed -n '/^([fh]d[0-9]*)/s/\(^(.*)\).*/\1/p' $device_map \
+
    | sort | uniq -d | sed -n 1p`
+
if test -n "$tmp"; then
+
    echo "The drive $tmp is defined multiple times in the device map $device_map" 1>&2
+
    exit 1
+
fi
+
</syntaxhighlight>
+
This does some sanity checks on the device map file in case it has been manually corrected in an erroneous way.
+
<syntaxhighlight lang="bash">
+
 
+
# Copy the GRUB images to the GRUB directory.
+
for file in ${grubdir}/*.mod ${grubdir}/*.lst ${grubdir}/*.img ${grubdir}/efiemu??.o; do
+
    if test -f $file && [ "`basename $file`" != menu.lst ]; then
+
rm -f $file || exit 1
+
    fi
+
done
+
for file in ${pkglibdir}/*.mod ${pkglibdir}/*.lst; do
+
    cp -f $file ${grubdir} || exit 1
+
done
+
if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then
+
    for file in ${pkglibdir}/*.img ${pkglibdir}/efiemu??.o; do
+
if test -f $file; then
+
    cp -f $file ${grubdir} || exit 1
+
fi
+
    done
+
fi
+
 
+
# Copy gettext files
+
mkdir -p ${grubdir}/locale/
+
for file in ${grubdir}/locale/*.mo ${pkglibdir}/locale/*.mo; do
+
    if test -f "$file"; then
+
        cp -f "$file" ${grubdir}/locale/
+
    fi
+
done
+
</syntaxhighlight>
+
This copies grub components and its localization files to the [[The_Root_Filesystem#.2Fboot_:_Static_files_of_the_boot_loader|boot]] directory.
+
<syntaxhighlight lang="bash">
+
 
+
# Write device to a variable so we don't have to traverse /dev every time.
+
grub_device=`$grub_probe --target=device ${grubdir}`
+
 
+
if ! test -f ${grubdir}/grubenv; then
+
    $grub_editenv ${grubdir}/grubenv create
+
fi
+
 
+
# Create the core image. First, auto-detect the filesystem module.
+
fs_module=`$grub_probe --target=fs --device ${grub_device}`
+
if test "x$fs_module" = x -a "x$modules" = x; then
+
    echo "Auto-detection of a filesystem module failed." 1>&2
+
    echo "Please specify the module with the option \`--modules' explicitly." 1>&2
+
    exit 1
+
fi
+
 
+
# Then the partition map module.  In order to support partition-less media,
+
# this command is allowed to fail (--target=fs already grants us that the
+
# filesystem will be accessible).
+
partmap_module=`$grub_probe --target=partmap --device ${grub_device} 2> /dev/null`
+
 
+
# Device abstraction module, if any (lvm, raid).
+
devabstraction_module=`$grub_probe --target=abstraction --device ${grub_device}`
+
 
+
# The order in this list is critical.  Be careful when modifying it.
+
modules="$modules $disk_module"
+
modules="$modules $fs_module $partmap_module $devabstraction_module"
+
</syntaxhighlight>
+
Since Grub is modular, it needs the modules that allow it to recognize the boot directory. Consequently, it uses the <code>grub-probe</code> command to determine the modules necessary and adds them to the modules list in an appropriate order. Once it can recognize the boot directory, Grub can dynamically load modules as necessary and read its configuration file.
+
<syntaxhighlight lang="bash">
+
 
+
relative_grubdir=`make_system_path_relative_to_its_root ${grubdir}` || exit 1
+
if [ "x${relative_grubdir}" = "x" ] ; then
+
    relative_grubdir=/
+
fi
+
 
+
prefix_drive=
+
config_opt=
+
 
+
if [ "x${devabstraction_module}" = "x" ] ; then
+
    if [ x"${install_device}" != x ]; then
+
      if echo "${install_device}" | grep -qx "(.*)" ; then
+
        install_drive="${install_device}"
+
      else
+
        install_drive="`$grub_probe --target=drive --device ${install_device}`"
+
      fi
+
      install_drive="`echo ${install_drive} | sed -e s/,[0-9]*[a-z]*//g`"
+
    fi
+
    grub_drive="`$grub_probe --target=drive --device ${grub_device}`"
+
 
+
    # Strip partition number
+
    grub_drive="`echo ${grub_drive} | sed -e s/,[0-9]*[a-z]*//g`"
+
    if [ "$disk_module" = ata ] ; then
+
        # generic method (used on coreboot and ata mod)
+
        uuid="`$grub_probe --target=fs_uuid --device ${grub_device}`"
+
        if [ "x${uuid}" = "x" ] ; then
+
          echo "UUID needed with ata mod, but the filesystem containing ${grubdir} does not support UUIDs." 1>&2
+
          exit 1
+
        fi
+
        echo "search.fs_uuid ${uuid} root " > ${grubdir}/load.cfg
+
echo 'set prefix=($root)'"${relative_grubdir}" >> ${grubdir}/load.cfg
+
config_opt="-c ${grubdir}/load.cfg "
+
        modules="$modules search_fs_uuid"
+
    elif [ "x${grub_drive}" != "x${install_drive}" ] ; then
+
        uuid="`$grub_probe --target=fs_uuid --device ${grub_device}`"
+
        if [ "x${uuid}" = "x" ] ; then
+
          echo "You attempted a cross-disk install, but the filesystem containing ${grubdir} does not support UUIDs." 1>&2
+
          exit 1
+
        fi
+
        echo "search.fs_uuid ${uuid} root " > ${grubdir}/load.cfg
+
echo 'set prefix=($root)'"${relative_grubdir}" >> ${grubdir}/load.cfg
+
config_opt="-c ${grubdir}/load.cfg "
+
        modules="$modules search_fs_uuid"
+
    fi
+
else
+
    prefix_drive=`$grub_probe --target=drive --device ${grub_device}`
+
fi
+
</syntaxhighlight>
+
Partitions can be moved around or initialized in a different order, so Grub wants to identify filesystems by their UUIDs. It also can load from a drive different from where it is installed. It does further probing to determine if the UUID module will be needed and includes it with the other modules.
+
<syntaxhighlight lang="bash">
+
 
+
if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then
+
    $grub_mkimage ${config_opt} --output=${grubdir}/core.img --prefix=${prefix_drive}${relative_grubdir} $modules || exit 1
+
 
+
    # Now perform the installation.
+
    $grub_setup ${setup_verbose} ${setup_force} --directory=${grubdir} --device-map=${device_map} \
+
        ${install_device} || exit 1
+
elif [ "${target_cpu}-${platform}" = "mips-yeeloong" ] ; then
+
    $grub_mkimage ${config_opt} -f ${font} -d ${pkglibdir} -O elf --output=/boot/grub.elf --prefix=${prefix_drive}${relative_grubdir} $modules || exit 1
+
else
+
    $grub_mkimage ${config_opt} -d ${pkglibdir} --output=/boot/multiboot.img --prefix=${prefix_drive}${relative_grubdir} $modules || exit 1
+
fi
+
 
+
echo "Installation finished. No error reported."
+
 
+
# Bye.
+
exit 0
+
</syntaxhighlight>
+
Grub finally uses the information about needed modules to create an image using <code>grub-mkimage</code>. The initial <code>boot.img</code> file is then modified to point to the <code>core.img</code> file that was just generated. That image is then installed to the desired installation device with <code>grub-setup</code>.
+
[[Category:Grub]]
+

Revision as of 01:16, 28 October 2013

What is Java? What purpose does it serve?

Definition

"Java is a programming language and computing platform first released by Sun Microsystems in 1995. There are lots of applications and websites that will not work unless you have Java installed, and more are created every day. Java is fast, secure, and reliable. From laptops to datacenters, game consoles to scientific supercomputers, cell phones to the Internet, Java is everywhere!" (Oracle page on Java)

Installing java

Editing your make.conf

To tell portage that we would like java pulled in the next time it is updated, we need to do the following:

 # nano /etc/portage/make.conf

Running that command should present you with a file containing something similar to this:

File:Make conf example.png
An example make.conf

In the file, if it does not exist, create a line like the following:

USE="java"

Press Ctrl+X , then y, then enter to write the changes to the file.

Emerging java

To install java, run the following command:

 # emerge --ask --update --newuse --deep @world

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild  N     ] dev-java/java-config-wrapper-0.16  8 kB
[ebuild  N     ] sys-apps/baselayout-java-0.1.0  71 kB
[ebuild  N     ] dev-java/java-config-2.2.0-r1000:2  PYTHON_ABIS="2.7 3.3 -2.6 -3.1 -3.2 (-3.4)" 51 kB
[ebuild  N     ] app-admin/eselect-java-0.1.0  71 kB
[ebuild  N     ] dev-java/icedtea-bin-7.2.3.9:7  USE="X alsa cups -cjk -doc -examples -nsplugin -source" 47,781 kB
[ebuild  N     ] virtual/jdk-1.7.0:1.7  0 kB
[ebuild  N     ] virtual/jre-1.7.0:1.7  0 kB
Would you like to merge these packages? [Yes/No] yes

Testing to see if it emerged

To check that java installed on your system, run the following command:

java -version

If you get something like this, you are ready to use java!:

java version "1.7.0_21"OpenJDK Runtime Environment (IcedTea 2.3.9) (Gentoo build 1.7.0_21-b02)OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)

Using the java command

Overview of the command

The java command can be run like so:

  • java [options] class [argument ...]
  • java [options] -jar file.jar [argument ...]

Example command usage

Compiling code:

$ javac -d bin -sourcepath src -cp lib/lib1.jar;lib/lib2.jar src/com/example/Application.java

Running code:

$ java -cp bin;lib/lib1.jar;lib/lib2.jar com.example.Application

Running a jarfile:

$ java -jar Application.jar

Sources

(Information provided for example command usage)