高可用集群——HA

Posted by TQ on 十月 11th, 2009

高可用集群——HA

2008年3月10日

当日小结:

 掌握使用heartbeat对Director做高可用集群HA(High Availability)。

clip_image001

“数据源”和“单一故障点(SOPE)”需要做HA集群。 

HA方式:(三种)

主从方式HA:

clip_image002 

主从方式HA:从服务平时不运行。只有当主服务DOWN掉时,从服务才马上启用。 

 

对称方式HA:

clip_image003 

现在,一般的陈列柜都有双控制器,可以有来个服务同时进行读写。 

 

 

集群方式HA:

clip_image004 

 

 

  Read the rest of this entry »

调优小结(一)&& linux_Performance_Tuning_1

Posted by TQ on 十月 11th, 2009

调优小结(一)

2008年3月3日

Linux调优:从底层编程的角度考虑。

先调优应用程序Application

再调优操作系统OS

再调优硬件

调优:

计算机体系结构:冯·诺伊曼模型。

Linux系统及硬件常见性能问题及分析工具。

命令:ps、top、vmstat、iostat、mpstat、lsof、strace、ltrace、pmap、ipcs

③ /proc文件系统及内核参数调整。

一、计算机体系结构

system_configuration

CPU的X86指令集兼容386指令集以后的指令集。

Windows中:.com 文件,编译成机器代码。

.exe 文件,编译成操作系统(windows)的API,一少部分编译成机器代码。

.com 文件执行最快,直接执行机器代码。

windows微内核(最核心)

注:grub就是机器代码。

IA-32体系结构:

一、CPU:

RISC:精简指令集。

CISC:复杂指令集。

64位:① X86-64:支持大内存264=16G

② 科学计算(整数计算)264位。

二、内存:

memory

服务器端需要大缓存。

内存:EDO:50MHZ

SDRAM:66MHZ~133MHZ

DDR1:266MHZ~400MHZ 上升沿、下降沿都执行一次,翻倍了。

DDR2:533MHZ~800MHZ

三、总线:

PCI总线

4B(32bit)×33 MHZ/s=133MB/s

8B(64bit)×33 MHZ/s=266MB/s

8B(64bit)×66 MHZ/s=512MB/s

PCI-X总线=1GB/s

USB总线:都是480Mb/s,是点对点(Point-to-Point)的Share Switch架构。

PCI-E总线:是点对点(Point-to-Point)的Share Switch架构,每条回路都为250MB/s。

1X:250MB/s

16X:4GB/s

IDE总线:133Mbps=16MB/s ,寻道时间:8ms(毫秒) 一秒,125HZ

二、Linux系统及硬件常见性能问题及分析工具

命令:ps、top、vmstat、iostat、mpstat、lsof、strace、ltrace、pmap、ipcs

检查系统时的步骤

① #free

② #ps aux

③ 先备份

④ 再进行调整。

[root@vm51: ~]#top

clip_image004

[root@vm51: ~]#uptime

15:02:22 up 9:55, 2 users, load average: 0.00, 0.00, 0.00

注:top和uptime都是调用/proc/loadavg

load average:1秒、5秒、15秒 等待执行任务的平均时间。

说明:load average值高时,可能是:① I/O 慢设备读写;② 内存不足。

内存不足会引起I/O wait高,CPU占用高。内存不足,三个都高。

CPU(s):

用top命令时,

按”1”:可看每个CPU占用%。

按”m”:以内存占用率排序。

按”r”:renice 一个进程。

按”k”:kill一个进程。

%us:用户占用CPU%

%sy:系统空间占用CPU%

%ni:高优先级占用CPU%

%id:空闲CPU%

%wa:等待硬盘占CPU%

%hi:硬中断占CPU%

%si:软中断占CPU%

说明:内存还没用空,就有用SWAP了,是内存慌恐机制引起的。

说明:

buffer:在硬件中的缓存。只关心硬件,其内容不被关心。

cache:写文件时用的缓存。关心文件、路径。

[root@vm51: ~]#ps -aux

Warning: bad syntax, perhaps a bogus ‘-’? See /usr/share/doc/procps-3.2.7/FAQ

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND

root 1 0.0 0.2 2036 644 ? Ss 05:06 0:03 init [3]

root 2 0.0 0.0 0 0 ? S 05:06 0:00 [migration/0]

root 3 0.0 0.0 0 0 ? SN 05:06 0:00 [ksoftirqd/0]

root 4 0.0 0.0 0 0 ? S 05:06 0:00 [watchdog/0]

root 5 0.0 0.0 0 0 ? S 05:06 0:00 [migration/1]

root 6 0.0 0.0 0 0 ? SN 05:06 0:00 [ksoftirqd/1]

root 7 0.0 0.0 0 0 ? S 05:06 0:00 [watchdog/1]

TIME:从开机到现在占用CPU累计时间。

COMMAND:进程名字。有[]的只占内核空间(内核线程),是kill不掉的。

Linux中一页内存4K。

SATA:状态字。

R:正在运行running。

S:可中断休眠。

s:会话session。一堆具有相同父进程的进程,表示下面有“子进程”,此为“父进程”。

l:有线程。共享相同(工作单元)资源的进程。(省内存)

+:前置进程。当前tty的第一个进程。

<:高优先级进程。 nice值:-20最高~19最低

N:低优先级进程。

L:有内存锁。所占的内存不会被交换到SWAP中。

D:不可中断休眠。deep sleep深度休眠,多了说明慢速设备I/O多。

T:暂停进程。

Z:僵尸进程。(儿子死了,父不回收。不占资源,占PID,占内存1.7K,不能被kill)

clip_image005

说明:

① 进程之间有封闭的内存。如果超出封闭内存范围,叫“内存溢出”。

② 多线程可充分利用CPU。线程之间通讯方便、容易。

③ 线程之间切换付出代价较小。

命令:#pmap PID 查看调用到什么库

[root@vm51: ~]#pmap 1

1: init [3]

00546000 100K r-x– /lib/ld-2.5.so

0055f000 4K r-x– /lib/ld-2.5.so

00560000 4K rwx– /lib/ld-2.5.so

00563000 1244K r-x– /lib/libc-2.5.so

