Вы находитесь на странице: 1из 21

developerWorks 04.04.

2006

LPI 102, 106: ,


,
Linux (LPIC-1), 106


, :
BIOS (Basic Input/Output System -
-) .
1. , BIOS
( MBR, 512-
). ,
, CD- USB-.
2. MBR ,
LILO GRUB Linux.
512 .
3. ,
( "" ("stage 1.5")
).
4. . Linux ,
, RAM- (initrd).

: LILO (LInux LOader) GRUB (GRand Unified Boot loader).

, . " LPI 101
( 102): Linux ",
.
, :
1. , .
, ,
USB, CD DVD .
, BIOS
. , ,
BIOS.
LPI, .

2. , ,
.
LILO GRUB.
3. GRUB LILO, ,
, ,
.
LILO
LILO /etc/lilo.conf. 1
, Red Hat Enterprise Linux 3.
Red Hat 9 ,
/mnt/hda7, Windows XP /dev/hda1.
1. LILO
[root@lyrebird root]# cat /etc/lilo.conf
prompt
timeout=50
compact
default=latest-EL
boot=/dev/fd0
map=/boot/map
install=/boot/boot.b
message=/boot/message2
lba32
password=mypassword
restricted
image=/mnt/hda7/boot/vmlinuz-2.4.20-31.9
label=redhat9
alias=shrike
initrd=/mnt/hda7/boot/initrd-2.4.20-31.9.img
read-only
append="hdd=ide-scsi root=LABEL=RH9"
image=/boot/vmlinuz-2.4.21-40.EL
label=2.4.21-40.EL
alias=latest-EL
initrd=/boot/initrd-2.4.21-40.EL.img
read-only
append="hdd=ide-scsi root=LABEL=RHEL3"
image=/boot/vmlinuz-2.4.21-37.0.1.EL
label=2.4.21-37a.EL

initrd=/boot/initrd-2.4.21-37.0.1.EL.img
read-only
append="hdd=ide-scsi root=LABEL=RHEL3"
image=/boot/vmlinuz-2.4.21-37.EL
label=2.4.21-37.EL
initrd=/boot/initrd-2.4.21-37.EL.img
read-only
append="hdd=ide-scsi root=LABEL=RHEL3"
image=/boot/vmlinuz-2.4.21-32.0.1.EL
label=2.4.21-32.EL
alias=early
initrd=/boot/initrd-2.4.21-32.0.1.EL.img
read-only
append="hdd=ide-scsi root=LABEL=RHEL3"
other=/dev/hda1
loader=/boot/chain.b
label=WIN-XP
alias=xp

, , /etc/lilo.conf
, lilo. lilo
MBR , ,
.
Linux ,
, lilo , .
message LILO
PCX. Red Hat
Enterprise Linux /boot/message,
Red Hat. 1
, 2.
LILO . ,
.
2. LILO
[root@lyrebird root]# cat /boot/message2
Booting lyrebird

,
: LILO boot:.
. ,

Shift , ,
, .

, Tab,
. , 3,
Enter .
, , ,
.
3. LILO
LILO
Booting lyrebird
boot:
latest-EL

shrike

redhat9

2.4.21-40.EL

2.4.21-37a.EL

2.4.21-37.EL

early

2.4.21-32.EL

xp

WIN-XP

boot: latest-EL

LILO, -q
lilo LILO.
-v . ,
1, 4.
4. LILO
[root@lyrebird root]# lilo -q
latest-EL

shrike
redhat9
2.4.21-40.EL
2.4.21-37a.EL
2.4.21-37.EL
early
2.4.21-32.EL
xp
WIN-XP
[root@lyrebird root]# lilo -q -v | tail +22 | head -n 9
shrike
Password is required for specifying options
Boot command-line won't be locked
No single-key activation

VGA mode is taken from boot image


Kernel is loaded "high", at 0x00100000
Initial RAM disk is 149789 bytes
No fallback
Options: "ro BOOT_FILE=/mnt/hda7/boot/vmlinuz-2.4.20-31.9 hdd=idescsi root=LABEL=RH9"

