%general-entities; ]> Настройка и использование System V Bootscript Bootscripts usage Как работает System V Bootscripts? В Linux используется специальное средство загрузки SysVinit, основанное на концепции уровней выполнения (run-levels). Он может сильно отличаться от одной системы к другой, поэтому нельзя предположить, что, корректная работа в одном дистрибутиве Linux, должны работать одинаково и в LFS. У LFS есть свой собственный способ управления, но она уважает общепринятые стандарты. SysVinit (который теперь будет называться init) работает по схеме уровней выполнения. Есть семь (пронумерованных от 0 до 6) уровней выполнения (на самом деле, есть больше уровней выполнения, но они предназначены для особых случаев и обычно не используются. См. init(8) Для получения более подробной информации), и каждый из них соответствует действиям, которые компьютер должен выполнять при запуске. Уровень запуска по умолчанию-3. Ниже приведены описания различных уровней запуска по мере их реализации: 0: остановить компьютер 1: однопользовательский режим 2: многопользовательский режим без сети 3: многопользовательский режим с сетью 4: зарезервированный для настроек, в ином случае аналогичен уровню 3 5: аналогичен уровню 3 4, обычно используется для GUI авторизации (например xdm или kdm) 6: перезагрузка компьютера Настройка Sysvinit Sysvinit configuring /etc/inittab Во время инициализации ядра первая запущенная программа указывается либо в командной строке, либо по умолчанию в init. Эта программа читает файл инициализации /etc/inittab. Создайте этот файл: cat > /etc/inittab << "EOF" # Begin /etc/inittab id:3:initdefault: si::sysinit:/etc/rc.d/init.d/rc S l0:0:wait:/etc/rc.d/init.d/rc 0 l1:S1:wait:/etc/rc.d/init.d/rc 1 l2:2:wait:/etc/rc.d/init.d/rc 2 l3:3:wait:/etc/rc.d/init.d/rc 3 l4:4:wait:/etc/rc.d/init.d/rc 4 l5:5:wait:/etc/rc.d/init.d/rc 5 l6:6:wait:/etc/rc.d/init.d/rc 6 ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now su:S016:once:/sbin/sulogin 1:2345:respawn:/sbin/agetty --noclear tty1 9600 2:2345:respawn:/sbin/agetty tty2 9600 3:2345:respawn:/sbin/agetty tty3 9600 4:2345:respawn:/sbin/agetty tty4 9600 5:2345:respawn:/sbin/agetty tty5 9600 6:2345:respawn:/sbin/agetty tty6 9600 # End /etc/inittab EOF Объяснение содержимого файла инициализации находится на справочных страницах inittab. Для LFS ключевой командой является rc. В приведенном выше файле инициализации rc будет выполнять все сценарии, начиная с символа S в каталоге /etc/rc.d/rcS.d, за которым следуют все скрипты, начинающиеся с S в /etc/rc.d / rc?.D каталог, в котором знак вопроса задается значением initdefault. Для удобства, сценарий rc считывает функции из библиотеки /lib/lsb/init-functions. Библиотека, в свою очередь, считывает опциональные файлы конфигурации из файла /etc/sysconfig/rc.site. Любой из системных конфигурационных файлов описанных в последующих разделах можно, в качестве альтернативы, поместить в этот файл, что позволит объединить все системные параметры в один файл. Для удобства отладки, функции сценария журналируют весь вывод в файл /run/var/bootlog. Поскольку каталог /run является tmpfs, файла может не быть, в процессе загрузки, однако уго содержимое добавляется к фиксированному файлу /var/log/boot.log при завершении процесса загрузки. Изменение уровней выполнения (Run Levels) Изменить уровень выполнения можно с помощью команды init <runlevel>, где <runlevel> - будет целевым уровнем выполнения. Например, чтобы перезагрузить компьютер, пользователь должен выполнить команду init 6, которая является псевдонимом команды reboot. Аналогично, init 0 является псевдонимом команды halt. В каталоге /etc/rc.d есть ещё несколько каталогов, которые выглядят как rc?.d (где ? номер уровня выполнения) и каталог rcsysinit.d, содержащий некоторый набор символических ссылок. Некоторые начинаются с K, другие начинаются с S, и все они имеют два числа после начальной буквы. K означает остановить (kill) службу, а S означает запустить службу. Числа определяют порядок выполнения сценариев от 00 до 99 - чем меньше число, тем раньше он запустится. Когда init переключается на другой уровень выполнения, соответствующие службы запускаются или останавливаются в зависимости от выбранного уровня запуска. Реальные сценарии находятся в каталоге /etc/rc.d/init.d. Они выполняют фактическую работу, и символические ссылки указывают на них. Ссылки К и ссылки S указывают на тот же сценарий в /etc/rc.d/init.d. Это связано с тем, что сценарии можно вызывать с различными параметрами, такими как start, stop, restart, reload, и status. Когда встречается ссылка K, соответствующий скрипт запускается с аргументом stop. Когда встречается S-ссылка, соответствующий скрипт запускается с аргументом start. Есть одно исключение. Ссылки, которые начинаются с S в каталогах rc0.d и rc6.d, не будут запускать что-либо. Они будут вызываться с параметром stop, для того, чтобы остановить какую либо службу. Логика этого заключается в том, что когда пользователь собирается перезагрузить или остановить систему, при этом, ему ничего не нужно запускать. Систему нужно только остановить. Ниже приведены описания к аргументам для сценариев и их значения: start Служба запущена stop Служба остановлена restart Остановка службы и затем повторный её запуск reload Конфигурация службы была обновлена. Используется после того, как файлы конфигурации были обновлены, когда службу не нужно перезапускать. status Сообщает, работает ли служба и какие ей назначены PID Не стесняйтесь изменять способ загрузки процесса (в конце концов,    это ваша собственная система LFS). Приведенные здесь файлы являются примером того, как    это можно сделать. Udev Bootscripts The /etc/rc.d/init.d/udev initscript starts udevd, triggers any "coldplug" devices that have already been created by the kernel and waits for any rules to complete. The script also unsets the uevent handler from the default of /sbin/hotplug . This is done because the kernel no longer needs to call out to an external binary. Instead udevd will listen on a netlink socket for uevents that the kernel raises. The /etc/rc.d/init.d/udev_retry initscript takes care of re-triggering events for subsystems whose rules may rely on filesystems that are not mounted until the mountfs script is run (in particular, /usr and /var may cause this). This script runs after the mountfs script, so those rules (if re-triggered) should succeed the second time around. It is configured from the /etc/sysconfig/udev_retry file; any words in this file other than comments are considered subsystem names to trigger at retry time. To find the subsystem of a device, use udevadm info --attribute-walk <device> where <device> is an absolute path in /dev or /sys such as /dev/sr0 or /sys/class/rtc. For information on kernel module loading and udev, see . Configuring the System Clock setclock configuring The setclock script reads the time from the hardware clock, also known as the BIOS or the Complementary Metal Oxide Semiconductor (CMOS) clock. If the hardware clock is set to UTC, this script will convert the hardware clock's time to the local time using the /etc/localtime file (which tells the hwclock program which timezone the user is in). There is no way to detect whether or not the hardware clock is set to UTC, so this needs to be configured manually. The setclock is run via udev when the kernel detects the hardware capability upon boot. It can also be run manually with the stop parameter to store the system time to the CMOS clock. If you cannot remember whether or not the hardware clock is set to UTC, find out by running the hwclock --localtime --show command. This will display what the current time is according to the hardware clock. If this time matches whatever your watch says, then the hardware clock is set to local time. If the output from hwclock is not local time, chances are it is set to UTC time. Verify this by adding or subtracting the proper amount of hours for the timezone to the time shown by hwclock. For example, if you are currently in the MST timezone, which is also known as GMT -0700, add seven hours to the local time. Change the value of the UTC variable below to a value of 0 (zero) if the hardware clock is not set to UTC time. Create a new file /etc/sysconfig/clock by running the following: cat > /etc/sysconfig/clock << "EOF" # Begin /etc/sysconfig/clock UTC=1 # Set this to any options you might need to give to hwclock, # such as machine hardware clock type for Alphas. CLOCKPARAMS= # End /etc/sysconfig/clock EOF A good hint explaining how to deal with time on LFS is available at . It explains issues such as time zones, UTC, and the TZ environment variable. The CLOCKPARAMS and UTC paramaters may be alternatively set in the /etc/sysconfig/rc.site file. Configuring the Linux Console console configuring This section discusses how to configure the console bootscript that sets up the keyboard map, console font and console kernel log level. If non-ASCII characters (e.g., the copyright sign, the British pound sign and Euro symbol) will not be used and the keyboard is a U.S. one, much of this section can be skipped. Without the configuration file, (or equivalent settings in rc.site), the console bootscript will do nothing. The console script reads the /etc/sysconfig/console file for configuration information. Decide which keymap and screen font will be used. Various language-specific HOWTOs can also help with this, see . If still in doubt, look in the /usr/share/keymaps and /usr/share/consolefonts directories for valid keymaps and screen fonts. Read loadkeys(1) and setfont(8) manual pages to determine the correct arguments for these programs. The /etc/sysconfig/console file should contain lines of the form: VARIABLE="value". The following variables are recognized: LOGLEVEL This variable specifies the log level for kernel messages sent to the console as set by dmesg. Valid levels are from "1" (no messages) to "8". The default level is "7". KEYMAP This variable specifies the arguments for the loadkeys program, typically, the name of keymap to load, e.g., it. If this variable is not set, the bootscript will not run the loadkeys program, and the default kernel keymap will be used. Note that a few keymaps have multiple versions with the same name (cz and its variants in qwerty/ and qwertz/, es in olpc/ and qwerty/, and trf in fgGIod/ and qwerty/). In these cases the parent directory should also be specified (e.g. qwerty/es) to ensure the proper keymap is loaded. KEYMAP_CORRECTIONS This (rarely used) variable specifies the arguments for the second call to the loadkeys program. This is useful if the stock keymap is not completely satisfactory and a small adjustment has to be made. E.g., to include the Euro sign into a keymap that normally doesn't have it, set this variable to euro2. FONT This variable specifies the arguments for the setfont program. Typically, this includes the font name, -m, and the name of the application character map to load. E.g., in order to load the lat1-16 font together with the 8859-1 application character map (as it is appropriate in the USA), set this variable to lat1-16 -m 8859-1. In UTF-8 mode, the kernel uses the application character map for conversion of composed 8-bit key codes in the keymap to UTF-8, and thus the argument of the "-m" parameter should be set to the encoding of the composed key codes in the keymap. UNICODE Set this variable to 1, yes or true in order to put the console into UTF-8 mode. This is useful in UTF-8 based locales and harmful otherwise. LEGACY_CHARSET For many keyboard layouts, there is no stock Unicode keymap in the Kbd package. The console bootscript will convert an available keymap to UTF-8 on the fly if this variable is set to the encoding of the available non-UTF-8 keymap. Some examples: For a non-Unicode setup, only the KEYMAP and FONT variables are generally needed. E.g., for a Polish setup, one would use: cat > /etc/sysconfig/console << "EOF" # Begin /etc/sysconfig/console KEYMAP="pl2" FONT="lat2a-16 -m 8859-2" # End /etc/sysconfig/console EOF As mentioned above, it is sometimes necessary to adjust a stock keymap slightly. The following example adds the Euro symbol to the German keymap: cat > /etc/sysconfig/console << "EOF" # Begin /etc/sysconfig/console KEYMAP="de-latin1" KEYMAP_CORRECTIONS="euro2" FONT="lat0-16 -m 8859-15" UNICODE=1 # End /etc/sysconfig/console EOF The following is a Unicode-enabled example for Bulgarian, where a stock UTF-8 keymap exists: cat > /etc/sysconfig/console << "EOF" # Begin /etc/sysconfig/console UNICODE="1" KEYMAP="bg_bds-utf8" FONT="LatArCyrHeb-16" # End /etc/sysconfig/console EOF Due to the use of a 512-glyph LatArCyrHeb-16 font in the previous example, bright colors are no longer available on the Linux console unless a framebuffer is used. If one wants to have bright colors without framebuffer and can live without characters not belonging to his language, it is still possible to use a language-specific 256-glyph font, as illustrated below: cat > /etc/sysconfig/console << "EOF" # Begin /etc/sysconfig/console UNICODE="1" KEYMAP="bg_bds-utf8" FONT="cyr-sun16" # End /etc/sysconfig/console EOF The following example illustrates keymap autoconversion from ISO-8859-15 to UTF-8 and enabling dead keys in Unicode mode: cat > /etc/sysconfig/console << "EOF" # Begin /etc/sysconfig/console UNICODE="1" KEYMAP="de-latin1" KEYMAP_CORRECTIONS="euro2" LEGACY_CHARSET="iso-8859-15" FONT="LatArCyrHeb-16 -m 8859-15" # End /etc/sysconfig/console EOF Some keymaps have dead keys (i.e., keys that don't produce a character by themselves, but put an accent on the character produced by the next key) or define composition rules (such as: press Ctrl+. A E to get Æ in the default keymap). Linux-&linux-version; interprets dead keys and composition rules in the keymap correctly only when the source characters to be composed together are not multibyte. This deficiency doesn't affect keymaps for European languages, because there accents are added to unaccented ASCII characters, or two ASCII characters are composed together. However, in UTF-8 mode it is a problem, e.g., for the Greek language, where one sometimes needs to put an accent on the letter alpha. The solution is either to avoid the use of UTF-8, or to install the X window system that doesn't have this limitation in its input handling. For Chinese, Japanese, Korean and some other languages, the Linux console cannot be configured to display the needed characters. Users who need such languages should install the X Window System, fonts that cover the necessary character ranges, and the proper input method (e.g., SCIM, it supports a wide variety of languages). The /etc/sysconfig/console file only controls the Linux text console localization. It has nothing to do with setting the proper keyboard layout and terminal fonts in the X Window System, with ssh sessions or with a serial console. In such situations, limitations mentioned in the last two list items above do not apply. Creating Files at Boot File creation at boot configuring At times, it is desired to create files at boot time. For instance, the /tmp/.ICE-unix directory may be desired. This can be done by creating an entry in the /etc/sysconfig/createfiles configuration script. The format of this file is embedded in the comments of the default configuration file. Configuring the sysklogd Script sysklogd configuring The sysklogd script invokes the syslogd program as a part of System V initialization. The -m 0 option turns off the periodic timestamp mark that syslogd writes to the log files every 20 minutes by default. If you want to turn on this periodic timestamp mark, edit /etc/sysconfig/rc.site and define the variable SYSKLOGD_PARMS to the desired value. For instance, to remove all parameters, set the variable to a null value: SYSKLOGD_PARMS= See man syslogd for more options. Файл rc.site rc.site The optional /etc/sysconfig/rc.site file contains settings that are automatically set for each SystemV boot script. It can alternatively set the values specified in the hostname, console, and clock files in the /etc/sysconfig/ directory. If the associated variables are present in both these separate files and rc.site, the values in the script specific files have precedence. rc.site also contains parameters that can customize other aspects of the boot process. Setting the IPROMPT variable will enable selective running of bootscripts. Other options are described in the file comments. The default version of the file is as follows: &site; Customizing the Boot and Shutdown Scripts The LFS boot scripts boot and shut down a system in a fairly efficient manner, but there are a few tweaks that you can make in the rc.site file to improve speed even more and to adjust messages according to your preferences. To do this, adjust the settings in the /etc/sysconfig/rc.site file above. During the boot script udev, there is a call to udev settle that requires some time to complete. This time may or may not be required depending on devices present in the system. If you only have simple partitions and a single ethernet card, the boot process will probably not need to wait for this command. To skip it, set the variable OMIT_UDEV_SETTLE=y. The boot script udev_retry also runs udev settle by default. This command is only needed by default if the /var directory is separately mounted. This is because the clock needs the file /var/lib/hwclock/adjtime. Other customizations may also need to wait for udev to complete, but in many installations it is not needed. Skip the command by setting the variable OMIT_UDEV_RETRY_SETTLE=y. By default, the file system checks are silent. This can appear to be a delay during the bootup process. To turn on the fsck output, set the variable VERBOSE_FSCK=y. When rebooting, you may want to skip the filesystem check, fsck, completely. To do this, either create the file /fastboot or reboot the system with the command /sbin/shutdown -f -r now. On the other hand, you can force all file systems to be checked by creating /forcefsck or running shutdown with the -F parameter instead of -f. Setting the variable FASTBOOT=y will disable fsck during the boot process until it is removed. This is not recommended on a permanent basis. Normally, all files in the /tmp directory are deleted at boot time. Depending on the number of files or directories present, this can cause a noticeable delay in the boot process. To skip removing these files set the variable SKIPTMPCLEAN=y. During shutdown, the init program sends a TERM signal to each program it has started (e.g. agetty), waits for a set time (default 3 seconds), and sends each process a KILL signal and waits again. This process is repeated in the sendsignals script for any processes that are not shut down by their own scripts. The delay for init can be set by passing a parameter. For example to remove the delay in init, pass the -t0 parameter when shutting down or rebooting (e.g. /sbin/shutdown -t0 -r now). The delay for the sendsignals script can be skipped by setting the parameter KILLDELAY=0.