0069a000 8K r-x– /lib/libc-2.5.so

0069c000 4K rwx– /lib/libc-2.5.so

0069d000 12K rwx– [ anon ]

006cb000 8K r-x– /lib/libdl-2.5.so

006cd000 4K r-x– /lib/libdl-2.5.so

006ce000 4K rwx– /lib/libdl-2.5.so

008df000 236K r-x– /lib/libsepol.so.1

0091a000 4K rwx– /lib/libsepol.so.1

0091b000 40K rwx– [ anon ]

00927000 84K r-x– /lib/libselinux.so.1

0093c000 8K rwx– /lib/libselinux.so.1

00dec000 4K r-x– [ anon ]

08048000 32K r-x– /sbin/init

08050000 4K rw— /sbin/init

088ec000 132K rw— [ anon ]

b7fb3000 8K rw— [ anon ]

b7fc2000 4K rw— [ anon ]

bff27000 88K rw— [ stack ]

total 2036K

命令:#vmstat

[root@vm51: ~]#vmstat 2 3

procs ———–memory———- —swap– —–io—- –system– —–cpu——

r b swpd free buff cache si so bi bo in cs us sy id wa st

0 0 8 10412 73608 116576 0 0 7 4 506 28 0 1 98 0 0

0 0 8 10412 73608 116576 0 0 0 0 1015 35 0 0 100 0 0

0 0 8 10412 73608 116576 0 0 0 0 1012 37 0 0 100 0 0

r:在CPU等待要执行任务的个数。

b:在CPU等待要进行块设备操作的个数。

si/so:swapin:从磁盘读。

swapout:写入到磁盘。

bi/bo:blockin/blockout

in:中断。

cs:内容切换。

us:用户占用CPU%

sy:系统空间占用CPU%

id:空闲CPU%

wa:等待硬盘占CPU% bi/bo高会导致wa高

说明:没有si、so、bi、bo但r很高,说明CPU不行了,要换高性能的CPU了。

安装sysstat包会有iostat、sar、mpstat这三个命令。

[root@vm51: /mnt/Server]#rpm -ivh sysstat-7.0.0-3.el5.i386.rpm

[root@vm51: ~]#vmstat -d 1 1 每隔1秒刷新 就刷1次

disk- ————reads———— ————writes———– —–IO——

total merged sectors ms total merged sectors ms cur sec

ram0 0 0 0 0 0 0 0 0 0 0

ram1 0 0 0 0 0 0 0 0 0 0

ram2 0 0 0 0 0 0 0 0 0 0

ram3 0 0 0 0 0 0 0 0 0 0

ram4 0 0 0 0 0 0 0 0 0 0

ram5 0 0 0 0 0 0 0 0 0 0

ram6 0 0 0 0 0 0 0 0 0 0

ram7 0 0 0 0 0 0 0 0 0 0

ram8 0 0 0 0 0 0 0 0 0 0

ram9 0 0 0 0 0 0 0 0 0 0

ram10 0 0 0 0 0 0 0 0 0 0

ram11 0 0 0 0 0 0 0 0 0 0

ram12 0 0 0 0 0 0 0 0 0 0

ram13 0 0 0 0 0 0 0 0 0 0

ram14 0 0 0 0 0 0 0 0 0 0

ram15 0 0 0 0 0 0 0 0 0 0

sda 4636 2835 126957 19796 1679 2472 33208 24702 0 16

hdc 195 116 1444 345 0 0 0 0 0 0

fd0 0 0 0 0 0 0 0 0 0 0

md0 0 0 0 0 0 0 0 0 0 0

[root@vm51: ~]#sar -d 1 2 可看现在到之后2秒的数据

Linux 2.6.18-8.el5 (vm51.com) 01/23/2008

04:20:14 PM DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm %util

04:20:15 PM dev8-0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00

04:20:15 PM dev22-0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00

04:20:15 PM DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm %util

04:20:16 PM dev8-0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00

04:20:16 PM dev22-0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00

Average: DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm %util

Average: dev8-0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00

Average: dev22-0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00

tps:每秒读取次数

sar 命令行的常用格式:
sar [options] [-A] [-o file] t [n]
在命令行中,n 和t 两个参数组合起来定义采样间隔和次数,t为采样间隔,是必须有
的参数,n为采样次数,是可选的,默认值是1,-o file表示将命令结果以二进制格式
存放在文件中,file 在此处不是关键字,是文件名。options 为命令行选项,sar命令
的选项很多,下面只列出常用选项:
-A:所有报告的总和。
-u:CPU利用率
-v:进程、I节点、文件和锁表状态。
-d:硬盘使用报告。 (看过去数据)
-r:没有使用的内存页面和硬盘块。
-q:看CPU负载。
-g:串口I/O的情况。
-b:缓冲区使用情况。
-a:文件读写情况。
-c:系统调用情况。
-R:进程的活动情况。
-y:终端设备活动情况。
-w:系统交换活动。

[root@vm51: ~]#mpstat 用于看多CPU

Linux 2.6.18-8.el5 (vm51.com) 01/23/2008

04:28:57 PM CPU %user %nice %sys %iowait %irq %soft %steal %idle intr/s

04:28:57 PM all 0.73 0.00 2.24 0.80 0.05 0.14 0.00 96.03 1013.95

ipcs 进程间通讯。

[root@vm51: ~]#ipcs

—— Shared Memory Segments ——–共享内存

key shmid owner perms bytes nattch status

—— Semaphore Arrays ——–信号灯:两进程之间协调用

key semid owner perms nsems

—— Message Queues ——–消息队列

key msqid owner perms used-bytes messages

[root@vm51: ~]#ipcrm -m shmid(共享ID) 删SHM共享内存(Orecal时用)

lsof、strace、ltrace命令:

lsof 刷/proc文件系统

[root@vm51: ~]#lsof -p 1 -p:PID

COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME

init 1 root cwd DIR 8,1 4096 2 /

init 1 root rtd DIR 8,1 4096 2 /

init 1 root txt REG 8,1 38620 654239 /sbin/init

init 1 root mem REG 8,1 121684 427404 /lib/ld-2.5.so

init 1 root mem REG 8,1 1576952 427405 /lib/libc-2.5.so

