• Aucun résultat trouvé

Working with the GRUB Boot Menu

Dans le document Beginning Ubuntu LTS Server Administration (Page 185-189)

When GRUB runs, it displays a boot menu. (Remember to press the Esc key when booting your server in silent mode.) From the boot menu, you will normally have a choice between the three different sections that are defined in /boot/grub/menu.lst. Normally you will select the first option to boot the server. If you want to use your server for XEN virtualization, select the XEN option from the boot menu. (This option is available only if you selected the XEN soft-ware when installing your server. See Chapter 13 for more on XEN.) The failsafe option is the one you need if you run into trouble, and finally, you can select the Memory Check option if you suspect that you have problems with your server’s RAM.

Note

The failsafe option is more than just a single-user mode. A minimal number of services are loaded in single-user mode, but the kernel is loaded in the normal way. Selecting the failsafe option from the boot menu starts the single-user mode, but the kernel is also started with minimal options to increase chances that you can boot successfully.

If the default startup option from the GRUB menu is not good enough, select the item that you want to start and press the e key. You’ll next see a window like the one in Figure 6-4.

Figure 6-4.After pressing the e key, you can choose from more details when booting your server.

You’ll now see the selected boot item in more detail. Every line in the selected item can be edited from this interface. From this interface, you can perform the following tasks:

• Press b to boot: Use this option if you want to boot your computer with the selected settings.

• Select a line and press the e key to edit the selected line. This option is very convenient if you know that you have made an error in a certain line and you want to fix it.

• Press c to open the GRUB command line. This not-so-intuitive interface allows you to type GRUB-specific commands to tell your server what you want to do. If GRUB still is capable of showing you some boot options, you probably won’t use this option much.

• Press o or O to open a new line. On this line, you can add new options that you want to pass to GRUB while starting your machine. For example, if you want to start your server in troubleshooting mode instead of its normal startup mode, type singleto start single-user mode.

• Press d to remove a line from the menu.

• Press Esc to return to the main menu. From there, you can press Enter to continue booting.

Upstart

After GRUB, the kernel is loaded. In the old days, the kernel loaded the init process that read its configuration file /etc/inittab. Since Ubuntu 7.04, however, a new program is used instead. The Upstart program is responsible for the remainder of the boot procedure. To start your computer, it still uses a boot method that looks a lot like the one that was used in the old days.

The most important part of Upstart is found in the /etc/event.ddirectory. It’s here that Upstart looks for a definition of all the jobs it has to start, and there’s a file for every job. Next, you’ll find a description of all the available jobs:

• control-alt-delete: This job defines what should happen when a user presses the Ctrl+Alt+Del key sequence. The default behavior is that the system will reboot. If you don’t like that, open the /etc/event.d/control-alt-deletefile and replace this shut-down command with something else.

• logd: This job makes sure that the log process /sbin/logdis started. This process ensures that all log messages generated by daemons on your server can be logged.

• rc0-rc6: A Linux computer uses the concept of runlevels, which are used to define what services have to be started when booting your server. The scripts with the names rc0up to rc6define what should happen in the corresponding runlevels. Typically, Ubuntu Server is started in runlevel 2. This master script makes sure that all services normally required in that runlevel are launched. Later in this chapter you’ll learn how to define what happens in a given runlevel.

• rc-default: This script determines the default runlevel, which is normally runlevel 2 on Ubuntu Server. If you want to use something else for the default runlevel, you should create a file with the name /etc/inittabthat contains the following line:

id:N:initdefault:. In this line, Nrefers to the number of the runlevel that you want to activate.

• rcS: This script is used to ensure compatibility with System V startup scripts. Ubuntu Server still uses these old scripts to start services, and you can read in more detail how to configure them in the section “Runlevels” later in this chapter.

• rcS-sulogin: Normally, single-user mode is used for troubleshooting, and no adminis-trator password is asked for. Of course, this is a serious security issue, and some measures have to be taken. The rcS-suloginservice makes sure that the root password has to be provided every time the single-user mode is entered.

• sulogin: In this script, the administrator can specify the message that a user should see when entering single-user mode.

• tty1-tty6: On Ubuntu Server, virtual terminals are used. To activate a virtual terminal, the key sequences Ctrl+Alt+F1 up to Ctrl+Alt+F6 have to be used. The services files in /etc/event.dspecify what needs to be done when activating one of these virtual termi-nals. If you want to have more than six virtual terminals, copy one of these files to (for example) a file with the name tty8(never use tty7because it is by default used for the graphical environment). Next, change the last line of this file to reflect the name of the TTY it is related to. See Listing 6-4 for an example.

Listing 6-4.The TTY Files Specify What Should Happen on a Virtual Console root@ubuntu:~# cat /etc/event.d/tty1

# tty1 - getty

#

# This service maintains a getty on tty1 from the point the system is

# started until it is shut down again.

start on runlevel 2 start on runlevel 3 start on runlevel 4 start on runlevel 5 stop on runlevel 0 stop on runlevel 1 stop on runlevel 6 respawn

exec /sbin/getty 38400 tty1

As you have seen, the Upstart service activates services as specified in the different files in /etc/event.d. This is pretty much the same as what happened on older versions of Ubuntu Server that still used the initprocess. One of the most important tasks of Upstart is that it’s also responsible for starting all the services that are needed on your server. To do this, it uses the concept of runlevels.