GRUB
GRUB /boot/grub/grub.conf
/boot/grub/menu.lst. ,
. 5 ,
LILO,
.
5. GRUB
default=1
timeout=10
splashimage=(hd0,2)/boot/grub/fig1x.xpm.gz
foreground=23334c
background=82a6bc
password --md5 $1$H8LlM1$cI0Lfs5.C06xFJYPQ8Ixz/
title Red Hat Linux (2.4.20-31.9)
root (hd0,6)
kernel /boot/vmlinuz-2.4.20-31.9 ro root=LABEL=RH9 hdd=ide-scsi
initrd /boot/initrd-2.4.20-31.9.img
savedefault
boot
title Red Hat Enterprise Linux WS A (2.4.21-40.EL)
root (hd0,10)
kernel /boot/vmlinuz-2.4.21-40.EL ro root=LABEL=RHEL3 hdd=idescsi
initrd /boot/initrd-2.4.21-40.EL.img
title Win/XP
rootnoverify (hd0,0)
chainloader +1

GRUB LILO.
, MD5,
LILO. , , ,

, , GRUB,
GRUB MBR. ,
GRUB ( LILO)
,
RAM-, , ,
.
GRUB ,
. root (hd0,6)
splashimage=(hd0,2)/boot/grub/fig1x.xpm.gz. GRUB
hdn, n - 0 . ,
, .
, (hd0,2) /dev/hda3, (hd0,6) /dev/hda7. - - (fd0).
, GRUB bash,
, GRUB - MBR.
GRUB, 14
. JPEG- ,
14 . 1,
, ,
.

; 2 .
1. , 14 , GRUB

2. ,

GRUB, ,
.
LILO, GRUB