init 1 root mem REG 8,1 16528 427406 /lib/libdl-2.5.so

init 1 root mem REG 8,1 242880 427422 /lib/libsepol.so.1

init 1 root mem REG 8,1 93512 427423 /lib/libselinux.so.1

init 1 root 10u FIFO 0,16 927 /dev/initctl

[root@vm51: ~]#watch lsof -p PID

[root@vm51: ~]#strace -p PID 显示系统调用,追踪程序在干什么

[root@vm51: ~]#strace apachectl start

[root@vm51: ~]#ltrace /bin/ls

[root@vm51: ~]#time /bin/ls 看执行命令用了多少时间

anaconda-ks.cfg Desktop install.log install.log.syslog password tq tqwjj u

real 0m0.013s

user 0m0.001s

sys 0m0.011s

三、/proc文件系统及内核参数调整

/proc/interrupts 中断

/proc/ioports I/O资源

/proc/meminfo 内存信息

/proc/cpuinfo CPU信息

/proc/devices 设备文件

例:

[root@vm51: ~]#vim /etc/modprobe.conf

alias scsi_hostadapter mptbase

alias scsi_hostadapter1 mptspi

alias snd-card-0 snd-ens1371

options snd-card-0 index=0

options snd-ens1371 index=0

remove snd-ens1371 { /usr/sbin/alsactl store 0 >/dev/null 2>&1 || : ; }; /sbin/modprobe -r –ignore-remove snd-ens

1371

alias eth0 pcnet32

写:options eth0 irq=10 ioports=

中断冲突时改

/proc/sys/目录下的文件是要我们改的,即调优。

例:

[root@vm51: ~]#cat /proc/sys/net/ipv4/ip_forward

0

[root@vm51: ~]#echo > 1 /proc/sys/net/ipv4/ip_forward 临时修改

[root@vm51: ~]#sysctl -w net.ipv4.ip_forward=1 临时修改

net.ipv4.ip_forward = 1

永久生效:

[root@vm51: ~]#vim /etc/sysctl.conf

写:net.ipv4.ip_forward = 1

[root@vm51: ~]#sysctl -p 读取/etc/sysctl.conf配置文件内容,并重新设置一遍。(永久生效)

日志管理

Posted by TQ on 十月 11th, 2009

日志服务:syslog

分为:kernel logger 内核日志;

system logger 系统日志。

[root@vm5: ~]#service syslog restart

Shutting down kernel logger: [ OK ]

Shutting down system logger: [ OK ]

Starting system logger: [ OK ]

Starting kernel logger: [ OK ]

查看内核日志用dmesg命令。

[root@vm5: ~]#dmesg

Linux version 2.6.18-8.el5 (brewbuilder@ls20-bc2-14.build.redhat.com) (gcc version 4.1.1 20070105 (Red Hat 4.1.1-52)) #1 SMP Fri Jan 26 14:15:21 EST 2007

BIOS-provided physical RAM map:

BIOS-e820: 0000000000000000 – 000000000009f800 (usable)

BIOS-e820: 000000000009f800 – 00000000000a0000 (reserved)

BIOS-e820: 00000000000ca000 – 00000000000cc000 (reserved)

BIOS-e820: 00000000000dc000 – 0000000000100000 (reserved)

BIOS-e820: 0000000000100000 – 000000000fef0000 (usable)

BIOS-e820: 000000000fef0000 – 000000000feff000 (ACPI data)

BIOS-e820: 000000000feff000 – 000000000ff00000 (ACPI NVS)

BIOS-e820: 000000000ff00000 – 0000000010000000 (usable)

BIOS-e820: 00000000fec00000 – 00000000fec10000 (reserved)

BIOS-e820: 00000000fee00000 – 00000000fee01000 (reserved)

BIOS-e820: 00000000fffe0000 – 0000000100000000 (reserved)

0MB HIGHMEM available.

256MB LOWMEM available.

found SMP MP-table at 000f6cd0

Using x86 segment limits to approximate NX protection

On node 0 totalpages: 65536

DMA zone: 4096 pages, LIFO batch:0

Normal zone: 61440 pages, LIFO batch:15

DMI present.

Using APIC driver default

ACPI: RSDP (v000 PTLTD ) @ 0×000f6c60

ACPI: RSDT (v001 PTLTD RSDT 0×06040000 LTP 0×00000000) @ 0×0fefab5a

—————————————后面内容省略了,太多了—————————————

/var/log/:登录文件放置的目录。

/var/log/messages:是总管所有登录文件的文件(即:日志文件)。

syslog日志服务的配置文件:/etc/syslog.conf 。

[root@vm5: ~]#vim /etc/syslog.conf

# Log all kernel messages to the console.

# Logging much else clutters up the screen.

#kern.* /dev/console

# Log anything (except mail) of level info or higher.

# Don’t log private authentication messages!

*.info;mail.none;news.none;authpriv.none;cron.none /var/log/messages

# The authpriv file has restricted access.

authpriv.* /var/log/secure

# Log all the mail messages in one place.

mail.* -/var/log/maillog

注:-表示异步磁盘数据,有用缓存。

# Log cron stuff

cron.* /var/log/cron

# Everybody gets emergency messages

*.emerg *

# Save news errors of level crit and higher in a special file.

uucp,news.crit /var/log/spooler

# Save boot messages also to boot.log

local7.* /var/log/boot.log

#

# INN

#

news.=crit /var/log/news/news.crit

news.=err /var/log/news/news.err

news.notice /var/log/news/news.notice

说明:

日志有:对象.等级

对象.

邮件mail.

内核kern.

打印lpr.

新闻组mark.

news.

安全security. 同于auth.

日志本身syslog.

用户user.

uucp.

用户自定义local0.

local7.

.等级

.debug 问题信息 (低级)

.info 正常信息

.notice 通知(友好提示)

.warning

.warn 警告信息

.err

.error 错误信息

.crit 应急信息

.alert 比warning更警告

.emerg

.panic 很紧急,不解决不行了

(高级)

news.=crit 就这一级的信息;不加“=”就从本级到最高级。

news.!crit “!”:取反,除了crit级的信息。

news.*;news.crit;news.err “;”:排除等一个“分号;”后的信息。

