old-www/HOWTO/Remote-Serial-Console-HOWTO/configure-boot-loader-grub....

768 lines
13 KiB
HTML

<HTML
><HEAD
><TITLE
>Configure the GRUB boot
loader</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="Remote Serial Console HOWTO"
HREF="index.html"><LINK
REL="UP"
TITLE="Configure the boot loader"
HREF="configure-boot-loader.html"><LINK
REL="PREVIOUS"
TITLE="Configure the LILO boot
loader"
HREF="configure-boot-loader-lilo.html"><LINK
REL="NEXT"
TITLE="Configure the SYSLINUX boot
loader"
HREF="configure-boot-loader-syslinux.html"></HEAD
><BODY
CLASS="SECTION"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Remote Serial Console HOWTO</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="configure-boot-loader-lilo.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 4. Configure the boot loader</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="configure-boot-loader-syslinux.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECTION"
><H1
CLASS="SECTION"
><A
NAME="CONFIGURE-BOOT-LOADER-GRUB"
></A
>4.2. Configure the <SPAN
CLASS="APPLICATION"
>GRUB</SPAN
> boot
loader</H1
><P
><SPAN
CLASS="APPLICATION"
>GRUB</SPAN
> is a boot loader designed to
boot a wide range of operating systems from a wide range of
filesystems. <SPAN
CLASS="APPLICATION"
>GRUB</SPAN
> is becoming popular
due to the increasing number of possible root filesystems that can
Linux can reside upon.</P
><P
><SPAN
CLASS="APPLICATION"
>GRUB</SPAN
> is documented in a
<SPAN
CLASS="ABBREV"
>GNU</SPAN
> info file. Type <B
CLASS="COMMAND"
>info grub</B
>
to view the documentation.</P
><P
>The <SPAN
CLASS="APPLICATION"
>GRUB</SPAN
> configuration file is
<TT
CLASS="FILENAME"
>/boot/grub/menu.lst</TT
>. Some distributions use
another configuration file; for example, <SPAN
CLASS="PRODUCTNAME"
>Red Hat
Linux</SPAN
> uses the file
<TT
CLASS="FILENAME"
>/boot/grub/grub.conf</TT
>.</P
><P
><SPAN
CLASS="APPLICATION"
>GRUB</SPAN
> configuration files are
interpreted. Syntax errors will not be detected until the machine
is rebooted, so take care not to make typing errors.</P
><P
>Edit the <SPAN
CLASS="APPLICATION"
>GRUB</SPAN
> configuration file
and remove any <B
CLASS="COMMAND"
>splashimage</B
> entries. If these
entries are not removed <SPAN
CLASS="APPLICATION"
>GRUB</SPAN
> 0.90
behaves very oddly, transferring control between the serial console
and the attached monitor and keyboard.</P
><P
>If there is not already a <B
CLASS="COMMAND"
>password</B
> command
in the <SPAN
CLASS="APPLICATION"
>GRUB</SPAN
> configuration file then
create a hashed password, see <A
HREF="configure-boot-loader-grub.html#CONFIGURE-BOOT-LOADER-GRUB-MD5"
>Figure 4-4</A
>. The password should be
good, as it can be used to gain <SPAN
CLASS="SYSTEMITEM"
>root</SPAN
> access.</P
><DIV
CLASS="FIGURE"
><A
NAME="CONFIGURE-BOOT-LOADER-GRUB-MD5"
></A
><P
><B
>Figure 4-4. Using <B
CLASS="COMMAND"
>md5crypt</B
> to create a hashed
password for <SPAN
CLASS="APPLICATION"
>GRUB</SPAN
> </B
></P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
><TT
CLASS="PROMPT"
>grub&#62;</TT
> <B
CLASS="COMMAND"
>md5crypt</B
>
<TT
CLASS="PROMPT"
>Password</TT
>: <TT
CLASS="USERINPUT"
><B
>**********</B
></TT
>
<TT
CLASS="COMPUTEROUTPUT"
>Encrypted: $1$U$JK7xFegdxWH6VuppCUSIb.</TT
></PRE
></FONT
></TD
></TR
></TABLE
></DIV
><P
>Use that hashed password in the
<SPAN
CLASS="APPLICATION"
>GRUB</SPAN
> configuration file, this is shown
in <A
HREF="configure-boot-loader-grub.html#CONFIGURE-BOOT-LOADER-GRUB-PASSWORD"
>Figure 4-5</A
>.</P
><DIV
CLASS="FIGURE"
><A
NAME="CONFIGURE-BOOT-LOADER-GRUB-PASSWORD"
></A
><P
><B
>Figure 4-5. <SPAN
CLASS="APPLICATION"
>GRUB</SPAN
> configuration to require a
password</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="PROGRAMLISTING"
>password --md5 $1$U$JK7xFegdxWH6VuppCUSIb.</PRE
></FONT
></TD
></TR
></TABLE
></DIV
><P
>Define the serial port and configure
<SPAN
CLASS="APPLICATION"
>GRUB</SPAN
> to use the serial port, as shown in
<A
HREF="configure-boot-loader-grub.html#CONFIGURE-BOOT-LOADER-GRUB-SERIAL"
>Figure 4-6</A
>.</P
><DIV
CLASS="FIGURE"
><A
NAME="CONFIGURE-BOOT-LOADER-GRUB-SERIAL"
></A
><P
><B
>Figure 4-6. <SPAN
CLASS="APPLICATION"
>GRUB</SPAN
> configuration for serial
console</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="PROGRAMLISTING"
>serial --unit=0 --speed=9600 --word=8 --parity=no --stop=1
terminal serial</PRE
></FONT
></TD
></TR
></TABLE
></DIV
><P
><TT
CLASS="LITERAL"
>--unit</TT
> is the number of the
serial port, counting from zero, unit 0 being
<TT
CLASS="LITERAL"
>COM1</TT
>.</P
><P
>Note that the values of
<TT
CLASS="LITERAL"
>--parity</TT
> are spelt out in full:
<TT
CLASS="LITERAL"
>no</TT
>, <TT
CLASS="LITERAL"
>even</TT
> and
<TT
CLASS="LITERAL"
>odd</TT
>. The common abbreviations
<TT
CLASS="LITERAL"
>n</TT
>, <TT
CLASS="LITERAL"
>e</TT
> and <TT
CLASS="LITERAL"
>o</TT
>
are <EM
>not</EM
> accepted.</P
><P
>If there is mysteriously no output on the serial port then
suspect a syntax error in the <B
CLASS="COMMAND"
>serial</B
> or
<B
CLASS="COMMAND"
>terminal</B
> commands.</P
><P
>If you also want to use and attached monitor and keyboard as
well as the serial port to control the
<SPAN
CLASS="APPLICATION"
>GRUB</SPAN
> boot loader then use the
alternative configuration in <A
HREF="configure-boot-loader-grub.html#CONFIGURE-BOOT-LOADER-GRUB-SERIALCONSOLE"
>Figure 4-7</A
>.</P
><DIV
CLASS="FIGURE"
><A
NAME="CONFIGURE-BOOT-LOADER-GRUB-SERIALCONSOLE"
></A
><P
><B
>Figure 4-7. <SPAN
CLASS="APPLICATION"
>GRUB</SPAN
> configuration for serial
console and attached monitor and keybaord console</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="PROGRAMLISTING"
>password --md5 $1$U$JK7xFegdxWH6VuppCUSIb.
serial --unit=0 --speed=9600 --word=8 --parity=no --stop=1
terminal --timeout=10 serial console</PRE
></FONT
></TD
></TR
></TABLE
></DIV
><P
>When both the serial port and the attached monitor and
keyboard are configured they will both ask for a key to be pressed
until the timeout expires. If a key is pressed then the boot menu
is displayed to that device. Disconcertingly, the other device
sees nothing.</P
><P
>If no key is pressed then the boot menu is displayed on the
whichever of <TT
CLASS="LITERAL"
>serial</TT
> or
<TT
CLASS="LITERAL"
>console</TT
> is listed first in the
<B
CLASS="COMMAND"
>terminal</B
> command. After the timeout set by the
<B
CLASS="COMMAND"
>timeout</B
> the default option set by
<B
CLASS="COMMAND"
>default</B
> is booted.</P
><DIV
CLASS="FIGURE"
><A
NAME="CONFIGURE-BOOT-LOADER-GRUB-PRESS"
></A
><P
><B
>Figure 4-8. GRUB output to default device when configured for serial
and attached monior output</B
></P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
><TT
CLASS="COMPUTEROUTPUT"
>Press any key to continue.
Press any key to continue.
Press any key to continue.
Press any key to continue.
Press any key to continue.
Press any key to continue.
Press any key to continue.
Press any key to continue.
Press any key to continue.
Press any key to continue.
GRUB version 0.90 (639K lower / 162752K upper memory)
+-------------------------------------------------------------------------+
| [ Red Hat Linux (2.4.9-21) ] |
| |
| |
+-------------------------------------------------------------------------+
Use the ^ and v keys to select which entry is highlighted.
Press enter to boot the selected OS or 'p' to enter a
password to unlock the next set of features.
The highlighted entry will be booted automatically in 10 seconds.</TT
></PRE
></FONT
></TD
></TR
></TABLE
></DIV
><P
>If you are not using a <SPAN
CLASS="ACRONYM"
>VT100</SPAN
> terminal then
the cursor keys may not work to select a
<SPAN
CLASS="APPLICATION"
>GRUB</SPAN
> menu item. The instructions shown
in <A
HREF="configure-boot-loader-grub.html#CONFIGURE-BOOT-LOADER-GRUB-PRESS"
>Figure 4-8</A
> are literally
correct: <SPAN
CLASS="GUILABEL"
>Use the ^ and v keys</SPAN
> means that the
caret key
(<B
CLASS="KEYCAP"
>Shift</B
>-<B
CLASS="KEYCAP"
>6</B
>)
moves the cursor up and letter vee key (<B
CLASS="KEYCAP"
>V</B
>) moves
the cursor down.</P
><P
>Note when configuring <SPAN
CLASS="APPLICATION"
>GRUB</SPAN
> that
there are two timeouts involved. <TT
CLASS="COMPUTEROUTPUT"
>Press any key to
continue</TT
> is printed for <B
CLASS="COMMAND"
>terminal
--timeout=10</B
> seconds, waiting for someone on the keyboard
or terminal to press a key to get the input focus. Then the menu
is displayed for <B
CLASS="COMMAND"
>timeout 10</B
> seconds before the
default boot option is taken.</P
><P
>If the terminal attached to the serial port is not a real or
emulated <SPAN
CLASS="PRODUCTNAME"
>VT100</SPAN
>, then force
<SPAN
CLASS="APPLICATION"
>GRUB</SPAN
> to use it's command line interface.
This interface is much more difficult to use than
<SPAN
CLASS="APPLICATION"
>GRUB</SPAN
>'s menu interface; however, the
command line interface does not assume the
<SPAN
CLASS="PRODUCTNAME"
>VT100</SPAN
>'s terminal language.</P
><DIV
CLASS="FIGURE"
><A
NAME="CONFIGURE-BOOT-LOADER-GRUB-DUMB"
></A
><P
><B
>Figure 4-9. <SPAN
CLASS="APPLICATION"
>GRUB</SPAN
> configuration for command
line interface for terminals other than
<SPAN
CLASS="PRODUCTNAME"
>VT100</SPAN
></B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="PROGRAMLISTING"
>terminal --timeout=10 --dumb serial console</PRE
></FONT
></TD
></TR
></TABLE
></DIV
><P
>This <I
CLASS="CITETITLE"
>HOWTO</I
> does not discuss the use of
<SPAN
CLASS="APPLICATION"
>GRUB</SPAN
>'s command line. It is far too
complex and error-prone to recommend for use on production
machines. Wizards will know to consult
<SPAN
CLASS="APPLICATION"
>GRUB</SPAN
>'s <SPAN
CLASS="APPLICATION"
>info</SPAN
>
manual for the commands required to boot the kernel.</P
><P
><SPAN
CLASS="APPLICATION"
>GRUB</SPAN
>'s menu's can be edited
interactively after <B
CLASS="KEYCAP"
>P</B
> is pressed and the password
supplied. A better approach is to add menu items to boot the
machine into alternative run levels. A sample configuration
showing a menu entry for the default run level and an alternative
menu entry for single user mode (run level
<I
CLASS="WORDASWORD"
>s</I
>) is shown in <A
HREF="configure-boot-loader-grub.html#CONFIGURE-BOOT-LOADER-GRUB-RUNLEVEL"
>Figure 4-10</A
>. Remember to use
the <B
CLASS="COMMAND"
>lock</B
> command to require a password for
single user mode, as single user mode does not ask for a
<SPAN
CLASS="SYSTEMITEM"
>Linux</SPAN
> password.</P
><DIV
CLASS="FIGURE"
><A
NAME="CONFIGURE-BOOT-LOADER-GRUB-RUNLEVEL"
></A
><P
><B
>Figure 4-10. Adding a single user mode option to the
<SPAN
CLASS="APPLICATION"
>GRUB</SPAN
> menu</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="PROGRAMLISTING"
>password --md5 $1$U$JK7xFegdxWH6VuppCUSIb.
default 0
title Red Hat Linux (2.4.9-21)
root (hd0,0)
kernel /vmlinuz-2.4.9-21 ro root=/dev/hda6
initrd /initrd-2.4.9-21.img
title Red Hat Linux (2.4.9-21) single user mode
lock
root (hd0,0)
kernel /vmlinuz-2.4.9-21 ro root=/dev/hda6 s
initrd /initrd-2.4.9-21.img</PRE
></FONT
></TD
></TR
></TABLE
></DIV
><P
>File names in the <B
CLASS="COMMAND"
>kernel</B
> and
<B
CLASS="COMMAND"
>initrd</B
> commands are relative to the
<SPAN
CLASS="APPLICATION"
>GRUB</SPAN
> installation directory, which is
usually <TT
CLASS="FILENAME"
>/boot/grub</TT
>. So
<TT
CLASS="FILENAME"
>/vmlinuz-2.4.9-21</TT
> is actually the file
<TT
CLASS="FILENAME"
>/boot/grub/vmlinuz-2.4.9-21</TT
>.</P
><P
><SPAN
CLASS="APPLICATION"
>GRUB</SPAN
> is now configured to use the
serial console. The kernels booted from
<SPAN
CLASS="APPLICATION"
>GRUB</SPAN
> are yet to be configured to use the
serial console.</P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="configure-boot-loader-lilo.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="configure-boot-loader-syslinux.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Configure the <SPAN
CLASS="APPLICATION"
>LILO</SPAN
> boot
loader</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="configure-boot-loader.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Configure the <SPAN
CLASS="APPLICATION"
>SYSLINUX</SPAN
> boot
loader</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>