Runlevels

The default runlevel on Ubuntu Server is runlevel 2, in which all the services that have to be started are referred to. Before entering runlevel 2, Ubuntu Server passes through runlevel S. In this runlevel, all the essential services that are always required on your server are started. The configuration of both works in more or less the same way.

To understand the working of a runlevel, you need to understand two components: the service scripts and the scripts that execute these service scripts. All the service scripts are found in the /etc/init.ddirectory, and they are used to start fundamental services such as the mounting of file systems as well as network services like your Apache server. To specify which of these scripts have to be executed when starting your server, two runlevel-related directories are used. The first of these directories is /etc/rcS.d, and on a system that follows a default installation, the second of them is /etc/rc2.d. In the /etc/rcS.ddirectory, services are started that are always needed, whereas in the /etc/rc2.ddirectory, services are started that are specific to a given runlevel.

To make sure that a service starts automatically during system initialization, a symbolic link is created in the /etc/rcS.ddirectory. The name of this link starts with an S, followed by a two-digit number, followed by the name of the script in /etc/init.dthat the link refers to. All these links are processed when booting your server, and they are processed in alphabetical order. So S01blahis processed before S99blah.

The same thing happens for the runlevel directories, except that when working with run-levels, there is an option to change the current runlevel. When changing a runlevel, some scripts may have to be started as well. To do this, more symbolic links are created. The name of these links starts with K, followed by a two-digit number. Listing 6-5 shows an example of the default runlevel 2.

Listing 6-5.To Determine What Is Started and What Is Stopped in a Runlevel, Some Symbolic Links Are Processed

root@ubuntu:/etc/rc2.d# ls -l total 4

-rw-r--r-- 1 root root 556 2007-04-10 17:46 README

lrwxrwxrwx 1 root root 18 2007-07-29 07:34 S10sysklogd -> ../init.d/sysklogd lrwxrwxrwx 1 root root 15 2007-07-29 07:34 S11klogd -> ../init.d/klogd lrwxrwxrwx 1 root root 15 2007-07-29 07:36 S15bind9 -> ../init.d/bind9 lrwxrwxrwx 1 root root 23 2007-07-29 07:36\

S17mysql-ndb-mgm -> ../init.d/mysql-ndb-mgm

lrwxrwxrwx 1 root root 19 2007-07-29 07:36 S18mysql-ndb -> ../init.d/mysql-ndb lrwxrwxrwx 1 root root 15 2007-07-29 07:36 S19mysql -> ../init.d/mysql

lrwxrwxrwx 1 root root 17 2007-07-29 07:32 S20makedev -> ../init.d/makedev lrwxrwxrwx 1 root root 15 2007-07-29 07:36 S20rsync -> ../init.d/rsync lrwxrwxrwx 1 root root 13 2007-07-29 11:44 S20ssh -> ../init.d/ssh lrwxrwxrwx 1 root root 13 2007-07-29 07:36 S89atd -> ../init.d/atd lrwxrwxrwx 1 root root 14 2007-07-29 07:36 S89cron -> ../init.d/cron lrwxrwxrwx 1 root root 17 2007-07-29 07:36 S91apache2 -> ../init.d/apache2 lrwxrwxrwx 1 root root 18 2007-07-29 07:33 S99rc.local -> ../init.d/rc.local lrwxrwxrwx 1 root root 19 2007-07-29 07:33 S99rmnologin -> ../init.d/rmnologin

If you want to make sure that a given service is started automatically, it follows that you first need to make sure that it has a service script in /etc/init.d. If it does, you next need to make a symbolic link for this service. If it is a service that has to be started when your server is booting, you just need a start link in /etc/rcS.d. If it is a service that you want to be included in your server’s runlevels, you need to create a start link as well as a stop link in the directory of the default runlevel, which would be /etc/rc2.din most cases. So let’s see how this works for the imaginary service blahd.

1. To include blahdin system startup, make sure that it has a start script in /etc/init.d.

Ifblahdwas developed to be used on either Debian or Ubuntu Linux, it will have such a script. Let’s say that the name of this script is /etc/init.d/blah. If you can write a decent Bash shell script, open the example script /etc/init.d/skeletonand change it to start the blahservice instead of the default fooservice.

2. Ifblahdis a nonessential service, you should include it in the default runlevel. There-fore, you’re going to create two symbolic links in /etc/rc2.d, and to put the service in the right place, you should first analyze its dependencies. If it depends on some other service to be started first, give it a relatively high number after the S, such as S50. If it doesn’t depend on anything, you can give it a relatively low number. The inverse is true for the kill scripts that make sure that the service is stopped once you quit the runlevel:

scripts that depend on many other services but don’t have dependencies themselves get a low number; scripts that don’t depend on other services get a high number.

3. Now create the links. To create the start link, first use cd /etc/rc2.dand then ln -s ../init.d/blah S10blahd. Next, to create the kill link, use ln -s ../init.d/blah K90blahd. When restarting your server, the service will now be executed automatically.

Tip

When determining the proper load number for a script, on Ubuntu Server you can always assume that all device drivers are initialized, local file systems have been mounted, and networking is available after the S40 scripts have been processed. So in case of doubt, use S41 or higher.

Dans le document Beginning Ubuntu LTS Server Administration (Page 185-189)