*.info;mail.none .none表示不记。

-/var/log/maillog 注:-表示异步磁盘数据,有用缓存。

日志可写到设备上:如:/dev/tty12

日志可写给用户:(三种)

⑴ “用户名”,如:root

⑵ @IP地址,如:@192.168.0.66 表示接收来自192.168.0.66发来的日志,要开启远程管理(加-r) (在客户端)

⑶ *,表示给所有用户。

开启日志服务的远程管理功能,在/etc/sysconfig/syslog文件中设置。

[root@vm5: ~]#vim /etc/sysconfig/syslog

# Options to syslogd

# -m 0 disables ‘MARK’ messages.

# -r enables logging from remote machines

# -x disables DNS lookups on messages recieved with -r

# See syslogd(8) for more details

SYSLOGD_OPTIONS=”-m 0 -r -x注:-mMAC -r:开启远程日志 -x:不DNS

# Options to klogd

# -2 prints all kernel oops messages twice; once for klogd to decode, and

# once for processing with ‘ksymoops’

# -x disables all klogd processing of oops messages entirely

# See klogd(8) for more details

KLOGD_OPTIONS=”-x”

#

SYSLOG_UMASK=077

# set this to a umask value to use for all log files as in umask(1).

# By default, all permissions are removed for “group” and “other”.

可以用ps aux | grep syslog 来查看是否开启“日志远程管理”功能。

[root@vm5: ~]#ps aux | grep syslog

root 4338 0.0 0.2 1688 576 ? Ss 05:00 0:00 syslogd -m 0 -r -x

root 4354 0.0 0.2 3884 680 pts/4 S+ 05:01 0:00 grep syslog

例:找本局域网内日志最多的机器。

[root@vm5: ~]#awk ‘{print $4}’ /var/log/messages | sort | uniq -c

297 10.0.4.4 sort:排序 –n:按数字排

413 localhost

1375 vm5

[root@vm5: ~]#awk ‘{print $4}’ /var/log/messages | uniq -c | sort -n

52 vm5 uniq:去除重复行 -c:计数

297 10.0.4.4

413 localhost

544 vm5

779 vm5

[root@vm5: ~]#awk ‘{print $4}’ /var/log/messages | sort | uniq -c | sort -n

297 10.0.4.4

413 localhost

1375 vm5

[root@vm5: ~]#awk ‘{print $4}’ /var/log/messages | sort | uniq -c | sort -nr

1375 vm5

413 localhost

297 10.0.4.4

[root@vm5: ~]#awk ‘{print $4}’ /var/log/messages | sort | uniq -c | sort -nr | head -1

1375 vm5

/etc/logrotate.d/下,是日志记录的信息。

[root@vm5: /etc/logrotate.d]#ls

acpid cups mgetty ppp rpm sa-update squid tux vsftpd.log

conman httpd named psacct samba setroubleshoot syslog up2date yum

[root@vm5: /etc/logrotate.d]#cat httpd