, ,
, ,
cat. ,
e , , c -
GRUB, b - , p - Esc -
. grub,
,
GRUB GRUB.
GRUB help . help
commandname commandname.
6 .
6. GRUB
[root@lyrebird root]# grub
Probing devices to guess BIOS drives. This may take a long time.
find FILENAME
SECTOR [

geometry DRIVE [CYLINDER HEAD

halt [--no-apm]

help [--all] [PATTERN ...]

hide PARTITION

initrd FILE [ARG ...]

kernel [--no-mem-option] [--type=TYPE] makeactive


map TO_DRIVE FROM_DRIVE

md5crypt

module FILE [ARG ...]

modulenounzip FILE [ARG ...]

pager [FLAG]

partnew PART TYPE START LEN

parttype PART TYPE

quit

reboot

root [DEVICE [HDBIAS]]

rootnoverify [DEVICE [HDBIAS]]


[--

serial [--unit=UNIT] [--port=PORT]

setkey [TO_KEY FROM_KEY]


stage2=STAGE2_

setup [--prefix=DIR] [--

terminal [--dumb] [--no-echo] [--no-ed terminfo [--name=NAME --cursoraddress


testvbe MODE

unhide PARTITION

uppermem KBYTES

vbeprobe [MODE]

grub>

help rootnoverify

rootnoverify: rootnoverify [DEVICE [HDBIAS]]


Similar to `root', but don't attempt to mount the partition. This
is useful for when an OS is outside of the area of the disk that
GRUB can read, but setting the correct root device is still
desired. Note that the items mentioned in `root' which derived
from attempting the mount will NOT work correctly.
grub>


GRUB find .
(hd0,2), /dev/hda3,
7.
7. GRUB
GRUB
grub> find /boot/grub/menu.lst
(hd0,2)
(hd0,6)
(hd0,7)
(hd0,8)
(hd0,9)
(hd0,10)
grub> configfile (hd0,2)/boot/grub/menu.lst

, ,
, 8. ,
GRUB, GRUB
. , ,
, ,
GRUB.
8. GRUB
GRUB

version 0.93

(640K lower / 3072K upper memory)

+----------------------------------------------------------------------+
| Red Hat Linux (2.4.20-31.9)

| Red Hat Linux (2.4.20-6)

| Red Hat Enterprise Linux WS A (2.4.21-40.EL)

| Red Hat Enterprise Linux WS A (2.4.21-37.0.1.EL)

| Red Hat Enterprise Linux WS A (2.4.21-37.EL)

| Red Hat Enterprise Linux WS A (2.4.21-32.0.1.EL)

| Red Hat Enterprise Linux WS A (2.4.21-27.0.4.EL)

| Red Hat Enterprise Linux WS A (2.4.21-27.0.2.EL)

| Red Hat Enterprise Linux WS A (2.4.21-27.0.1.EL)

| Red Hat Enterprise Linux WS A (2.4.21-20.EL)

| Red Hat Enterprise Linux WS (2.4.21-27.0.1.EL)

| Red Hat Enterprise Linux WS (2.4.21-15.0.2.EL)


|
+-----------------------------------------------------------------------+

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 5 seconds.

, , Red Hat Enterprise Linux WS A


(2.4.21-40.EL), e, . -
9.
9. GRUB
GRUB

version 0.93

(640K lower / 3072K upper memory)

+----------------------------------------------------------------------+
| root (hd0,10)

| kernel /boot/vmlinuz-2.4.21-40.EL ro root=LABEL=RHEL3 hdd=ide-scsi

| initrd /boot/initrd-2.4.21-40.EL.img

+----------------------------------------------------------------------+
Use the ^ and v keys to select which entry is highlighted.
Press 'b' to boot, 'e' to edit the selected command in the
boot sequence, 'c' for a command-line, 'o' to open a new line
after ('O' for before) the selected line, 'd' to remove the
selected line, or escape to go back to the main menu.


e . ,
/dev/hda5, /dev/hda10 (hd0,9)
/dev/hda11 (hd0,10). . Enter,
, Esc . , b,
.
GRUB ,
, ,
GRUB. , ,
,
GRUB. ,
, GRUB (. )
GRUB.
, info grub.

( )
,
, ,
, .
,
(SMP)
.

.
LILO, ( )
, . ,
/boot/vmlinuz-2.4.21-40.EL-prep,
, LILO ,
10.
10. LILO
boot: latest-EL image=/boot/vmlinuz-2.4.21-40.EL-prep

GRUB,
initrd , , ,
, , -prep
.
, /sbin/init.
, .
(PID) 1, 11.
11. init
[root@lyrebird root]# ps --pid 1
PID TTY
1 ?

TIME CMD
00:00:04 init

init ,
. /etc/rc.d/init.d /etc/init.d,
, ,
, , ,
, . init ,
getty, .
-,
" LPI 102, 105: ."
, init,
,

. , init=/bin/sh
,
.
,
man bootparam
/usr/src/linux/Documentation/ramdisk.txt, /usr/src/linux$(uname -r)/Documentation/kernel-parameters.txt .
, ,
,
. lilo,
LILO.

Linux, ,
,
, . , ,
, , ,
-, ,
.
Linux Bootsplash (. )
,
. ,
,
- , , F2.
dmesg
.
, ,
( ) .
, dmesg,
. ,

. 12 ,
.
12. dmesg
[root@lyrebird root]# dmesg | head -n 30
Linux version 2.4.21-40.EL (bhcompile@hs20-bc1-7.build.redhat.com) (gcc
version 3.2.3
20030502 (Red Hat Linux 3.2.3-54)) #1 Thu Feb 2 22:32:00 EST 2006
BIOS-provided physical RAM map:

BIOS-e820: 0000000000000000 - 000000000009f800 (usable)


BIOS-e820: 000000000009f800 - 00000000000a0000 (reserved)
BIOS-e820: 00000000000e0000 - 0000000000100000 (reserved)
BIOS-e820: 0000000000100000 - 000000005f6f0000 (usable)
BIOS-e820: 000000005f6f0000 - 000000005f6fb000 (ACPI data)
BIOS-e820: 000000005f6fb000 - 000000005f700000 (ACPI NVS)
BIOS-e820: 000000005f700000 - 000000005f780000 (usable)
BIOS-e820: 000000005f780000 - 0000000060000000 (reserved)
BIOS-e820: 00000000fec00000 - 00000000fec10000 (reserved)
BIOS-e820: 00000000fee00000 - 00000000fee01000 (reserved)
BIOS-e820: 00000000ff800000 - 00000000ffc00000 (reserved)
BIOS-e820: 00000000fffffc00 - 0000000100000000 (reserved)
631MB HIGHMEM available.
896MB LOWMEM available.
NX protection not present; using segment protection
On node 0 totalpages: 391040
zone(0): 4096 pages.
zone(1): 225280 pages.
zone(2): 161664 pages.
IBM machine detected. Enabling interrupts during APM calls.
Kernel command line: ro root=LABEL=RHEL3 hdd=ide-scsi
ide_setup: hdd=ide-scsi
Initializing CPU#0
Detected 2392.059 MHz processor.
Console: colour VGA+ 80x25
Calibrating delay loop... 4771.02 BogoMIPS
Page-cache hash table entries: 524288 (order: 9, 2048 KB)
Page-pin hash table entries: 131072 (order: 7, 512 KB)

,
. ""
. 13 ,
, ,
USB.
13.
[root@attic4 ~]# dmesg |tail -n 19
main[15961]: segfault at 0000000000529000 rip 0000000000403b5d rsp
00007fffffd15d00
error 6

usb 1-4.3: new high speed USB device using ehci_hcd and address 4
scsi5 : SCSI emulation for USB Mass Storage devices
usb-storage: device found at 4
usb-storage: waiting for device to settle before scanning
Vendor: Sony
Type:

Model: Storage Media

Direct-Access

Rev: 0100
ANSI SCSI revision: 00

SCSI device sdb: 1014784 512-byte hdwr sectors (520 MB)


sdb: Write Protect is off
sdb: Mode Sense: 43 00 00 00
sdb: assuming drive cache: write through
SCSI device sdb: 1014784 512-byte hdwr sectors (520 MB)
sdb: Write Protect is off
sdb: Mode Sense: 43 00 00 00
sdb: assuming drive cache: write through
sdb: sdb1
sd 5:0:0:0: Attached scsi removable disk sdb
usb-storage: device scan complete
SELinux: initialized (dev sdb1, type vfat), uses genfs_contexts
/var/log/messages

/sbin/init,
, ,
syslog , /var/log/messages.
, syslog ,
. - ,
,
init .
, 'd'. 14
,
.
14. /var/log/messages
[root@lyrebird root]# grep "^Apr.*d\:" /var/log/messages|tail -n 14
Apr

2 15:36:50 lyrebird kernel: hdd: attached ide-scsi driver.

Apr

2 15:36:52 lyrebird apmd: apmd startup succeeded

Apr 2 15:36:26 lyrebird rc.sysinit: Setting hostname lyrebird:


succeeded
Apr 2 15:36:26 lyrebird rc.sysinit: Initializing USB keyboard:
succeeded
Apr

2 15:36:55 lyrebird sshd:

succeeded

Apr

2 15:36:55 lyrebird xinetd: xinetd startup succeeded

Apr

2 15:36:56 lyrebird ntpd:

succeeded

Apr

2 15:36:56 lyrebird ntpd:

succeeded

Apr

2 15:36:56 lyrebird ntpd:

succeeded

Apr

2 15:36:56 lyrebird ntpd: ntpd startup succeeded

Apr

2 15:36:57 lyrebird crond: crond startup succeeded

Apr

2 15:36:58 lyrebird atd: atd startup succeeded

Apr 2 15:36:58 lyrebird snastart: insmod: streams: no module by that


name found
Apr

2 15:36:58 lyrebird rhnsd: rhnsd startup succeeded

/var/log.
, X Window,
" LPI 101, 110: X
Window ."

,

,
( ) Linux.
Linux
. 3.
3. Linux

( )

;
s S

, ,
. 4.

4. Linux


X Window

Slackware 4 5
X Window. Debian
, 2.
.

Linux id:
/etc/inittab. 15 ,
Red Hat Enterprise Linux, 5 X
Window.
15. ./etc/inittab
[root@lyrebird root]# grep "^id:" /etc/inittab
id:5:initdefault:


.
, /etc/inittab
, .
,
. , ,
, ,
, X Window. , ,

3, .
, (GRUB)
(LILO).
( 3). ,
5, ,
16.
16.
kernel /boot/vmlinuz-2.4.21-40.EL ro root=LABEL=RHEL3 hdd=ide-scsi 3

3, , ,
5. ,
. telinit,
init, .
, runlevel,
.
- 'N', ,
. 17
.
17.
[root@lyrebird root]# runlevel
N 3
[root@lyrebird root]# telinit 5
[root@lyrebird root]# runlevel
3 5

ls, telinit,
,
init. init , ,
. init PID 1,
, , init telinit.
, , ,
telinit . , int 5 telinit 5,
5.


, DOS
Windows, Linux . ,
, , ,
,
- . 1,

, - .
,
. , (
) .
,
. ,
, ,
.

, ,
telinit 1. 3, 's' 'S' - 1,
, , telinit s.


telinit init
,
shutdown. shutdown
.
init .
init SIGTERM,
. 5
, , init SIGKILL,
.
shutdown 1
( ). -h,
, -r, .
.
hh:mm n, n -
. now, +0.
, ,
, Ctrl-c,
, shutdown -c .
18 shutdown,
.
18.
[root@lyrebird root]# shutdown 5 File system recovery needed
Broadcast message from root (pts/0) (Mon Apr

3 22:44:29 2006):

File system recovery needed


The system is going DOWN to maintenance mode in 5 minutes!

Shutdown cancelled.
[root@lyrebird root]# shutdown -r 10 Reloading updated kernel&
[1] 5388
Broadcast message from root (pts/0) (Mon Apr

3 22:45:15 2006):

Reloading updated kernel


The system is going DOWN for reboot in 10 minutes!
[root@lyrebird root]# fg
shutdown -r 10 Reloading updated kernel
Shutdown cancelled.
[root@lyrebird root]# shutdown -h 23:59&
[1] 5390
[root@lyrebird root]# shutdown -c
Shutdown cancelled.
[1]+

Done

shutdown -h 23:59

, , ,
. 15 ,
, 15 , 19.
19 -t
SIGTERM SIGKILL 5 60.
19.
[root@lyrebird root]# date;shutdown -t60 17 Time to do backups
Mon Apr

3 22:51:45 EDT 2006

Broadcast message from root (pts/0) (Mon Apr

3 22:53:45 2006):

Time to do backups
The system is going DOWN to maintenance mode in 15 minutes!
20.
[root@lyrebird root]# reboot
Broadcast message from root (pts/0) (Mon Apr

3 22:58:27 2006):

The system is going down for reboot NOW!

, 3,
runlevel uptime 21.
21.
[ian@lyrebird ian]$ /sbin/runlevel
N 3
[ian@lyrebird ian]$ uptime

23:05:51

up 6 min,

1 user,

load average: 0.00, 0.06, 0.03

telinit ( init)
. telinit,
s, ,
SIGTERM SIGKILL .
telinit, init shutdown man.

,
, .
halt .
poweroff halt,
.
reboot - halt,
.
- ,
0 6,
shutdown.
,
, ,
man.

, , , Ctrl-Alt-Delete
,
.
id

/etc/inittab? , /etc/inittab,
, rc1.d rc5.d,
,
. 22 Ctrl-Alt-Delete, , ,
.
22. ctrl-alt-delete
[root@lyrebird root]# grep -i ctrl /etc/inittab
# Trap CTRL-ALT-DELETE
ca::ctrlaltdel:/sbin/shutdown -t3 -r now

, init ,
, /etc/init.d /etc/rc.d.init.d.
rcn.d,
n, ,
. "K" "S",
, 23.
23. init
[root@lyrebird root]# find /etc -path "*rc[0-9]*.d/???au*"
/etc/rc.d/rc0.d/K95audit
/etc/rc.d/rc0.d/K72autofs
/etc/rc.d/rc1.d/K95audit
/etc/rc.d/rc1.d/K72autofs
/etc/rc.d/rc2.d/S20audit
/etc/rc.d/rc2.d/K72autofs
/etc/rc.d/rc3.d/S20audit
/etc/rc.d/rc3.d/S28autofs
/etc/rc.d/rc4.d/K95audit
/etc/rc.d/rc4.d/S28autofs
/etc/rc.d/rc5.d/S20audit
/etc/rc.d/rc5.d/S28autofs
/etc/rc.d/rc6.d/K95audit
/etc/rc.d/rc6.d/K72autofs
[root@lyrebird root]# cd /etc/rc.d/rc5.d
[root@lyrebird rc5.d]# ls -l ???a*
lrwxr-xr-x
1 root
../init.d/audit

root

15 Jan 11

2005 S20audit ->

lrwxr-xr-x
1 root
../init.d/apmd

root

14 Jan 11

2005 S26apmd ->

lrwxr-xr-x
1 root
../init.d/autofs

root

16 Jan 11

2005 S28autofs ->

lrwxr-xr-x
1 root
../init.d/atd

root

13 Jan 11

2005 S95atd ->

, audit autofs Knn


Snn 3 5. "S" ,
, "K"
, . nn
,
. audit autofs .

init inittab
man.