/var/log/httpd/*log {

missingok

notifempty

sharedscripts

postrotate

/bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null || true

endscript

}

配置文件在/etc/logrotate.conf中,用来设置日志来如何记录。

[root@vm5: ~]#vim /etc/logrotate.conf

# see “man logrotate” for details

# rotate log files weekly

weekly

# keep 4 weeks worth of backlogs

rotate 4

# create new (empty) log files after rotating old ones

create

# uncomment this if you want your log files compressed

#compress

# RPM packages drop log rotation information into this directory

include /etc/logrotate.d

# no packages own wtmp — we’ll rotate them here

/var/log/wtmp {

monthly

create 0664 root utmp

rotate 1

}

# system-specific logs may be also be configured here.

在计划任务中有:/etc/cron.daily/logrotate文件。

[root@vm5: ~]#vim /etc/cron.daily/logrotate

#!/bin/sh

/usr/sbin/logrotate /etc/logrotate.conf

EXITVALUE=$?

if [ $EXITVALUE != 0 ]; then

/usr/bin/logger -t logrotate “ALERT exited abnormally with [$EXITVALUE]”

fi

exit 0

logger命令,常在脚本中用,使用脚本进入日志。

[root@vm5: ~]#logger -p local0.info “aaaaaa” 注:-p:加对象.级别

[root@vm5: ~]#tail -1 /var/log/messages

Feb 6 05:49:07 vm5 root: aaaaaa

用户名

[root@vm5: ~]#logger -p local.info -t abc “bbbbbb” 注:-t:加标签。

[root@vm5: ~]#tail -1 /var/log/messages

Feb 6 05:51:25 vm5 abc: bbbbbb

标签

日志相关:用iptables记日志。

-j后加LOG –log-level info

日志级别

例:

[root@vm5: ~]#iptables -A INPUT -s 192.168.0.0/24 -p tcp –dport 80 -j LOG –log-level info

[root@vm5: ~]#tail -1 /var/log/messages

Feb 6 05:54:02 vm5 kernel: ip_tables: (C) 2000-2006 Netfilter Core Team

对象名

∵iptables是由内核直接的,只是kernel对象。

∴iptables只能指定其级别。

USB引导盘制作

Posted by TQ on 十月 11th, 2009

USB引导盘制作

2008年2月20日

一、系统启动过程:

开机→初始化BIOS→→启动引导器bootloader→→装载内核kernel→→启动init

(GRUB)

l 第一步,初始化BIOS设置启动顺序等基本输入输出系统。

MBR:Master Boot Recorder主引导分区 (512字节,0柱面、0磁头、第1个扇区)

446字节MBC:主引导代码(找可引导分区)

64字节DPT:4个16字节的主分区信息

2字节:55AA(十六进制数)表示结束。

l 第二步,启动引导器bootloader

⑴ grub:/boot/grub/grub.conf配置文件

# grub.conf generated by anaconda

#

# Note that you do not have to rerun grub after making changes to this file

# NOTICE: You do not have a /boot partition. This means that

# all kernel and initrd paths are relative to /, eg.

# root (hd0,0)

# kernel /boot/vmlinuz-version ro root=/dev/sda1

# initrd /boot/initrd-version.img

#boot=/dev/sda

default=0

timeout=5

splashimage=(hd0,0)/boot/grub/splash.xpm.gz

hiddenmenu

title Red Hat Enterprise Linux Server (2.6.18-8.el5)

root (hd0,0)

注:hd0:第一个硬盘 , 0:第一个分区

hd0是由/boot/grub/device.map硬盘映射的。

kernel /boot/vmlinuz-2.6.18-8.el5 ro root=LABEL=/ rhgb quiet 安静:不显示selinux提示的错误信息等其它信息。

注:根分区为卷标为/的。

initrd /boot/initrd-2.6.18-8.el5.img

注:[root@vm5: /boot]#ls

config-2.6.18-8.el5 initrd-2.6.18-8.el5.img System.map-2.6.18-8.el5

grub symvers-2.6.18-8.el5.gz vmlinuz-2.6.18-8.el5

[root@vm5: /boot]#mkdir initrd

[root@vm5: /boot]#ls

config-2.6.18-8.el5 initrd symvers-2.6.18-8.el5.gz vmlinuz-2.6.18-8.el5

grub initrd-2.6.18-8.el5.img System.map-2.6.18-8.el5

[root@vm5: /boot]#gunzip < initrd-2.6.18-8.el5.img > initrd/initrd.img

[root@vm5: /boot]#cd initrd

[root@vm5: /boot/initrd]#ls

initrd.img

[root@vm5: /boot/initrd]#file initrd.img

initrd.img: ASCII cpio archive (SVR4 with no CRC)

[root@vm5: /boot/initrd]#cpio -iv < initrd.img

sys

lib

lib/mptspi.ko

lib/ext3.ko 载入:ext3驱动模块

lib/mptbase.ko

lib/sd_mod.ko 载入:sd驱动模块

lib/ohci-hcd.ko 载入:other芯片驱动模块

lib/jbd.ko

lib/mptscsih.ko

lib/ehci-hcd.ko 载入:USB2.0驱动模块

lib/uhci-hcd.ko 载入:USB1.1驱动模块

lib/scsi_mod.ko 载入:SCSI驱动模块

lib/scsi_transport_spi.ko

etc

proc

init

bin

bin/nash

bin/modprobe

bin/insmod

sysroot

dev

dev/mapper

dev/tty7

dev/tty3

dev/tty2

dev/tty0

dev/ttyS0

dev/tty6

dev/ram

dev/ram1

dev/rtc

dev/zero

dev/tty11

dev/ptmx

dev/tty

dev/tty5

dev/console

dev/tty10

dev/ttyS1

dev/tty1

dev/tty8

dev/tty4

dev/null

dev/tty9

dev/ram0

dev/tty12

dev/ttyS2

dev/systty

dev/ttyS3

sbin

6761 blocks

[root@vm5: /boot/initrd]#ls

bin dev etc init initrd.img lib proc sbin sys sysroot

[root@vm5: /boot/initrd]#vim init

#!/bin/nash

mount -t proc /proc /proc

setquiet

echo Mounting proc filesystem

echo Mounting sysfs filesystem

mount -t sysfs /sys /sys

echo Creating /dev

mount -o mode=0755 -t tmpfs /dev /dev

mkdir /dev/pts

mount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts

mkdir /dev/shm

mkdir /dev/mapper

echo Creating initial device nodes

mknod /dev/null c 1 3

mknod /dev/zero c 1 5

mknod /dev/systty c 4 0

mknod /dev/tty c 5 0

mknod /dev/console c 5 1

mknod /dev/ptmx c 5 2

mknod /dev/rtc c 10 135

mknod /dev/tty0 c 4 0

mknod /dev/tty1 c 4 1

mknod /dev/tty2 c 4 2

mknod /dev/tty3 c 4 3

mknod /dev/tty4 c 4 4

mknod /dev/tty5 c 4 5

mknod /dev/tty6 c 4 6

mknod /dev/tty7 c 4 7

mknod /dev/tty8 c 4 8

mknod /dev/tty9 c 4 9

mknod /dev/tty10 c 4 10

mknod /dev/tty11 c 4 11

mknod /dev/tty12 c 4 12

mknod /dev/ttyS0 c 4 64

⑵ initrd:解决驱动问题(rd:run disk)

initrd /boot/initrd-2.6.18-8.el5.img

l 第三步,装载内核kernel

kernel /boot/vmlinuz-2.6.18-8.el5 ro root=LABEL=/ rhgb quiet

l 第四步,初始化init

/etc/inittab配置文件 →→初始化 /etc/rc.d/

#

# inittab This file describes how the INIT process should set up

# the system in a certain run-level.

#

# Author: Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>

# Modified for RHS Linux by Marc Ewing and Donnie Barnes

#

# Default runlevel. The runlevels used by RHS are:

# 0 – halt (Do NOT set initdefault to this)

# 1 – Single user mode

# 2 – Multiuser, without NFS (The same as 3, if you do not have networking)

# 3 – Full multiuser mode

# 4 – unused

# 5 – X11

# 6 – reboot (Do NOT set initdefault to this)

#

id:3:initdefault: 设置默认的运行级别为:3

# System initialization.

si::sysinit:/etc/rc.d/rc.sysinit sysinit:一定要运行完后面的脚本,再继续运行后面,有错也不停(继续运行后面程序)

l0:0:wait:/etc/rc.d/rc 0 wait:等运行完后面脚本,再继续运行会面,有错就停。

l1:1:wait:/etc/rc.d/rc 1

l2:2:wait:/etc/rc.d/rc 2

l3:3:wait:/etc/rc.d/rc 3

l4:4:wait:/etc/rc.d/rc 4

l5:5:wait:/etc/rc.d/rc 5

l6:6:wait:/etc/rc.d/rc 6

# Trap CTRL-ALT-DELETE

ca::ctrlaltdel:/sbin/shutdown -t3 -r now

# When our UPS tells us power has failed, assume we have a few minutes

# of power left. Schedule a shutdown for 2 minutes from now.

# This does, of course, assume you have powerd installed and your

# UPS connected and working correctly.

pf::powerfail:/sbin/shutdown -f -h +2 “Power Failure; System Shutting Down”

# If power was restored before the shutdown kicked in, cancel it.

pr:12345:powerokwait:/sbin/shutdown -c “Power Restored; Shutdown Cancelled”

# Run gettys in standard runlevels

1:2345:respawn:/sbin/mingetty tty1 respawn:可重生

2:2345:respawn:/sbin/mingetty tty2

3:2345:respawn:/sbin/mingetty tty3

4:2345:respawn:/sbin/mingetty tty4

5:2345:respawn:/sbin/mingetty tty5

6:2345:respawn:/sbin/mingetty tty6

# Run xdm in runlevel 5

x:5:respawn:/etc/X11/prefdm –nodaemon

/etc/inittab配置文件 →→初始化: /etc/rc.d/rc.sysinit 键盘、鼠标驱动

(5步) /etc/rc.d/rc 运行级别

/etc/rc.d/rc.local

系统环境配置

l 说明:

⑴ initrd先于kernel,如果kernel中有硬盘等驱动就不用initrd了。

RHEL5的kernel中没有硬盘驱动,所以得先initrd再装载kernel。

⑵ 当前模块配置文件在:/boot/config-2.6.18-8.el5中,同/usr/local/src/`uname -r`/.config文件

⑶ /boot/grub中,menu.lst -> ./grub.conf

⑷ 在第四步中,

/etc/inittab配置文件 →→初始化 /etc/rc.d/rc.sysinit 键盘、鼠标驱动

/etc/rc.d/rc 运行级别

/etc/rc.d/rc.local 系统环境配置

二、U盘引导制作方法、步骤:

⑴ 对U盘分区、格式化为EXT3文件系统并且加可引导。

[root@vm5: ~]#fdisk /dev/sdb

按a,加可引导。

[root@vm5: ~]#partprobe

[root@vm5: ~]#mke2fs -j /dev/sdb1

⑵ 安装目录树。

[root@vm5: /mnt/Server]#rpm -ivh –nodeps –force –root=/mnt/ filesystem-2.4.0-1.i386.rpm

⑶ 安装grub。

[root@vm5: /mnt/Server]#rpm -ivh –nodeps –force –root=/mnt/ grub-0.97-13.i386.rpm

⑶ 拷贝应用程序到U盘。注:不要覆盖刚刚生成的文件或目录。

[root@vm5: ~]#cp -rf /bin/* /mnt/bin/

[root@vm5: ~]#cp -rf /sbin/* /mnt/sbin/

[root@vm5: ~]#cp -rf /usr/bin/* /mnt/usr/bin/

[root@vm5: ~]#cp -rf /usr/sbin/* /mnt/usr/sbin/

⑷ 拷贝库文件到U盘。注:不要覆盖刚刚生成的文件或目录。

[root@vm5: ~]#cp -rf /lib/* /mnt/lib/

[root@vm5: ~]#cp -rf /usr/lib/* /mnt/usr/lib/ ←如果文件太大,可不拷

⑸ 拷贝/boot/*到U盘之后,在U盘中修改/mnt/boot/grub/grub.conf配置文件、修改/mnt/boot/grub/device.map硬盘映射文件等。

[root@vm5: ~]#cp -rf /boot/* /mnt/boot/

[root@vm5: /mnt]#vim boot/grub/grub.conf

改:default=0

timeout=5

hiddenmenu

title Red Hat Enterprise Linux Server USB LINUX (2.6.18-8.el5)

root (hd0,0)

kernel /boot/vmlinuz-2.6.18-8.el5 ro root=/dev/sdb1 init=/bin/bash

注:不能有多于的“空格”,否则,无法引导成功!

initrd /boot/initrd_usb.img

[root@vm5: /mnt]#vim boot/grub/device.map

写:(hd0) /dev/sdb

⑹ 创建设备文件。 块 主 从

[root@vm5: ~]#mknod /mnt/dev/sdb b 8 16

[root@vm5: ~]#mknod /mnt/dev/sdb1 b 8 17

说明:主设备号:用同一个驱动。

从设备号:记录分区号。

[root@vm5: /mnt/Server]#rpm -ivh kernel-doc-2.6.18-8.el5.noarch.rpm安装内核文档,查看/usr/share/doc/kernel-doc-2.6.18/Documentation/devices.txt文档来学习主设备号、从设备号等说明。

⑺ 加载驱动到initrd。 注:加载顺序不能错!

[root@vm5: ~]#mkinitrd –with=sd_mod –with=scsi_mod –with=uhci-mod –with=ehci-hcd –with=usb-storage /mnt/boot/ initrd_usb.img `uname -r`

说明:initrd_usb.img为U盘中/mnt/boot/grub/grub.conf配置文件中initrd /boot/initrd_usb.img 。

⑻ 拷贝/etc/fstab和/etc/mtab,并加以修改。

[root@vm5: ~]#cp /etc/fstab /mnt/etc/fstab

只写:/dev/sdb1 / ext3 defaults 1 1

[root@vm5: ~]#cp /etc/mtab /mnt/etc/mtab

只写:/dev/sdb1 / ext3 rw 0 0

⑼ 切换U盘/mnt/为/根分区。

[root@vm5: ~]#chroot /mnt

⑽ 重装sdb,修复MBR。

sh-3.1#grub-install /dev/sdb

sh-3.1#grub-install –recheck /dev/sdb

注:检测(也可不用)

至此,U盘引导盘制作完毕!用sync命令同步一下磁盘,重启系统。

改BIOS为USB-HDD为第一启动,即可用U盘引导Linux系统了!!!

USB引导盘制作

Posted by TQ on 十月 11th, 2009

USB引导盘制作

2008年2月20日

 

一、系统启动过程:

开机→初始化BIOS→→启动引导器bootloader→→装载内核kernel→→启动init

                                                     (GRUB)

                            

l        第一步,初始化BIOS设置启动顺序等基本输入输出系统。

MBR:Master Boot Recorder主引导分区 (512字节,0柱面、0磁头、第1个扇区)

446字节MBC:主引导代码(找可引导分区)

64字节DPT:4个16字节的主分区信息

2字节:55AA(十六进制数)表示结束。

 

 

l        第二步,启动引导器bootloader

⑴ grub:/boot/grub/grub.conf配置文件

# grub.conf generated by anaconda

#

# Note that you do not have to rerun grub after making changes to this file

# NOTICE:  You do not have a /boot partition.  This means that

#          all kernel and initrd paths are relative to /, eg.

#          root (hd0,0)

#          kernel /boot/vmlinuz-version ro root=/dev/sda1

#          initrd /boot/initrd-version.img

#boot=/dev/sda

default=0

timeout=5

splashimage=(hd0,0)/boot/grub/splash.xpm.gz

hiddenmenu

title Red Hat Enterprise Linux Server (2.6.18-8.el5)

        root (hd0,0)                              

        注:hd0:第一个硬盘 , 0:第一个分区

                hd0是由/boot/grub/device.map硬盘映射的。

       

kernel /boot/vmlinuz-2.6.18-8.el5 ro root=LABEL=/ rhgb quiet 安静:不显示selinux提示的错误信息等其它信息。

注:根分区为卷标为/的。

       

initrd /boot/initrd-2.6.18-8.el5.img

注:[root@vm5: /boot]#ls

config-2.6.18-8.el5  initrd-2.6.18-8.el5.img  System.map-2.6.18-8.el5

grub                 symvers-2.6.18-8.el5.gz  vmlinuz-2.6.18-8.el5

[root@vm5: /boot]#mkdir initrd

[root@vm5: /boot]#ls

config-2.6.18-8.el5  initrd                   symvers-2.6.18-8.el5.gz  vmlinuz-2.6.18-8.el5

grub                 initrd-2.6.18-8.el5.img  System.map-2.6.18-8.el5

[root@vm5: /boot]#gunzip < initrd-2.6.18-8.el5.img > initrd/initrd.img

[root@vm5: /boot]#cd initrd

[root@vm5: /boot/initrd]#ls

initrd.img

[root@vm5: /boot/initrd]#file initrd.img

initrd.img: ASCII cpio archive (SVR4 with no CRC)

[root@vm5: /boot/initrd]#cpio -iv < initrd.img

sys

lib

lib/mptspi.ko

lib/ext3.ko        载入:ext3驱动模块

lib/mptbase.ko                   

lib/sd_mod.ko          载入:sd驱动模块

lib/ohci-hcd.ko     载入:other芯片驱动模块

lib/jbd.ko

lib/mptscsih.ko

lib/ehci-hcd.ko         载入:USB2.0驱动模块

lib/uhci-hcd.ko     载入:USB1.1驱动模块

lib/scsi_mod.ko         载入:SCSI驱动模块

lib/scsi_transport_spi.ko

etc

proc

init

bin

bin/nash

bin/modprobe

bin/insmod

sysroot

dev

dev/mapper

dev/tty7

dev/tty3

dev/tty2

dev/tty0

dev/ttyS0

dev/tty6

dev/ram

dev/ram1

dev/rtc

dev/zero

dev/tty11

dev/ptmx

dev/tty

dev/tty5

dev/console

dev/tty10

dev/ttyS1

dev/tty1

dev/tty8

dev/tty4

dev/null

dev/tty9

dev/ram0

dev/tty12

dev/ttyS2

dev/systty

dev/ttyS3

sbin

6761 blocks

[root@vm5: /boot/initrd]#ls

bin  dev  etc  init  initrd.img  lib  proc  sbin  sys  sysroot

[root@vm5: /boot/initrd]#vim init

#!/bin/nash

 

mount -t proc /proc /proc

setquiet

echo Mounting proc filesystem

echo Mounting sysfs filesystem

mount -t sysfs /sys /sys

echo Creating /dev

mount -o mode=0755 -t tmpfs /dev /dev

mkdir /dev/pts

mount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts

mkdir /dev/shm

mkdir /dev/mapper

echo Creating initial device nodes

mknod /dev/null c 1 3

mknod /dev/zero c 1 5

mknod /dev/systty c 4 0

mknod /dev/tty c 5 0

mknod /dev/console c 5 1

mknod /dev/ptmx c 5 2

mknod /dev/rtc c 10 135

mknod /dev/tty0 c 4 0

mknod /dev/tty1 c 4 1

mknod /dev/tty2 c 4 2

mknod /dev/tty3 c 4 3

mknod /dev/tty4 c 4 4

mknod /dev/tty5 c 4 5

mknod /dev/tty6 c 4 6

mknod /dev/tty7 c 4 7

mknod /dev/tty8 c 4 8

mknod /dev/tty9 c 4 9

mknod /dev/tty10 c 4 10

mknod /dev/tty11 c 4 11

mknod /dev/tty12 c 4 12

mknod /dev/ttyS0 c 4 64

 

⑵ initrd:解决驱动问题(rd:run disk)

   initrd /boot/initrd-2.6.18-8.el5.img

 

 

l        第三步,装载内核kernel

kernel /boot/vmlinuz-2.6.18-8.el5 ro root=LABEL=/ rhgb quiet

 

l        第四步,初始化init

/etc/inittab配置文件  →→初始化 /etc/rc.d/

#

# inittab       This file describes how the INIT process should set up

#               the system in a certain run-level.

#

# Author:       Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>

#               Modified for RHS Linux by Marc Ewing and Donnie Barnes

#

 

# Default runlevel. The runlevels used by RHS are:

#   0 – halt (Do NOT set initdefault to this)

#   1 – Single user mode

#   2 – Multiuser, without NFS (The same as 3, if you do not have networking)

#   3 – Full multiuser mode

#   4 – unused

#   5 – X11

#   6 – reboot (Do NOT set initdefault to this)

#

id:3:initdefault:                         设置默认的运行级别为:3

 

# System initialization.

si::sysinit:/etc/rc.d/rc.sysinit      sysinit:一定要运行完后面的脚本,再继续运行后面,有错也不停(继续运行后面程序)

 

l0:0:wait:/etc/rc.d/rc 0             wait:等运行完后面脚本,再继续运行会面,有错就停。

l1:1:wait:/etc/rc.d/rc 1

l2:2:wait:/etc/rc.d/rc 2

l3:3:wait:/etc/rc.d/rc 3

l4:4:wait:/etc/rc.d/rc 4

l5:5:wait:/etc/rc.d/rc 5

l6:6:wait:/etc/rc.d/rc 6

 

# Trap CTRL-ALT-DELETE

ca::ctrlaltdel:/sbin/shutdown -t3 -r now

 

# When our UPS tells us power has failed, assume we have a few minutes

# of power left.  Schedule a shutdown for 2 minutes from now.

# This does, of course, assume you have powerd installed and your

# UPS connected and working correctly. 

pf::powerfail:/sbin/shutdown -f -h +2 “Power Failure; System Shutting Down”

 

# If power was restored before the shutdown kicked in, cancel it.

pr:12345:powerokwait:/sbin/shutdown -c “Power Restored; Shutdown Cancelled”

 

# Run gettys in standard runlevels

1:2345:respawn:/sbin/mingetty tty1                      respawn:可重生

2:2345:respawn:/sbin/mingetty tty2

3:2345:respawn:/sbin/mingetty tty3

4:2345:respawn:/sbin/mingetty tty4

5:2345:respawn:/sbin/mingetty tty5

6:2345:respawn:/sbin/mingetty tty6

 

 

# Run xdm in runlevel 5

x:5:respawn:/etc/X11/prefdm –nodaemon

 

 

/etc/inittab配置文件  →→初始化: /etc/rc.d/rc.sysinit  键盘、鼠标驱动

                      (5步)   /etc/rc.d/rc  运行级别

                                /etc/rc.d/rc.local 

                                                 系统环境配置

                                                                  

 

l        说明:

⑴    initrd先于kernel,如果kernel中有硬盘等驱动就不用initrd了。

RHEL5的kernel中没有硬盘驱动,所以得先initrd再装载kernel。

 

⑵ 当前模块配置文件在:/boot/config-2.6.18-8.el5中,同/usr/local/src/`uname -r`/.config文件

 

⑶ /boot/grub中,menu.lst -> ./grub.conf

 

⑷ 在第四步中,

/etc/inittab配置文件  →→初始化 /etc/rc.d/rc.sysinit  键盘、鼠标驱动

                              /etc/rc.d/rc  运行级别

                              /etc/rc.d/rc.local  系统环境配置

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

二、U盘引导制作方法、步骤:

⑴ 对U盘分区、格式化为EXT3文件系统并且加可引导。

[root@vm5: ~]#fdisk /dev/sdb

按a,加可引导。

[root@vm5: ~]#partprobe

[root@vm5: ~]#mke2fs -j /dev/sdb1

 

⑵ 安装目录树。

[root@vm5: /mnt/Server]#rpm -ivh –nodeps –force –root=/mnt/ filesystem-2.4.0-1.i386.rpm

 

⑶ 安装grub。

[root@vm5: /mnt/Server]#rpm -ivh –nodeps –force –root=/mnt/ grub-0.97-13.i386.rpm

 

⑶ 拷贝应用程序到U盘。注:不要覆盖刚刚生成的文件或目录。

[root@vm5: ~]#cp -rf /bin/* /mnt/bin/

[root@vm5: ~]#cp -rf /sbin/* /mnt/sbin/

[root@vm5: ~]#cp -rf /usr/bin/* /mnt/usr/bin/

[root@vm5: ~]#cp -rf /usr/sbin/* /mnt/usr/sbin/

 

⑷ 拷贝库文件到U盘。注:不要覆盖刚刚生成的文件或目录。

[root@vm5: ~]#cp -rf /lib/* /mnt/lib/

[root@vm5: ~]#cp -rf /usr/lib/* /mnt/usr/lib/        ←如果文件太大,可不拷

 

⑸ 拷贝/boot/*到U盘之后,在U盘中修改/mnt/boot/grub/grub.conf配置文件、修改/mnt/boot/grub/device.map硬盘映射文件等。

[root@vm5: ~]#cp -rf /boot/* /mnt/boot/

[root@vm5: /mnt]#vim boot/grub/grub.conf

改:default=0

timeout=5

hiddenmenu

title Red Hat Enterprise Linux Server  USB  LINUX  (2.6.18-8.el5)

        root (hd0,0)

        kernel /boot/vmlinuz-2.6.18-8.el5 ro root=/dev/sdb1 init=/bin/bash

        注:不能有多于的“空格”,否则,无法引导成功!

        initrd /boot/initrd_usb.img

[root@vm5: /mnt]#vim boot/grub/device.map

写:(hd0)    /dev/sdb

 

⑹ 创建设备文件。            块 主 从

[root@vm5: ~]#mknod /mnt/dev/sdb b 8 16

[root@vm5: ~]#mknod /mnt/dev/sdb1 b 8 17

说明:主设备号:用同一个驱动。

从设备号:记录分区号。

[root@vm5: /mnt/Server]#rpm -ivh kernel-doc-2.6.18-8.el5.noarch.rpm安装内核文档,查看/usr/share/doc/kernel-doc-2.6.18/Documentation/devices.txt文档来学习主设备号、从设备号等说明。

 

⑺ 加载驱动到initrd。 注:加载顺序不能错!

[root@vm5: ~]#mkinitrd –with=sd_mod –with=scsi_mod –with=uhci-mod –with=ehci-hcd –with=usb-storage /mnt/boot/ initrd_usb.img `uname -r`

说明:initrd_usb.img为U盘中/mnt/boot/grub/grub.conf配置文件中initrd /boot/initrd_usb.img 。

 

⑻ 拷贝/etc/fstab和/etc/mtab,并加以修改。

[root@vm5: ~]#cp /etc/fstab /mnt/etc/fstab

只写:/dev/sdb1   /   ext3  defaults   1 1

[root@vm5: ~]#cp /etc/mtab /mnt/etc/mtab

只写:/dev/sdb1   /   ext3   rw  0 0

 

⑼ 切换U盘/mnt/为/根分区。

[root@vm5: ~]#chroot /mnt

 

⑽ 重装sdb,修复MBR。

sh-3.1#grub-install /dev/sdb

sh-3.1#grub-install –recheck /dev/sdb

              注:检测(也可不用)

 

至此,U盘引导盘制作完毕!用sync命令同步一下磁盘,重启系统。

改BIOS为USB-HDD为第一启动,即可用U盘引导Linux系统了!!!


Copyright © 2009 TQ 试用 WP. All rights reserved.