UTC GMT linux时间

10:40:00 PM 0 Comments

keywork: 不同系统时间相差 八个小时 windows linux

计算机有两个时钟,一个是始终运行的、由电池供电的( CMOS )硬件时钟,另一个是由操作系统维护的( 系统 )时钟。
硬件时钟通常只在操作系统启动时用来设置系统时钟。
在Linux 系统中,可以选择用UTC/GMT 时间或本地时间来处理硬件时钟(也就是把CMOS提供的硬件时钟当作UTC标准时间)。
使用UTC 记录硬件时钟的唯一不足是,如果使用了双系统,其它操作系统,如windows要求硬件时钟用本地时间设置,那么在那个操作系统里时间将是错误的。
Fedora 7默认使用了UTC,所以会出现你所遇到的问题。
解决方法为:
打开:/etc/sysconfig/clock
内容为:
# The ZONE parameter is only evaluated by system-config-date.
# The timezone of the system is defined by the contents of /etc/localtime.
ZONE="Asia/Shanghai"
UTC=true
ARC=false
把UTC=true 修改为 UTC=false,保存后重启即可。
也可以右键点击时间栏,然后选择调整日期和时间,去掉时区下面的“系统时钟使用UTC”的选项,保存退出。

linux下加载Fat32和NTFS分区

10:38:00 PM 0 Comments

linux下加载Fat32和NTFS分区

Fat32:

1.临时挂载:在终端运行命令mount -t vfat -o iocharset=utf8,umask=000 /dev/hda2 /mnt/wind/

其中/dev/hda2替换为你要加载的分区/mnt/wind/替换为你的挂载目录。

2.开机自动挂载:在/etc/fstab文件中添加一行/dev/hda2 /mnt/wind vfat umask=000,iocharset=utf8

NTFS:

1.根据系统内核版本下载支持ntfs的内核补丁,安装。

2.临时挂载:mount -t ntfs -o nls=utf8,umask=000 /dev/hda1 /mnt/winc

修改红色部分,同上。

3.开机自动挂载:在/etc/fstab文件中添加一行,/dev/hda1 /mnt/winc ntfs umask=000,iocharset=utf8 0 0

使用 ttyutils 截获 UNIX/Linux 终端

8:21:00 PM 0 Comments

对于大多数 UNIX 和 Linux 用户,终端无疑是不可或缺的。本文将描述一个可以让 UNIX 终端会话完整受控的软件包,它叫做 Ttyutils。这篇文档将向大家介绍 Ttyutils 的基本使用方法以及它的实现机制。

在本文档中,UNIX 终端也泛指 Linux 终端。并且,本文中的终端不仅仅包括物理终端,也包括虚拟控制台,图形仿真终端,例如 xterm, 和具备网络能力的仿真终端,例如 putty。

为了有助更加形象的描述,这篇文档会使用截获,捕获,甚至偷窥这样的词语,但这是没有恶意的。

监控终端会话

在通常情况下,当用户从终端登录 UNIX 主机时,系统登录程序会记录用户的登录时间,主机名称等信息到系统 utmp 数据库和 wtmp 数据库,却不能跟踪用户进入 shell 之后的会话。

有一些程序,例如 script,可以记录用户在终端上的会话到一个文件中,然后在后来的某个时候通过那个文件重现用户当时的会话。script 的局限性在于它只能记录,而不能干涉用户的会话,例如当用户在命令行输入"rm -fr /"这样的命令时,它没有办法阻止。

在一些受控的环境中,系统管理员必须有能力实时的查看用户的会话,或者因为好奇,想偷窥远程登录到你的主机的用户在干些什么,并且,如果必要,还可以实时的禁止或者终止用户进行更多的操作,这是很有趣的。

在 UNIX 中,有很多使用终端作为人机交互接口的应用程序,例如常用的 shell, vi,还有一些特定于行业的应用程序,例如我们在银行里办理业务时,营业柜员使用的操作接口。如果能够通过截获和实时的分析程序的输出所引起的终端变化, 并可以根据这些变化的特征来触发特殊的动作将是非常有用的。例如,当用户在提示符下输入 vi 两个字符时,就自动的启动 vi 编辑器,这样就可以省去按下回车键的麻烦。

考虑这样的情况,有一个运行在终端上的重要软件包,例如金融机构的业务处理系统,需要对现有的业务进行改造,例如为了支持新的设备,但是却因为各种原因, 不能修改系统的代码。这可以通过对现有的系统进行监控和分析来做到,并且,因为没有直接修改现有的系统,可以很容易的移除或修改。

Ttyutils 是为这个目标设计的一个软件包,它主要包括三个实用程序:ttyexec,ttyadmin,和 ttylook。

安装 ttyutils

Ttyutils 软件包使用 RPM 包发布,首先从参考资源列出的地址下载 ttyutils 软件包的最新版本,然后使用下面的命令安装 :

# rpm -Uvh ./ttyutils-@version.@release.@platform.rpm

其中 @version,@release 和 @platform 分别是版本号,发行号,以及平台。

安装 RPM 软件包通常需要 root 权限。

安装完成后,你可能需要配置一下日志文件。Ttyutils 的日志采用 syslog 函数记录,采用的 facility 为 LOG_LOCAL3,默认情况下,在 Linux 平台,所有消息将输出到 /var/log/messages 文件中,可以通过配置 /etc/syslog.conf 来重定向到一个单独的文件中,例如下面是一个例子 :

# Save ttyutils messages to ttyutils.log
local3.* /var/log/ttyutils.log

对于不支持 local3 作为 facility 的系统,可以采用下面的语法 :

# Save ttyutils messages to ttyutils.log
*.debug /var/log/syslog.out

Ttyutils 软件包的程序支持 --logfile 选项,它可以将日志重定向到一个指定的文件中。

一切就绪,下面开始一个简单的会话。

登录两个终端 A 和 B,在终端 A 的 shell 提示符下输入 :

$ ttyexec
$ tty
/dev/pts/3

其中"/dev/pts/3"是 tty 命令的输出,可能会是其它的名字,记住这个名字,然后在终端 B 输入:

$ ttylook --pts /dev/pts/3 -w

这时终端 A 的输出将会反应在终端 B,反之亦然。

其中,ttyexec 是监控程序,它的使用方法与 shell 中命令 exec 相似,被 ttyexec 启动的程序的输入输出将被 ttyexec 截获,如果没有参数,那么它会执行在 /etc/passwd 文件中为当前用户设置的 shell 程序。

当通过 ttyexec 在终端 A 监控了一个程序之后,ttyexec 自身不会记录任何关于会话的标准输入输出信息到某个文件或者其它地方,如果用户想查看被监控的程序的标准输出,需要使用在另外一个终端 B 上使用 ttylook 连接到那个 ttyexec,当连接建立以后,ttyexec 就会将截获的数据发送给 ttylook,而 ttylook 则将这些数据输出到终端 B 上。这个时候,终端 B 的屏幕和终端 A 的屏幕将会一样,并且如果不断开连接,将会实时的保持同步。这就相当于两个终端共享了一个用户会话。因为 ttyexec 支持多个 ttylook 连接,也就是说可以三个,四个,或者更多个终端共享同一个用户会话。

ttyadmin 是用于管理当前系统中运行的 ttyexec 进程的工具,对于熟悉 Ttyutils 的用户,它提供了一些很有用的功能。

使用 ttyexec 截获用户会话

ttyexec 是监控程序,被它监控的程序的标准输入输出将会被 ttyexec 截获,ttyexec 的用法很简单,只需要在命令行指定一个将被监控的程序名称即可,例如:

$ ttyexec vim

如果那个程序需要参数,直接跟在命令行后面即可,例如 :

$ ttyexec vim /etc/inittab

使用 ttyexec 不需要任何的特权。

如果没有在命令行中指定一个程序名称,那么 ttyexec 将会尝试去执行当前用户在 /etc/passwd 文件中登记的 shell 程序。

一个简单的技巧用来完整的监控用户从登录开始到退出登录之间的完整会话,就是在用户的 profile 文件最后加入下面的二行 :

ttyexec
exit $?

在本文档中,运行一个 ttyexec 实例就是为了监控一个用户在终端的会话,所以,有时候为了描述方便,也用一个 ttyexec 实例来代表一个监控的用户会话。

使用 ttylook 控制用户会话

当使用 ttyexec 监控了一个程序之后,如果想偷窥被监控终端上的会话,就需要在另外一个终端使用 ttylook 连接到 ttyexec。

使用 ttylook,必须要知道运行 ttyexec 的那个终端的终端名称,伪终端名称,或者进程 ID 中的至少一个。这可以很容易的从 ttyadmin 获得,看下图:


图 1 ttyadmin 截图

这是运行在 IBM AIX5.1 上的 ttyadmin 的截图,在主窗口中,每一行列出了当前系统中的一个 ttyexec 实例,信息包括运行它的用户 ( 图中故意模糊了 ),进程 ID,终端名称,伪终端名称,运行的时间和运行的命令。

在上图中我们可以看到当前系统有 13 个 ttyexec 实例在运行。

在上图中,如果用 ttylook 连接被监控的终端 /dev/pts/16,可以使用下面的命令中的任意一个,它们是等价的:

$ ttylook --tty /dev/pts/16
$ ttylook --pid 319688
$ ttylook --pts /dev/ttypf

在默认情况下,ttylook 在只读模式运行,也就是说,它只能偷窥被监控的终端,而不能操作被监控的终端,如果要操作被监控的终端,它必须通过命令行 --writable 进入可写模式。

但是进入了可写模式很危险,特别是你不希望让被监控终端上的用户发现的时候。所以默认是只读模式。

回顾一下,假设用户 1 在终端 A 在上运行着 ttyexec,用户 2 在终端 B 上运行着 ttylook,当 ttylook 连接到的 ttyexec 实例后,终端 A 和终端 B 的屏幕内容将实时同步,所以,用户 1 在被监控终端上的所有会话对于用户 2 而言就暴露无遗了。

使用 ttyadmin 管理 ttyexec 实例

在系统中通常会有多个 ttyexec 实例在运行,前面的 ttyadmin 截图已经大致说明了 ttyadmin 的用途,但它除了可以列出当前系统中所有的 ttyexec 实例外,还有一些其它的用途,例如它可以很容易的启动 ttylook,查看 ttyexec 实例的事件表等等。

使用 ttyexec 的事件触发

如果只是希望监控用户在终端上的会话的话,那么只需要使用前面描述的内容即可,但是如果还想得到更多,那么就可能需要这里描述的内容- 事件触发。

ttyexec 的一个有用的机制是事件触发,它是根据被监控程序的标准输出引起终端屏幕的变化来工作的,每当被监控程序改变终端屏幕的内容时,ttyexec 会根据更新后的屏幕内容与事件表中的事件条件进行匹配,如果成功,那么就会执行一个事件定义的程序。

事件表

在 ttyexec 内容维护了一个事件表,每个节点是一个事件,每个事件由 4 个部分组成:

  • 事件的名称;
  • 事件的组名称;
  • 事件的匹配器;
  • 事件的动作;

事件名称 是事件唯一的标识, 事件组名称 是对多个事件的划分,这两个名称主要用于事件的管理。

事件匹配器 由一个或多个 事件条件 组成,每个 事件条件 又根据类型的不同而不同,我们介绍完虚拟终端后再回头描述事件条件。

事件动作 是一个程序的名称和它的参数 ( 如果有的话 ),它是一个标准的可执行程序,在事件的匹配器得到匹配时执行。

虚拟终端

ttyexec 内部运行着一个虚拟的终端,它可以正确的解析发送到实际终端的那些控制序列,并在内存中重构一个和真实终端屏幕一样大小的屏幕,它的内容和用户在实际终端上看到的是一样的,但是对于用户而言,它是不可见的。

每当被监控的程序改变终端屏幕的内容时,ttyexec 的虚拟终端也会同步更新自己的屏幕,然后它开始检查事件表,如果发现了匹配的事件,就执行为事件定义的事件动作。

事件匹配

在 ttyexec 的事件表的每个事件中, 事件匹配器 由一到多个 事件条件 组成, 事件条件 是真正要去和虚拟终端屏幕比对的单元, 事件匹配器 只有在所有事件条件都匹配的情况下才是匹配的。

每个 事件条件 的类型有两种,第一种是根据光标的位置,第二种是根据屏幕上的数据。

光标位置是指光标到达某个指定的坐标时,条件就得到了满足,这种类型的条件需要两个参数,坐标的行和列。

屏幕的内容是指屏幕某个区域的内容达到预期的值,这种类型的条件需要四个参数,行,起始列,长度,以及一个正则表达式。

因为一个 事件匹配器 可以包含多个条件,并且只有匹配器中的所有条件都得到满足时,匹配器才算匹配,所以可以定义出很精确的匹配,当然也可以定义很模糊的匹配。

事件表维护

因为事件需要根据不同的应用场合而进行独立的设置,所以必须有能力去管理 ttyexec 的事件表,这需要了解一些基本的计算机编程。

有两种途径来管理 ttyexec 的事件表,第一种是通过 ttyexec 的配置文件,叫做 ttyexec.lua,这个文件使用标准的 Lua 程序语言。这种方式称为静态事件管理。

第二种方式是使用 ttyutils 提供的编程接口,外部程序可以动态的维护 ttyexec 事件表,这种方式称为动态事件管理。动态事件管理很强很实用,因为这样我们就可以在事件触发之后的程序中再去动态的管理 ttyexec 的事件表,这可以为事件提供了上下文关系。

在一个复杂的环境中,通常利用静态管理来维护 ttyexec 的初始事件,而在适当的时候利用动态事件管理来动态的维护 ttyexec 的事件表。

RPC 服务

远程过程调用 (remote process call)RPC 服务是 ttyexec 为进程间通讯提供的接口,注意它和 SUN RPC 没有任何的关系,并且不能跨网络使用。

当事件触发时,事件动作程序被启用,事件动作程序是一个标准的应用程序,它可以做任何它喜欢的事情,但是有时候,它需要和 ttyexec 交互,例如它可能需要获取当前终端屏幕的内容, ttyexec 为这样的情况提供了准备,称为 RPC 服务。

Ttyexec 提供了下面的服务 :

  • snap: 获取当前终端屏幕的快照;
  • feed: 发送数据作为实终端的标准输入;
  • suspend/resume_stdio: 悬挂 / 恢复实终端标准输入;
  • suspend/resume_stdout: 悬挂 / 恢复实终端标准输出;
  • insert/remove_event: 添加 / 删除事件表中的事件;

下面用一个例子描述如何编写一个 C 程序来使用上面提供的 feed 服务,包括从源代码编写到编译,连接完整的步骤。

#include <ttyutils.h>

int
main (int argc, char *argv[])
{
TRpcTarget target;

if (!t_init ())
return 1;

target.rt_timeout = 3;
target.rt_type = RPC_TARGET_PTS;
target.rt_pts = "/dev/pts/3";

if (!t_rpc_call_set_target (&target))
{
t_println ("set rpc target failed.");
return 1;
}

if (!t_rpc_call_feed ("hello", 5))
{
g_warning (_("rpc call failed."));
return 1;
}

t_uninit ();
return 0;
}

将上面的代码保存到文件 example.c,然后到用下面的命令编译它 :

$ cc -o example example.c `pkg-config --cflags --libs ttyutils-1`

第 1 行包含了头文件 <ttyutils.h>,这是每个外挂程序应该做的。

第 6 行声明了一个 TRpcTarget 结构的变量,这个结构描述如下 :

typedef enum
{
RPC_TARGET_TTY,
RPC_TARGET_PTS,
RPC_TARGET_PID,
RPC_TARGET_PATH
} TRpcTargetType;

typedef struct _TRpcTarget TRpcTarget;
struct _TRpcTarget
{
TRpcTargetType rt_type;
guint32 rt_timeout;
union
{
gchar *t_tty;
gchar *t_pts;
pid_t t_pid;
gchar *t_path;
} rt_target;
};
#define rt_tty rt_target.t_tty
#define rt_pts rt_target.t_pts
#define rt_pid rt_target.t_pid
#define rt_path rt_target.t_path

第 8 行调用了 t_init() 函数,要使用 ttyexec 接口的程序应该首先调用这个函数 ( 在调用其它接口函数之前 )。

第 11 行到 13 行设置 RPC 的目标,这里我们选择的是使用伪终端名称 "/dev/pts/3"。

上面 TRcTargetType 的枚举定义了我们可以使用的连接方式,它们分别是 :

RPC_TARGET_TTY ttyexec 实例使用的终端名称

RPC_TARGET_PTS ttyexec 实例运行命令的伪终端名称

RPC_TARGET_PID ttyexec 的进程 ID

RPC_TARGET_PATH ttyexec 为 RPC 服务建立的 UNIX 套接字名称

结构 TRpcTarget 中的联合体 rt_target 中的每个成员分别对应于每种不同的连接方式。为了方便的访问到 rt_target 中的成员,还分别定义了一些简化的宏 (rt_tty 等等 )。

第 15 到 19 行调用 t_rpc_call_set_target() 函数,它用我们上面设置好的 target 结构体作为参数。

t_println() 是一个调试用的函数,当编译程序时定义了 DEBUG 或者 T_DEBUG 时,它的功能和 printf() 类似,当没有定义上面的两个宏时,它不生成任何代码。

第 21 到 25 行调用函数 t_rpc_call_feed (),这个函数访问 ttyexec 提供的 feed 服务,它的作用是发送一些数据到 ttyexec 作为标准输入。

g_warning() 是 glib 提供的一个函数,它的作用是输出一条警告消息。

第 27 行调用 t_uninit() 函数,它的作用是释放资源,应该在程序退出之前调用。





回页首


Ttyutils 内部原理描述

前面描述了如何使用 ttyutils 软件包中的程序来监控终端的会话,读者可能好奇它的内部是如何工作的,这一部分将描述这些内容。

实现 ttyexec

ttyexec 是一个监控程序,它通过建立一个伪终端来运行一个应用程序,从而达到监控那个应用程序的目的。所以,要理解 ttyexec 的实现,必须理解伪终端。

伪终端

伪终端这个名词暗示它是一个虚拟的终端,应用程序可以将其作为一个终端设别使用,但是它不是一个真实的终端,一个伪终端由两端构成,分别称为伪终端主设备 和从设备,任何写到伪终端主设备的输入都会作为从设备端的输入,反之亦然。事实上所有从设备端的输入都来自于主设备上的用户进程。这看起来就像一个流管 道,但从设备上的终端行规程使我们拥有普通管道之外的其他处理能力。

文件 /dev/ptmx 是一个字符设备,它用来建立伪终端主从设备。

截获进程输入输出

ttyexec 通过建立一个伪终端,然后调用 fork。子进程建立了一个新的对话,打开一个相应的伪终端从设备,将它复制成标准输入、标准输出和标准出错,然后调用 exec。伪终端从设备成为子进程的控制终端。

对于伪终端从设备之上的用户进程来说,其标准输入、标准输出和标准出错都能当作终端设备使用。用户进程能够调用所有输入 / 输出函数。

虚拟终端

当 ttyexec 从伪终端主设备接收到数据后,这些数据是原始的 Escape 序列,它还需要传递给内置的 Escape 解析器,最后在内存中构造一个和屏幕上相同的虚拟终端。

注意虚拟终端,伪终端和实际终端之间的区别,下面的图描述了它们之间的关系:


图 2 ttyexec 内部关系

当使用 ttyexec 执行其它命令时, ttyexec 实际上拥有了两个终端设备,一个是继承于 shell 的实终端 ( 也可能是伪终端,例如在终端仿真程序中运行 ttyexec),另外一个是 ttyexec 建立的伪终端,后者将被 ttyexec 执行的命令使用。

当在使用 ttyadmin 时,得到的输出中有一栏名为 TTY,还有一栏名为 PTS,分别指的就是上面的实终端和伪终端。

ttyexec 拥有两个终端设备,其中伪终端被用于执行的命令,因为伪终端的一端的输出将会是另一端的输入,也就是说,被 ttyexec 执行的命令的所有输出将是 ttyexec 的输入,所以, ttyexec 截获了被执行的命令的全部终端输出。

同样,因为用户从真实终端的数据要通过 ttyexec 转发到伪终端上执行的命令,所以 ttyexec 也截获了用户的所有输入,并且可以模拟用户的输入发送数据到伪终端,这可以用于自动填充数据这样的场合。

通过虚拟终端在内存中重构一个终端屏幕,可以实时的跟踪屏幕的变化,并且根据当前屏幕的特征来触发事件,完成特定的事情。

伪终端是双向通讯设备,所以 ttyexec 可以输入数据到伪终端来模拟设备的标准输入 ( 键盘输入 ),ttyexec 提供的 feed RPC 服务就利用了这个特征。

需要澄清的一点是,虽然 ttyexec 能够控制被执行命令在终端上的的输入和输出,但不能改变被执行命令的内部程序逻辑。

支持 ttylook

Ttyexec 通过内置了一个网络服务器来支持 ttylook,这个服务在 ttyexec 中称为 lookd,它利用 UNIX socket 等待和 ttylook 建立一个双向的通讯,将截获的数据发送给 ttylook 即可,这项服务不能跨网络使用。

因为是双向通讯,所以 ttylook 也可以发送数据给 ttyexec 来写入伪终端主设备作为被 ttyexec 执行的程序的标准输入。

支持 RPC 服务

ttyexec 通过内置的一个网络服务器来支持 RPC 服务,这个服务在 ttyexec 中称为 RPCD,它利用 UNIX socket 等待和应用程序建立一个双向的通讯,然后根据应用程序的请求,返回相应的响应,这项服务不能跨网络使用。

因为 RPC 请求和响应的格式是由 ttyexec 内部定义的,为了方便开发人员使用,Ttyutils 提供了一个库,对这些细节进行了封装,所以在应用程序中使用 RPC 服务是非常简单的事情。

支持事件触发

事件触发的根本在于前面提到的虚拟终端,在 ttyexec 中,维护了一个事件表,每当虚拟终端发生变化时,它将会去用当前虚拟终端屏幕的内容去逐项匹配事件表中的事件,如果能够匹配,那么将触发一个动作。

因为终端的变化非常的频繁,如果事件表中有大量的事件,那么速度会受到一定的影响,但是为了确保实时性,这样的匹配是需要的,具体事件表能够加载多少事件没有限制,这个由管理人员根据系统的处理能力而定。

实现 ttylook

Ttylook 是 ttyexec lookd 服务器的客户端,它实现了两项功能:

1.从 ttyexec 接收数据,然后写到 用户终端

2.从 用户终端 接收数据,然后发送到 ttyexec。

这里 用户终端 是指运行 ttylook 的终端。

接收 ttyexec 的数据

ttylook 在启动时,将通过 UNIX socket 和 ttyexec 建立连接。

ttyexec 接收了这个连接之后,它会将所有被监控程序的标准输出数据 ( 输出到终端屏幕上的数据 ) 传送给 ttylook,然后 ttylook 简单的将这些数据写到用户的终端屏幕。

注意 ttylook 不理睬在 socket 之间传送的数据内容,这些数据直接被写到用户终端屏幕,所以如果运行 ttyexec 和 ttylook 的终端类型不同,那么可能会出现屏幕的内容错乱。

发送数据给 ttyexec

ttylook 在启动时,会将用户终端的标准输入 ( 键盘 ) 至于关闭回显模式,这样,用户在终端上的输入在屏幕上是不可见的。

但是 ttylook 会得到这些输入数据,然后将这些数据传送给 ttyexec,ttyexec 会将这些数据作为用户的输入写到被监控的进程,这就好像运行 ttyexec 的用户输入了数据一样。

实现 ttyadmin

当 ttyexec 启动的时候,它会将它自身的信息注册到一个系统区域,称为黄页,这个黄页是用一片共享内存实现的,ttyexec 注册的信息包括它的进程 ID,终端和伪终端名称,lookd 服务和 rpcd 服务帮定的地址,等等,每个 ttyexec 在黄叶中占据一项。

当 ttyexec 退出的时候,它会将自身的注册信息从黄页中删除。

Ttyadmin 主要是管理这个黄页的程序。

查看 ttyexec 实例

在 ttyadmin 启动时,它建立一个全屏幕的窗口,然后查询黄页,得到当前系统中所有 ttyexec 实例的注册信息,并将这些数据缓存到自己的内部表中。

然后它格式化得到的信息,显示在主窗口中。

后续的所有操作 ( 例如排序 ) 都是基于这个内部表,但是允许用户去重读黄页 ( 当前的实现是按下空格键或者设定一个更新超时 )。

管理 ttyexec 实例

ttyadmin 提供了对 ttyexec 的管理能力,这些能力可以在运行 ttyadmin 时通过帮助获得,这里要说明的是,这些管理功能主要是基于黄页中的信息。

虽然 ttyadmin 可以查看和管理 ttyexec,但是它和 ttyexec 没有直接的关系。

ttyexec 也为 ttyadmin 提供了一些管理功能 ( 例如查询事件表的内容 ),这是通过 ttyexec 的 RPC 服务实现的,在这种情况下,ttyadmin 只能算是 ttyexec 的一个 RPC 客户端。

用VNC实现远程桌面共享(支持Windows, Linux, …)[转]

4:31:00 PM 0 Comments

VNC,全称为Virtual Network Computing,它是一个桌面共享系统。它的功能,类似于windows中的远程桌面功能。VNC使用了RFB(Remote FrameBuffer,远程帧缓冲)协议来实现远程控制另外一台计算机。它把键盘、鼠标动作发送到远程计算机,并把远程计算机的屏幕发回到本地。
VNC技术与平台无关,VNC Viewer可以和VNC Server在不同的操作系统上。VNC几乎支持所有的操作系统,也支持Java,甚至可以通过支持Java的浏览器来访问VNC Server。多个VNC客户端可以同时连接到一个VNC Server上。
VNC最初由AT&T开发的,它的源代码是开源的。

在CentOs 4.3上配置VNC服务很简单(这里假定你的计算机上已经安装了VNC软件)

首先需要配置VNC密码,密码在使用客户端连接服务器时使用。
注意:VNC密码保存在用户的主目录中,每个用户都可以设置自己的密码。因此,请使用你的用户名(尽量不要使用root)运行下列命令:

vncpasswd


然后输入密码。

接下来就可以启动VNC server了。在启动VNC server时,需要为你的server指定一个display参数。你可以把display理解为一个桌面,每个用户都可以有自己的桌面。VNC客户端 在连接时,可以指定连接到哪个桌面上。在系统中,display号不能重复,也就是说,如果有用户已经建立了名为“:1”的display,另外一个用户 就不能再使用“:1”了,他可以使用“:2”。
启动VNC server的命令是:

vncserver <display>


例如,

vncserver :1


最后,需要配置一下防火墙,允许VNC客户端连接VNC server。VNC server监听的端口从5900开始,display :1的监听5901,display :2监听5902,以此类推。CentOs的防火墙缺省是不允许连接这些端口的,所以需要使用下面的步骤打开防火墙(需要root权限):

vi /etc/sysconfig/iptables


找到下面的语句:

-A INPUT -j REJECT --reject-with icmp-host-prohibited


在此行之前,加上下面的内容:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 5900:5903 -j ACCEPT


这句话的含义是,允许其它机器访问本机的5900到5903端口,这样,display:1, display:2, display:3的用户就可以连接到本机。

然后使用root身份重新启动防火墙:

/sbin/service iptables restart

好了,现在就可以运行客户端软件,连接到VNC server上了。
VNC客户端软件很多,在linux下有vncviewer,KDE还提供了一个krdc(它的菜单项就是”Remote Desktop Connection”,远程桌面连接)。
在window也有不少vnc客户端,你可以到http://www.realvnc.com/去下载一个,安装就可以用了。

假设VNC server的IP地址是192.168.1.1,display是:1。在VNC viewer的server栏中输入:“192.168.1.1:1”,然后连接。OK,你可以看到自己的桌面了。以后不管你什么时候关闭自己的本地PC机都不怕了,只要server不关机,你只要连接到VNC server,你就可以看到你前一天关闭本地PC机时的桌面还保持着原样。

不过…这个桌面怎么这么丑?!
原来vncserver默认使用的窗口管理器是twm,这是一个很简陋的窗口管理器,你可以把你的桌面改成GNOME或KDE。
方法是,进入你自己的home目录,然后编辑这个文件:.vnc/xstartup,下面是这个文件的内容:

#!/bin/sh

# Uncomment the following two lines

for normal desktop:
#unset SESSION_MANAGER
#exec
/etc/X11/xinit/xinitrc

[

-x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[
-r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot
-solid grey
vncconfig
-iconic &
xterm
-geometry 80×24+10+10 -ls -title $VNCDESKTOP Desktop &
#twm
&
gnome
-session &


你可以把像上面这样把”twm &”这一行注释掉,然后在下面加入一行”gnome-session &”,或者是”startkde &”,分别启动GNOME桌面和KDE桌面。

如果server重启了,那你就需要重新运行一次vncserver命令来启动VNC server,这很麻烦。有没有更好的方法呢?

有!我们可以把VNC server启动成后台服务。执行如下步骤:

首先要允许VNC server在系统启动过程中被启动。这可以通过“系统设置–>服务器设置–>服务”菜单来配置,把vncserver一项选上就可以了。
如果使用命令行的话,以root身份运行以下两条命令:

cd /etc/rc5.d
mv K35vncserver S35vncserver


然后编辑/etc/sysconfig/vncservers,以下是文件内容:

# The VNCSERVERS variable is a list of display:user pairs.
#
# Uncomment the line below to start a VNC server on display :
1
# as my ’myusername’ (adjust this to your own). You will also
# need to set a VNC password
; run ’man vncpasswd’ to see how
# to do that.
#
# DO NOT RUN THIS SERVICE if your local area network is
# untrusted! For a secure way of using VNC
, see
# .

VNCSERVERS

=1:user1 2:user2 3:user3
VNCSERVERARGS
[1]=-geometry 1024×768
VNCSERVERARGS
[2]=-geometry 1024×768
VNCSERVERARGS
[3]=-geometry 800×600


解释一下这个文件:
VNCSERVERS这一行是配置在系统启动时启动几个VNC server,上面的例子里运行了三个VNC server,其中user1在display :1,user2在display :2,user3在display :3。
VNCSERVERARGS这三行,分别为VNC server 1, 2, 3配置启动参数,上面的例子里对user1和user2使用屏幕分辨率1024×768,对user3使用800×600。
其它支持的参数请使用“man vncserver”命令查询。

编辑好这个文件后,保存,然后以root身份运行:

/sbin/service vncserver start


这样user1, user2, user3的vncserver就启动了。
以后每次系统重启时,都会自动启动这三个用户的vncserver。

注意:上面三个用户必须已经使用vncpasswd命令设置过vnc密码,不然他的vncserver启动会失败!

C语言编译全过程

9:33:00 PM 0 Comments

C语言编译全过程


编译的概念:编译程序读取源程序(字符流),对之进行词法和语法的分析,将高级语言指令转换为功能等效的汇编代码,再由汇编程序转换为机器语言,并且按照操作系统对可执行文件格式的要求链接生成可执行程序。
编译的完整过程:C源程序-->预编译处理(.c)-->编译、优化程序(.s、.asm)-->汇编程序(.obj、.o、.a、.ko)-->链接程序(.exe、.elf、.axf等)


1. 编译预处理


读取c源程序,对其中的伪指令(以#开头的指令)和特殊符号进行处理
伪指令主要包括以下四个方面:
(1)宏定义指令,如#define Name TokenString,#undef等。
对于前一个伪指令,预编译所要做的是将程序中的所有Name用TokenString替换,但作为字符串常量的 Name则不被替换。对于后者,则将取消对某个宏的定义,使以后该串的出现不再被替换。
(2)条件编译指令,如#ifdef,#ifndef,#else,#elif,#endif等。
这些伪指令的引入使得程序员可以通过定义不同的宏来决定编译程序对哪些代码进行处理。预编译程序将根据有关的文件,将那些不必要的代码过滤掉
(3) 头文件包含指令,如#include "FileName"或者#include <FileName>等。
在头文件中一般用伪指令#define定义了大量的宏(最常见的是字符常量),同时包含有各种外部符号的声明。
采用头文件的目的主要是为了使某些定义可以供多个不同的C源程序使用。因为在需要用到这些定义的C源程序中,只需加上一条#include语句即可,而不必再在此文件中将这些定义重复一遍。预编译程序将把头文件中的定义统统都加入到它所产生的输出文件中,以供编译程序对之进行处理。
包含到c源程序中的头文件可以是系统提供的,这些头文件一般被放在/usr/include目录下。在程序中#include它们要使用尖括号(< >)。另外开发人员也可以定义自己的头文件,这些文件一般与c源程序放在同一目录下,此时在#include中要用双引号("")。
(4)特殊符号,预编译程序可以识别一些特殊的符号。
例如在源程序中出现的LINE标识将被解释为当前行号(十进制数),FILE则被解释为当前被编译的C源程序的名称。预编译程序对于在源程序中出现的这些串将用合适的值进行替换。
预编译程序所完成的基本上是对源程序的“替代”工作。经过此种替代,生成一个没有宏定义、没有条件编译指令、没有特殊符号的输出文件。这个文件的含义同没有经过预处理的源文件是相同的,但内容有所不同。下一步,此输出文件将作为编译程序的输出而被翻译成为机器指令。


2. 编译、优化阶段


经过预编译得到的输出文件中,只有常量;如数字、字符串、变量的定义,以及C语言的关键字,如main,if,else,for,while,{,}, +,-,*,\等等。
编译程序所要作得工作就是通过词法分析和语法分析,在确认所有的指令都符合语法规则之后,将其翻译成等价的中间代码表示或汇编代码。
优化处理是编译系统中一项比较艰深的技术。它涉及到的问题不仅同编译技术本身有关,而且同机器的硬件环境也有很大的关系。优化一部分是对中间代码的优化。这种优化不依赖于具体的计算机。另一种优化则主要针对目标代码的生成而进行的。
对于前一种优化,主要的工作是删除公共表达式、循环优化(代码外提、强度削弱、变换循环控制条件、已知量的合并等)、复写传播,以及无用赋值的删除,等等。
后 一种类型的优化同机器的硬件结构密切相关,最主要的是考虑是如何充分利用机器的各个硬件寄存器存放的有关变量的值,以减少对于内存的访问次数。另外,如何 根据机器硬件执行指令的特点(如流水线、RISC、CISC、VLIW等)而对指令进行一些调整使目标代码比较短,执行的效率比较高,也是一个重要的研究 课题。
经过优化得到的汇编代码必须经过汇编程序的汇编转换成相应的机器指令,方可能被机器执行。


3. 汇编过程


汇编过程实际上指把汇编语言代码翻译成目标机器指令的过程。对于被翻译系统处理的每一个C语言源程序,都将最终经过这一处理而得到相应的目标文件。目标文件中所存放的也就是与源程序等效的目标的机器语言代码。
目标文件由段组成。通常一个目标文件中至少有两个段:
代码段:该段中所包含的主要是程序的指令。该段一般是可读和可执行的,但一般却不可写。
数据段:主要存放程序中要用到的各种全局变量或静态的数据。一般数据段都是可读,可写,可执行的。
UNIX环境下主要有三种类型的目标文件:
(1)可重定位文件
其中包含有适合于其它目标文件链接来创建一个可执行的或者共享的目标文件的代码和数据。
(2)共享的目标文件
这种文件存放了适合于在两种上下文里链接的代码和数据。
第一种是链接程序可把它与其它可重定位文件及共享的目标文件一起处理来创建另一个 目标文件;
第二种是动态链接程序将它与另一个可执行文件及其它的共享目标文件结合到一起,创建一个进程映象。
(3)可执行文件
它包含了一个可以被操作系统创建一个进程来执行之的文件。
汇编程序生成的实际上是第一种类型的目标文件。对于后两种还需要其他的一些处理方能得到,这个就是链接程序的工作了。


4. 链接程序


由汇编程序生成的目标文件并不能立即就被执行,其中可能还有许多没有解决
的问题。
例如,某个源文件中的函数可能引用了另一个源文件中定义的某个符号(如变量或者函数调用等);在程序中可能调用了某个库文件中的函数,等等。所有的这些问题,都需要经链接程序的处理方能得以解决。
链接程序的主要工作就是将有关的目标文件彼此相连接,也即将在一个文件中引用的符号同该符号在另外一个文件中的定义连接起来,使得所有的这些目标文件成为一个能够诶操作系统装入执行的统一整体。
根据开发人员指定的同库函数的链接方式的不同,链接处理可分为两种:
(1)静态链接
在这种链接方式下,函数的代码将从其所在地静态链接库中被拷贝到最终的可执行程序中。这样该程序在被执行时这些代码将被装入到该进程的虚拟地址空间中。静态链接库实际上是一个目标文件的集合,其中的每个文件含有库中的一个或者一组相关函数的代码。
(2) 动态链接
在此种方式下,函数的代码被放到称作是动态链接库或共享对象的某个目标文件中。链接程序此时所作的只是在最终的可执行程序中记录下共享对象的名字以及其它 少量的登记信息。在此可执行文件被执行时,动态链接库的全部内容将被映射到运行时相应进程的虚地址空间。动态链接程序将根据可执行程序中记录的信息找到相 应的函数代码。
对于可执行文件中的函数调用,可分别采用动态链接或静态链接的方法。使用动态链接能够使最终的可执行文件比较短小,并且当共享对象被多个进程使用时能节约 一些内存,因为在内存中只需要保存一份此共享对象的代码。但并不是使用动态链接就一定比使用静态链接要优越。在某些情况下动态链接可能带来一些性能上损 害。


总结:
C语言编译的整个过程是非常复杂的,里面涉及到的编译器知识、硬件知识、工具链知识都是非常多的,深入了解整个编译过程对工程师理解应用程序的编写是有很大帮助的,希望大家可以多了解一些,在遇到问题时多思考、多实践。
一般情况下,我们只需要知道分成编译和连接两个阶段,编译阶段将源程序(*.c)转换成为目标代码(,一般是obj文件,至于具体过程就是上面说的那些阶段),连接阶段是把源程序转换成的目标代码(obj文件)与你程序里面调用的库函数对应的代码连接起来形成对应的可执行文件(exe文件)就可以了,其他的都需要在实践中多多体会才能有更深的理解。

Linux 系统下查找进程并终止命令详解

5:33:00 PM 0 Comments

使用linux操作系统,难免遇到一些软件"卡壳"的问题,这时就需要使用linux下强大的kill命令来结束相关进程。这在linux系统下是极其容易的事情,你只需要kill xxx即可,这里xxx代表与此软件运行相关的进程PID号。

首先,我们需要使用linux下另外一个命令ps查找与进程相关的PID号:ps aux | grep program_filter_word

1)ps a 显示现行终端机下的所有程序,包括其他用户的程序。

2)ps -A 显示所有程序。

3)ps c 列出程序时,显示每个程序真正的指令名称,而不包含路径,参数或常驻服务的标示。

4)ps -e 此参数的效果和指定"A"参数相同。

5)ps e 列出程序时,显示每个程序所使用的环境变量。

6)ps f 用ASCII字符显示树状结构,表达程序间的相互关系。

7)ps -H 显示树状结构,表示程序间的相互关系。

8)ps -N 显示所有的程序,除了执行ps指令终端机下的程序之外。

9)ps s 采用程序信号的格式显示程序状况。

10)ps S 列出程序时,包括已中断的子程序资料。

11)ps -t<终端机编号> 指定终端机编号,并列出属于该终端机的程序的状况。

12)ps u 以用户为主的格式来显示程序状况。

13)ps x 显示所有程序,不以终端机来区分。

最常用的方法是ps aux,然后再通过管道使用grep命令过滤查找特定的进程,然后再对特定的进程进行操作。

其次,使用kill命令结束进程:kill xxx

1)作用
kill命令用来中止一个进程。

2)格式
kill [ -s signal | -p ] [ -a ] pid ...
kill -l [ signal ]

3)参数
-s:指定发送的信号。
-p:模拟发送信号。
-l:指定信号的名称列表。
pid:要中止进程的ID号。
Signal:表示信号。

4)说明
进程是Linux系统中一个非常重要的概念。Linux是一个多任务的操作系统,系统上经常同时运行着多个进程。我们不关心这些进程究竟是如何分配的,或者是内核如何管理分配时间片的,所关心的是如何去控制这些进程,让它们能够很好地为用户服务。

Linux 操作系统包括三种不同类型的进程,每种进程都有自己的特点和属性。交互进程是由一个Shell启动的进程。交互进程既可以在前台运行,也可以在后台运行。 批处理进程和终端没有联系,是一个进程序列。监控进程(也称系统守护进程)是Linux系统启动时启动的进程,并在后台运行。例如,httpd 是著名的Apache服务器的监控进程。

kill命令的工作原理是,向Linux系统的内核发送一个系统操作信号和某个程序的进程标识 号,然后系统内核就可以对进程标识号指定的进程进行操作。比如在top命令中,我们看到系统运行许多进程,有时就需要使用kill中止某些进程来提高系统 资源。在讲解安装和登陆命令时,曾提到系统多个虚拟控制台的作用是当一个程序出错造成系统死锁时,可以切换到其它虚拟控制台工作关闭这个程序。此时使用的 命令就是kill,因为kill是大多数Shell内部命令可以直接调用的。

5)应用实例
(1)强行中止(经常使用杀掉)一个进程标识号为324的进程:
#kill -9 324

(2)解除Linux系统的死锁
在 Linux中有时会发生这样一种情况:一个程序崩溃,并且处于死锁的状态。此时一般不用重新启动计算机,只需要中止(或者说是关闭)这个有问题的程序即 可。当kill处于X-Window界面时,主要的程序(除了崩溃的程序之外)一般都已经正常启动了。此时打开一个终端,在那里中止有问题的程序。比如, 如果Mozilla浏览器程序出现了锁死的情况,可以使用kill命令来中止所有包含有Mozolla浏览器的程序。首先用ps命令查找该程序的 PID,然后使用kill命令停止这个程序:
#kill -SIGKILL XXX
其中,XXX是包含有Mozolla浏览器的程序的进程标识号。

(3)使用命令回收内存
我们知道内存对于系统是非常重要的,回收内存可以提高系统资源。kill命令可以及时地中止一些"越轨"的程序或很长时间没有相应的程序。例如,使用top命令发现一个无用 (Zombie) 的进程,此时可以使用下面命令:
#kill -9 XXX
其中,XXX是无用的进程标识号。

然后使用下面命令:
#free
此时会发现可用内存容量增加了。

(4)killall命令
Linux下还提供了一个killall命令,可以直接使用进程的名字而不是进程标识号,例如:
# killall -HUP inetd

linux网址精选 | linux web site

10:47:00 PM 0 Comments

国外
  http://lwn.net/
  http://www.tldp.org/
  https://rhn.redhat.com/
  http://www.justlinux.com/
  http://www.linuxtoday.com/
  http://www.linuxquestions.org/
  http://www.fokus.gmd.de/linux/
  http://www.linux-tutorial.info/
  http://public.www.planetmirror.com/
  http://www.freebsdforums.org/forums/
  http://www.netfilter.org/documentation/
  http://www-106.ibm.com/developerworks/linux/
  http://www.redhat.com/docs/ redhat官方文档,redhat用户必看
  http://www.redhat.com/apps/support/errata/ redhat安全性警告、软件更新和增强,建议每周至少查阅一次

国内
  http://www.fanqiang.com/
  http://www.linuxsir.com/
  http://www.chinaunix.net/
http://linux-fans.com/
  http://www.linuxfans.org/
  http://www.linuxeden.com/
  http://www.linuxforum.net/
  http://www.linuxaid.com.cn/
  http://freesoft.online.sh.cn/
  http://www-900.ibm.com/developerWor…nux/index.shtml

redhat linux下载地址
  ftp://ftp.redhat.com/pub/redhat/linux
  http://redhat.com/download/mirror.html

redhat 发行版全球官方镜像站
  http://freesoft.online.sh.cn/ 国内高速下载
  http://www.linuxeden.com/
  http://www.freshrpms.net/
  http://www.linux.cz/apt-rpm/ - Red Hat linux 7.x repositories (with all freshrpms included too!)
  http://apt-rpm.tuxfamily.org/ - Red Hat linux 6.2, 7.x and 8.0 repositories
  http://apt.nlc.no/apt/ - Red Hat linux 6.2, 7.x and Rawhide repositories
  http://ftp.uninett.no/pub/linux/apt/ - Red Hat linux 6.2, 7.x, 8.0 and Rawhide repositories
  http://redhat.usu.edu/ - Red Hat linux 7.2, 7.3 and 8.0 repositories
  ftp://mirror.pa.msu.edu/apt/ - Red Hat linux 7.2, 7.3 and 8.0 repositories
  http://apt-rpm.codefactory.se/ - Red Hat linux 7.2, 7.3 and 8.0 and gnomehide repositories http://apt.42h.de/ - Red Hat Linux 7.2, 7.3 and 8.0 repositories
  http://apt.toggletext.com.au/ - A few Red Hat linux 7.2 custom packages http://people.ecsc.co.uk/~matt/repository.html - Lots of custom Red Hat Linux 8.0 GNOME 2 and related packages
  http://ftp-stud.fht-esslingen.de/apt/ - Red Hat linux 7.x, 8.x and rawhide
  http://apt.unl.edu/ - Red Hat linux 7.3 and 8.0
  http://kde-redhat.sourceforge.net/ - KDE for Red Hat project

linux 常用软件搜索
  http://bingle.pku.edu.cn/ 北大天网ftp搜索,教育网和国内用户查找软件应首先访问,软件特别丰富
  http://www.linuxforum.net/ 有很多国外软件的官方镜像,应首先访问  http://rpmfind.net/
  http://freshmeat.net/
  http://sourceforge.net/
  注:很多软件主站是在sourceforge上的,形如http://phpmyadmin.sourceforge.net/的…笾苯酉略厝砑?/a> http://telia.dl.sourceforge.net/phpmyadmin/
  http://www.gnu.org/ GNU的大本营,gcc,bash之类的软件源码可以到这里得到 linux 文档和FAQs
  http://www.tldp.org/ 强烈推荐! The linux document project: linux HOWTO and guides
  http://www.linux.org.tw/CLDP/ 强烈推荐! TLDP中文版,繁体
  http://www.linuxgazette.com/ linux在线杂志
  http://linux.tcpip.com.cn/download/ linux中文版文档和软件下载
  http://cosoft.org.cn/html/documents/ 很多中文版手册
  http://www.google.com/ 强烈推荐!本站的讨论内容也可以通过google搜索得到,遇到疑难问题到google搜索会得到比绝大多数论坛更快的回答

linux 桌面主站一览表
  GNOME: http://www.gnome.org/
  KDE: http://www.kde.org/
  XFce: http://www.xfce.org/
  Window Maker: http://www.windowmaker.org/
  BlackBox: http://sourceforge.net/projects/blackboxwm
  XPde: http://www.xpde.com/
  ROX: http://sourceforge.net/projects/rox
  5dwm: http://5dwm.org/
  foXdesktop: http://sourceforge.net/projects/foxdesktop
  EDE: http://sourceforge.net/projects/ede
  UDE: http://sourceforge.net/projects/udeproject

其它OS:
  Mandrake linux http://www.mandrakelinux.com/
  debian linux http://www.debian.org/
  slackware linux http://www.slackware.com/
  suse linux http://www.suse.com/
  FreeBSD http://www.freebsd.org/
  netbsd http://www.netbsd.org/
  openbsd http://www.openbsd.org/
  Solaris http://www.sun.com/solaris 硬件和安装专业站点
  linux Kernel内核: http://www.kernel.org/
  USB安装问题: http://www.linux-usb.org/
  笔记本计算机安装: http://www.linux-laptop.net/
  打印机驱动 http://www.linuxprinting.org/

主要服务器软件主站
1. WWW server:
  Apache http://www.apache.org/ Apache
  SSL模块Mod_ssl http://www.modssl.org/
  aol server http://www.aolserver.com/

2. Servlets/JSP引擎:
  Tomcat: http://jakarta.apache.org/
  Resin: http://www.caucho.com/
  开源应用服务器AS–Jboss: http://www.jboss.org/

3. 服务器语言:
  PHP http://www.php.net/
  Zend http://www.zend.com/
  Java http://www.javasoft.com/
  Python http://www.python.org/
  Zope http://www.zope.org/
  Perl http://www.perl.org/
  Ruby http://www.ruby-lang.org/en

4. 数据库:
  MySQL http://www.mysql.com/
  PostgreSQL http://www.postgresql.org/
  Oracle http://www.oracle.com/
  sap db http://www.sapdb.org/
  PHPMyAdmin — http://www.phpmyadmin.org/
  PHPPgAdmin: http://sourceforge.net/projects/phppgadmin

5. FTP服务器
  wu-ftpd http://www.wu-ftpd.org/
  Proftpd http://www.proftpd.org/
  Pure-ftpd http://www.pureftpd.org/
  ncftpd http://www.ncftpd.com/
  vsftpd http://vsftpd.beasts.org/

6. SMTP服务器
  Sendmail http://www.sendmail.org/
  qmail http://www.qmail.org/
  Postfix http://www.postfix.org/
  Exim http://www.exim.org/
  POP3–qpopper http://www.qpopper.org/

7. IMAP服务器
  Cyrus-IMAPD http://asg.web.cmu.edu/cyrus/imapd
  UW IMAP http://www.washington.edu/imap
  courierimap http://www.inter7.com/courierimap

8. 基本安全工具
  firewall Iptables: http://www.iptables.org/
  shorewall: http://www.shorewall.net/
  inetd Xinetd: http://www.xinetd.org/
  Openssl: http://www.openssl.org/
  OpenSSH: http://www.openssh.org/
  nmap: http://http://www.insecure.org/nmap
  Tripwire: http://www.tripwire.org/
  snort: http://www.snort.org/
  nessus: http://www.nessus.org/
  GnuPG: http://www.gnupg.org/
  chkrootkit: http://www.chkrootkit.org/
  安全顾问: http://www.cert.org/

9. 其它服务器软件
  CVS–CVS http://www.cvshome.org/
  DNS域名解析BIND http://www.isc.org/products/BIND/
  DHCP–DHCP http://www.isc.org/products/DHCP/
  INN新闻组INN: http://www.isc.org/products/INN/
  Proxy代理缓存: Squid http://www.squid-cache.org/
  Socks代理:http://www.socks.nec.com/
  Samba Server: http://www.samba.org/
  Print CUPS: http://www.cups.org/
  LDAP OpenLDAP: http://www.openldap.org/
  流量分析 MRTG http://www.mrtg.org/
  日志分析 webalizer http://www.mrunix.net/webalizer/
  Ipsec/VPN http://www.freeswan.org/
  路由 Zebra http://www.zebra.org/
  集群 LVS http://www.linuxvirtualserver.org/
  MPICH http://www-unix.mcs.anl.gov/mpi/mpich/
  PVM:http://www.netlib.org/pvm3/
  Rsync: http://rsync.samba.org/
  linuxconf: http://www.solucorp.qc.ca/linuxconf/
  Webmin: http://www.webmin.com/

通过udev自动挂载U盘的方法

10:30:00 PM 0 Comments

目前一些主流桌面系统(如Gnome,KDE,Xfce)的较新版本都支持自动挂载(mount)U盘 了. 一个流传很广的说法是 HAL(硬件抽象层) 起了自动挂载的作用, 其实这是误解. 对于2.6内核而言, udev 才是直接从内核接收设备连接或断开信息的主体.

udev 从内核得到信息后,根据一些简单规则(注意,是简单规则), 在 /dev 目录下创建相应的设备节点, 并进行某些相关操作. HAL 所做的事情是在 udev 的规则中加上一条(或几条), 让 udev 把收到的信息也传递给 HAL. 接下来, HAL 用更为复杂的规则来匹配和描述当前连接着的硬件. 举一个简单的例子, udev 知道的是U盘已经连接了并且有一个分区; 而 HAL 能更进一步知道这个分区的卷标名及其它一些信息.

上面这些都还不能自动挂载U盘. Gnome 等桌面系统会启动一个守护进程(daemon), 通过 D-Bus 从 HAL 那里得到硬件信息, 如果发现有U盘连接了就由它们来挂载它(实际是调用 pmount).

问题是, 如果你不想用Gnome,KDE,Xfce这些桌面系统, 那么由它们提供的U盘自动挂载功能也就失效了,有解决办法么?

解决的办法之一, 便是让 udev 来干这件事情!

udev 的主要功能是实时地在 /dev 目录下创建和删除设备节点, 但它也能在创建节点的同时, 执行一个额外地程序. 具体的原理这里就不详说了, 有时间请仔细阅读 Writing udev rules 这篇文章. 写规则时特别注意 KERNEL, SUBSYSTEM 等这些关键字单数和复数(最后有没有'S')的区别. 复数(比如 KERNELS)表示你想用父设备的属性来匹配, 单数(比如 KERNEL)是要匹配设备本身的属性.

在 /etc/udev/rules.d 目录下创建文件 10_usbkey.rules, 其内容如下

KERNEL=="sda1″, SUBSYSTEM=="block", RUN+="/root/usbmount.sh"

然后, 在 /root 目录中创建文件 usbmount.sh, 其内容为

#!/bin/bashLOG=/var/log/usb-hotplug.log

lap=$(date –rfc-3339=ns)
echo "$lap: $DEVPATH requesting $ACTION" >> $LOG

if [ $ACTION == "add" ]
then
    mount -t vfat -o umask=000,noatime,async,codepage=936,iocharset=gb2312 \
        /dev/sda1 /media/usbkey
elif [ $ACTION == "remove" ]
then
    umount -l /media/usbkey
fi

并把该文件属性设置为可执行, chmod a+x usbmount.sh
注意, 如果你的 linux 上 locale 是 zh_CN.utf-8, 需要把上面的 iocharset=gb2312 改成 iocharset=utf8

最后创建目录, mkdir /media/usbkey

这是一个非常简单但可用的例子. U盘插上后自动 mount 到 /media/usbkey , 拔出后自动 umount. 你可以查看 /var/log/usb-hotplug.log , 里面会有些简单的调用记录.

卷标的操作 e2label

10:01:00 PM 0 Comments


设置sda5 卷标名称 为 test
ext
e2label /dev/hda5 test

xfs
xfs_admin -L test /dev/hda5

reiserfs
reiserfstune -l test /dev/sda5

查看卷标名称
mount -l

用卷标来挂载 盘符
mount -L test /mnt/hd

fvwm怎么启动之类的问题解说。。。

9:50:00 PM 0 Comments

还是有看到问 fvwm icewm 等wm怎么启动之类的问题。。。。夜深了我也随便谈谈我的方法
我都是直接运行xinit来启动Xwindow, 有些人用startx启动,其实它也是调用xinit这个命令的
据我运行看来, xinit应该就是 启动X然后再调用 xinitrc(也可以是 ~/.xinitrc)这个配置文件下的命令了

所以启动 wm很简单
编写 .xinitrc
--------------
exec fvwm
---------------
运行 xinit 即可

以下是我的 .xinitrc
--------------------------------------
export LANG=zh_CN.UTF-8
#我喜欢字符下 用英文环境 x下用中文环境 所以在这里我设置中文环境
export XMODIFIERS=@im=fcitx
fcitx
#设置了 fcitx启动 输入法也是在这里启动的
#要说一下 到wm启动前为止 软件不能自动后台运行的要加& 不然会卡住哦

clipboard-daemon &
numlockx
#exec mwm
#exec fvwm
exec gnome-session
#exec openbox-session
-----------------------------------------
运行 xinit 就可以了

还是用xinit明了 呵呵

gnome挂载U盘

9:50:00 PM 0 Comments


gconf-editor

中文显示
system --> storage --> default_options --> vfat --> mount_options

右键单击-编辑键-添加,加上utf8,即可


取消自动挂载U盘

/apps/nautilus/preferences/media_automount




Exploring Linux kernel

11:08:00 PM 0 Comments

Exploring Linux kernel

by vivek

Here are some interesting facts about running Linux kernel. Following information is quite useful if you are planning to compile your own custom kernel :)

But where is my kernel stored?
Your compiled kernel is always installed in /boot directory:

Here is listing of all installed kernel in my system (filename -> description)
$ ls -l /boot/

  • config-2.6.12-1-386 --> Kernel configuration file generated by make menuconfig/make xconfig/make gconfig
  • System.map-2.6.12-1-386 --> This file has a map of positions of symbols in the kernel. Device driver such as USB pen uses hot plug, which depend upon symbols generated by depmod utility
  • vmlinuz-2.6.12-1-386 -- > Actual Kernel file
  • initrd.img-2.6.12-1-386 --> Contains device drivers which are required to boot and load rest of operating system from disk. Usually SCSI and IDE drivers are stored in this file
  • grub --> It is a directory, which stores grub Boot loader configuration file
  • config --> Soft link to current kernel configuration file
  • vmlinuz -> Soft link to current running kernel file
  • System.map --> Soft link to current running kernel system map file

But what is 2.6.12 ... yup you are right it is kernel version :D

How do I find out version of running Linux kernel?
Use any one of the following command:
uname -r
OR
cat /proc/version

How do I find out where running kernel modules (device drivers) are stored?
Use any one of the following command:
ls /lib/modules/$(uname -r)
ls -d /lib/modules/$(uname -r)

How do I load kernel modules at boot time?
/etc/modules file should contain the names of kernel modules that are
to be loaded at boot time, one per line.
$ cat /etc/modules

How to: Compile Linux kernel modules

10:55:00 PM 0 Comments

This is one the essential and important task. Many time we upgrade our kernel and some precompiled drivers won't work with Linux. Especially if you have weird hardware; then vendor may send you driver code aka C files to compile. Or even you can write your own Linux kernel driver. Compiling kernel driver is easy. Kernel 2.6.xx makes it even much more easier. Following steps are required to compile driver as module:

1) You need running kernel source code; if you don't have a source code download it from kernel.org. Untar kernel source code (tar ball) in /usr/src using tar command:
$ tar -zxvf kernel* -C /usr/src

To be frank kernel headers are more than sufficient to compile kernel modules / drivers. See how to install kernel headers under Debian / Ubuntu Linux or RHEL / CentOS / Fedora Linux.

2) Next go to your kernel module source code directory and simply create the Makefile file as follows (assuming your kernel module name is foo):
$ vi Makefile

3) Add following text to it:

obj-m = foo.o
KVERSION = $(shell uname -r)
all:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean

4) Compile module using make command (module build can be done by any user) :
$ make
It will finally creates the foo.ko module in current directory. You can see all actual compile command stored in .foo* files in same directory.

5) Once module compiled successfully, load it using insmod or modprobe command. You need to be root user or privileged user to run insmod:
# insmod foo.ko

Example: hello.c module

1) hello.c C source code. Copy following code and save to hello.c
$ mkdir demo; cd demo
$ vi hello.c

2)Add following c source code to it:

#include <linux/module.h>       /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
#include <linux/init.h> /* Needed for the macros */

static int __init hello_start(void)
{
printk(KERN_INFO "Loading hello module...\n");
printk(KERN_INFO "Hello world\n");
return 0;
}

static void __exit hello_end(void)
{
printk(KERN_INFO "Goodbye Mr.\n");
}

module_init(hello_start);
module_exit(hello_end);

This is an example modified from original source for demonstration purpose.

3) Save the file. Create new Makefile as follows:
$ vi Makefile
Append following make commands:

obj-m = hello.o
KVERSION = $(shell uname -r)
all:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean

4) Save and close the file.

5) Compile hello.c module:
$ make

6) Become a root user (use su or sudo) and load the module:
$ su -
# insmod hello.ko

Note you can see message on screen if you are logged in as root under run level 3.

7) Verify that module loaded:
# lsmod | less

8) See message in /var/log/message file:
# tail -f /var/log/message

9) Unload the module:
# rmmod hello

10) Load module when Linux system comes up. File /etc/modules use to load kernel boot time. This file should contain the names of kernel modules that are to be loaded at boot time, one per line. First copy your module to /lib/modules/$(uname -r)/kernel/drivers. Following are suggested steps:

(a) Create directory for hello module:
# mkdir -p /lib/modules/$(uname -r)/kernel/drivers/hello
(b) Copy module:
# cp hello.ko /lib/modules/$(uname -r)/kernel/drivers/hello/
(c) Edit /etc/modules file under Debian Linux:
# vi /etc/modules
(d) Add following line to it:
hello
(e) Reboot to see changes. Use lsmod or dmesg command to verify module loaded or not.
# cat /proc/modules
OR
# lsmod | less

How to: Compile Linux kernel 2.6

10:52:00 PM 0 Comments

Compiling custom kernel has its own advantages and disadvantages. However, new Linux user / admin find it difficult to compile Linux kernel. Compiling kernel needs to understand few things and then just type couple of commands. This step by step howto covers compiling Linux kernel version 2.6.xx under Debian GNU Linux. However, instructions remains the same for any other distribution except for apt-get command.

Step # 1 Get Latest Linux kernel code

Visit http://kernel.org/ and download the latest source code. File name would be linux-x.y.z.tar.bz2, where x.y.z is actual version number. For example file inux-2.6.25.tar.bz2 represents 2.6.25 kernel version. Use wget command to download kernel source code:
$ cd /tmp
$ wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-x.y.z.tar.bz2

Note: Replace x.y.z with actual version number.

Step # 2 Extract tar (.tar.bz3) file

Type the following command:
# tar -xjvf linux-2.6.25.tar.bz2 -C /usr/src
# cd /usr/src

Step # 3 Configure kernel

Before you configure kernel make sure you have development tools (gcc compilers and related tools) are installed on your system. If gcc compiler and tools are not installed then use apt-get command under Debian Linux to install development tools.
# apt-get install gcc

Now you can start kernel configuration by typing any one of the command:

  • $ make menuconfig - Text based color menus, radiolists & dialogs. This option also useful on remote server if you wanna compile kernel remotely.
  • $ make xconfig - X windows (Qt) based configuration tool, works best under KDE desktop
  • $ make gconfig - X windows (Gtk) based configuration tool, works best under Gnome Dekstop.

For example make menuconfig command launches following screen:
$ make menuconfig

You have to select different options as per your need. Each configuration option has HELP button associated with it so select help button to get help.

Step # 4 Compile kernel

Start compiling to create a compressed kernel image, enter:
$ make
Start compiling to kernel modules:
$ make modules

Install kernel modules (become a root user, use su command):
$ su -
# make modules_install

Step # 5 Install kernel

So far we have compiled kernel and installed kernel modules. It is time to install kernel itself.
# make install

It will install three files into /boot directory as well as modification to your kernel grub configuration file:

  • System.map-2.6.25
  • config-2.6.25
  • vmlinuz-2.6.25

Step # 6: Create an initrd image

Type the following command at a shell prompt:
# cd /boot
# mkinitrd -o initrd.img-2.6.25 2.6.25

initrd images contains device driver which needed to load rest of the operating system later on. Not all computer requires initrd, but it is safe to create one.

Step # 7 Modify Grub configuration file - /boot/grub/menu.lst

Open file using vi:
# vi /boot/grub/menu.lst

title           Debian GNU/Linux, kernel 2.6.25 Default
root (hd0,0)
kernel /boot/vmlinuz root=/dev/hdb1 ro
initrd /boot/initrd.img-2.6.25
savedefault
boot

Remember to setup correct root=/dev/hdXX device. Save and close the file. If you think editing and writing all lines by hand is too much for you, try out update-grub command to update the lines for each kernel in /boot/grub/menu.lst file. Just type the command:
# update-grub
Neat. Huh?

Step # 8 : Reboot computer and boot into your new kernel

Just issue reboot command:
# reboot

代理 proxy

7:54:00 PM 0 Comments

http://www.minidaili.com/

linux下挂载U盘,硬盘,自动挂载

4:46:00 PM 0 Comments

1. Linux挂载U盘:
插入u盘到计算机,如果目前只插入了一个u盘而且你的硬盘不是scsi的硬盘接口的话,那它的硬件名称为:sda1。在mnt目录下先建立一个usb的目录:
(如:[root@localhost root]# mkdir /mnt/usb)

挂载U盘:mount -t vfat /dev/sda1 /mnt/usb
卸载U盘:umount /mnt/usb
删除usb目录:rm -rf /mnt/usb

2. Linux挂载硬盘:

挂载FAT32文件系统最简单的用法
mount /dev/hda6 /mnt/wine

/dev/hda6是Windows的E盘,/mnt/wine是目录加挂点。Linux会识别到/dev/hda6分区的文件系统类型是什么,然后加挂的。当然也可以指定分区的文件系统类型,命令如下:
mount -t vfat /dev/hda6 /mnt/wine

在实际中操作中,直接加挂一个windows的分区,中文的文件名和目录名会出现乱码,为了避免这种情况可以指定字符集,命令如下:
mount /dev/hda6 /mnt/d -o codepage=936,iocharset=cp936
mount -t vfat /dev/hda6 /mnt/d -o codepage=936,iocharset=cp936
mount -t vfat -o iocharset=cp936,codepage=936 /dev/hda6 /mnt/wine

注意:cp936是指简体中文,cp950是指繁体中文。

卸载所挂的硬盘 umount /mnt/wine
删除所挂的硬盘 rm -rf /mnt/wine

挂载NTFS文件系统
在目前多数的Linux版本上,需要重编译Linux核心才能,加挂NTFS分区(编译方法请参阅其它文章)。核心支持NTFS后,可以用以下命令加挂:
mount -t ntfs /dev/hda2 /mnt/c

同样对于中文的文件名和目录名会出现乱码的问题可以指定字符集,不过和加挂vfat分区不同,实际中用以下命令是可行的:
mount -t ntfs -o iocharset=cp936 /dev/hda2 /mnt/c -r
mount -t ntfs -o iocharset=cp936,rw /dev/hda2 /mnt/c

注意:cp936是指简体中文,cp950是指繁体中文。
卸载删除同上。

3. Linux自动挂载硬盘

打开/etc找到里面的fstab文件进行编辑,如果你是以管理员身份登入的话,可以直接右键->打开方式->gedit,可以直接在后面追加行:
/dev/hda6 /mnt/wine vfat codepage=936,iocharset=cp936,defaults,umask=0 0 0
/dev/hda5 /mnt/wind vfat codepage=936,iocharset=cp936 0 0
<umask=0表示普通用户也有也可以读写>

4. Linux挂载光驱:
命令: mount -t iso9660 /dev/hdc /mnt/cdrom

Language and Country-Specific Settings : suse

5:04:00 PM 0 Comments

Language and Country-Specific Settings

The system is, to a very large extent, internationalized and can be modified for local needs in a flexible manner. In other words, internationalization (I18N) allows specific localizations (L10N). The abbreviations I18N and L10N are derived from the first and last letters of the words and, in between, the number of letters omitted.

Settings are made with LC_ variables defined in the file /etc/sysconfig/language. This refers not only to native language support, but also to the categories Messages (Language), Character Set, Sort Order, Time and Date, Numbers, and Money. Each of these categories can be defined directly with its own variable or indirectly with a master variable in the file language (see the locale man page).

RC_LC_MESSAGES, RC_LC_CTYPE, RC_LC_COLLATE, RC_LC_TIME, RC_LC_NUMERIC, RC_LC_MONETARY

These variables are passed to the shell without the RC_ prefix and represent the listed categories. The shell profiles concerned are listed below. The current setting can be shown with the command locale.

RC_LC_ALL

This variable, if set, overwrites the values of the variables already mentioned.

RC_LANG

If none of the previous variables are set, this is the fallback. By default, only RC_LANG is set. This makes it easier for users to enter their own values.

ROOT_USES_LANG

A yes or no variable. If it is set to no, root always works in the POSIX environment.

The variables can be set with the YaST sysconfig editor (see Section 14.3.1, Changing the System Configuration Using the YaST sysconfig Editor). The value of such a variable contains the language code, country code, encoding, and modifier. The individual components are connected by special characters:

  LANG=[[_].[@]]

16.4.1 Some Examples

You should always set the language and country codes together. Language settings follow the standard ISO 639 available at http://www.evertype.com/standards/iso639/iso639-en.html and http://www.loc.gov/standards/iso639-2/. Country codes are listed in ISO 3166 available at http://www.din.de/gremien/nas/nabd/iso3166ma/codlstp1/en_listp1.html.

It only makes sense to set values for which usable description files can be found in /usr/lib/locale. Additional description files can be created from the files in /usr/share/i18n using the command localedef. The description files are part of the glibc-i18ndata package. A description file for en_US.UTF-8 (for English and United States) can be created with:

localedef -i en_US -f UTF-8 en_US.UTF-8
LANG=en_US.UTF-8

This is the default setting if American English is selected during installation. If you selected another language, that language is enabled but still with UTF-8 as the character encoding.

LANG=en_US.ISO-8859-1

This sets the language to English, country to United States, and the character set to ISO-8859-1. This character set does not support the Euro sign, but it can be useful sometimes for programs that have not been updated to support UTF-8. The string defining the charset (ISO-8859-1 in this case) is then evaluated by programs like Emacs.

LANG=en_IE@euro

The above example explicitly includes the Euro sign in a language setting. Strictly speaking, this setting is obsolete now, because UTF-8 also covers the Euro symbol. It is only useful if an application does not support UTF-8, but ISO-8859-15.

SuSEconfig reads the variables in /etc/sysconfig/language and writes the necessary changes to /etc/SuSEconfig/profile and /etc/SuSEconfig/csh.cshrc. /etc/SuSEconfig/profile is read or sourced by /etc/profile. /etc/SuSEconfig/csh.cshrc is sourced by /etc/csh.cshrc. This makes the settings available systemwide.

Users can override the system defaults by editing their ~/.bashrc accordingly. For instance, if you do not want to use the systemwide en_US for program messages, include LC_MESSAGES=es_ES so messages are displayed in Spanish instead.

16.4.2 Locale Settings in ~/.i18n

If you are not satisfied with locale system defaults, change the settings in ~/.i18n according to the Bash scripting syntax. Entries in ~/.i18n override system defaults from /etc/sysconfig/language. Use the same variable names but without the RC_ namespace prefixes, for example, use LANG instead of RC_LANG:

LANG=cs_CZ.UTF-8
LC_COLLATE=C

16.4.3 Settings for Language Support

Files in the category Messages are, as a rule, only stored in the corresponding language directory (like en) to have a fallback. If you set LANG to en_US and the message file in /usr/share/locale/en_US/LC_MESSAGES does not exist, it falls back to /usr/share/locale/en/LC_MESSAGES.

A fallback chain can also be defined, for example, for Breton to French or for Galician to Spanish to Portuguese:

LANGUAGE="br_FR:fr_FR"

LANGUAGE="gl_ES:es_ES:pt_PT"

If desired, use the Norwegian variants Nynorsk and Bokmål instead (with additional fallback to no):

LANG="nn_NO"

LANGUAGE="nn_NO:nb_NO:no"

or

LANG="nb_NO"

LANGUAGE="nb_NO:nn_NO:no"

Note that in Norwegian, LC_TIME is also treated differently.

One problem that can arise is a separator used to delimit groups of digits not being recognized properly. This occurs if LANG is set to only a two-letter language code like de, but the definition file glibc uses is located in /usr/share/lib/de_DE/LC_NUMERIC. Thus LC_NUMERIC must be set to de_DE to make the separator definition visible to the system.

16.4.4 For More Information

  • The GNU C Library Reference Manual, Chapter Locales and Internationalization. It is included in glibc-info.

  • Markus Kuhn, UTF-8 and Unicode FAQ for Unix/Linux, currently at http://www.cl.cam.ac.uk/~mgk25/unicode.html.

  • Unicode-Howto, by Bruno Haible: /usr/share/doc/howto/en/html/Unicode-HOWTO.html.

The Graphical SUSE Screen

4:59:00 PM 0 Comments

The Graphical SUSE Screen

The graphical SUSE screen is displayed on the first console if the option vga=value is used as a kernel parameter. If you install using YaST, this option is automatically activated in accordance with the selected resolution and the graphics card. There are three ways to disable the SUSE screen, if desired:

Disabling the SUSE Screen When Necessary

Enter the command echo 0 >/proc/splash on the command line to disable the graphical screen. To activate it again, enter echo 1 >/proc/splash.

Disabling the SUSE screen by default.

Add the kernel parameter splash=0 to your boot loader configuration. Section 15.0, The Boot Loader GRUB provides more information about this. However, if you prefer the text mode, which was the default in earlier versions, set vga=normal.

Completely Disabling the SUSE Screen

Compile a new kernel and disable the option Use splash screen instead of boot logo in framebuffer support.

HINT: Disabling framebuffer support in the kernel automatically disables the splash screen as well. SUSE cannot provide any support for your system if you run it with a custom kernel.

Fedora 10 静态IP设置

4:54:00 PM 0 Comments

在 安装完毕后,尝试设置静态IP地址,发现在network下面修改完毕之后,其netmask与gateway始终相同,导致网络链接不上(右上角到链接 符号显示disconnected)。然后上网搜索了一下,发现这个现象在F9就已经存在,一直还没有修复。于是尝试几种解决方案,发现这个比较简单可 行,特此如下显示。
step 1:
# su root //只有root有权限
# password:

step 2:
# cd cd /etc/sysconfig/network-scripts/
# vi ifcfg-eth0

修改配置文件如下:
# Marvell Technology Group Ltd. 88E8001 Gigabit Ethernet Controller
DEVICE=eth0
HWADDR=00:16:e6:db:c2:96
ONBOOT=yes
BOOTPROTO=static //这个应该是“static”,而不是“dhcp”或“none”;
USERCTL=yes
PEERDNS=yes
IPV6INIT=no
NM_CONTROLLED=yes//这个应该是“yes”,如不修改,链接仍是disconnected
TYPE=Ethernet
NETMASK=***.***.***.***
IPADDR=***.***.***.***
DNS1=***.***.***.***
DNS2=***.***.***.***
GATEWAY=***.***.***.***
step 3:
# service network restart
step 4:
上网,呵呵




key: fedora firefox 上网

The Linux Boot Process

3:03:00 PM 0 Comments

The Linux Boot Process

The Linux boot process consists of several stages each represented by a different component. The following list briefly summarizes the boot process and features all the major components involved.

  1. BIOS After the computer has been turned on, the BIOS initializes the screen and keyboard and tests the main memory. Up to this stage, the machine does not access any mass storage media. Subsequently, the information about the current date, time, and the most important peripherals are loaded from the CMOS values. When the first hard disk and its geometry are recognized, the system control passes from the BIOS to the boot loader.

  2. Boot Loader The first physical 512-byte data sector of the first hard disk is loaded into the main memory and the boot loader that resides at the beginning of this sector takes over. The commands executed by the boot loader determine the remaining part of the boot process. Therefore, the first 512 bytes on the first hard disk are referred to as the Master Boot Record (MBR). The boot loader then passes control to the actual operating system, in this case, the Linux kernel. More information about GRUB, the Linux boot loader, can be found in Section 15.0, The Boot Loader GRUB.

  3. Kernel and initramfs To pass system control, the boot loader loads both the kernel and an initial RAM–based file system (initramfs) into memory. The contents of the initramfs can be used by the kernel directly. initramfs contains a small executable called init that handles the mounting of the real root file system. If special hardware drivers are needed before the mass storage can be accessed, they must be in initramfs. For more information about initramfs, refer to Section 14.1.1, initramfs.

  4. init on initramfs This program performs all actions needed to mount the proper root file system, like providing kernel functionality for the needed file system and device drivers for mass storage controllers with udev. After the root file system has been found, it is checked for errors and mounted. If this has been successful, the initramfs is cleaned and the init program on the root file system is executed. For more information about init, refer to Section 14.1.2, init on initramfs. Find more information about udev in Section 17.0, Dynamic Kernel Device Management with udev.

  5. init init handles the actual booting of the system through several different levels providing different functionality. init is described in Section 14.2, The init Process.

14.1.1 initramfs

initramfs is a small cpio archive that the kernel can load to a RAM disk. It provides a minimal Linux environment that enables the execution of programs before the actual root file system is mounted. This minimal Linux environment is loaded into memory by BIOS routines and does not have specific hardware requirements other than sufficient memory. initramfs must always provide an executable named init that should execute the actual init program on the root file system for the boot process to proceed.

Before the root file system can be mounted and the operating system can be started, the kernel needs the corresponding drivers to access the device on which the root file system is located. These drivers may include special drivers for certain kinds of hard drives or even network drivers to access a network file system. The needed modules for the root file system may be loaded by init on initramfs. After the modules are loaded, udev provides the initramfs with the needed devices. Later in the boot process, after changing the root file system, it is necessary to regenerate the devices. This is done by boot.udev with the command udevtrigger.

If you need to change hardware (e.g. hard disks) in an installed system and this hardware requires different drivers to be present in the kernel at boot time, you must update initramfs. This is done in the same way as with its predecessor, initrd—by calling mkinitrd. Calling mkinitrd without any argument creates an initramfs. Calling mkinitrd -R creates an initrd. In openSUSE®, the modules to load are specified by the variable INITRD_MODULES in /etc/sysconfig/kernel. After installation, this variable is automatically set to the correct value. The modules are loaded in exactly the order in which they appear in INITRD_MODULES. This is only important if you rely on the correct setting of the device files /dev/sd?. However, in current systems you also may use the device files below /dev/disk/ that are sorted in several subdirectories, named by-id, by-path and by-uuid, and always represent the same disk. This is also possible at install time by specifying the respective mount option.

IMPORTANT: Updating initramfs or initrd

The boot loader loads initramfs or initrd in the same way as the kernel. It is not necessary to reinstall GRUB after updating initramfs or initrd, because GRUB searches the directory for the right file when booting.

14.1.2 init on initramfs

The main purpose of init on initramfs is to prepare the mounting of and access to the real root file system. Depending on your system configuration, init is responsible for the following tasks.

Loading Kernel Modules

Depending on your hardware configuration, special drivers may be needed to access the hardware components of your computer (the most important component being your hard drive). To access the final root file system, the kernel needs to load the proper file system drivers.

Providing Block Special Files

For each loaded module, the kernel generates device events. udev handles these events and generates the required block special files on a RAM file system in /dev. Without those special files, the file system and other devices would not be accessible.

Managing RAID and LVM Setups

If you configured your system to hold the root file system under RAID or LVM, init sets up LVM or RAID to enable access to the root file system later. Find information about RAID and LVM in Section 2.0, Advanced Disk Setup.

Managing Network Configuration

If you configured your system to use a network-mounted root file system (mounted via NFS), init must make sure that the proper network drivers are loaded and that they are set up to allow access to the root file system.

When init is called during the initial boot as part of the installation process, its tasks differ from those mentioned earlier:

Finding the Installation Medium

As you start the installation process, your machine loads an installation kernel and a special initrd with the YaST installer from the installation medium. The YaST installer, which is run in a RAM file system, needs to have information about the location of the installation medium to access it and install the operating system.

Initiating Hardware Recognition and Loading Appropriate Kernel Modules

As mentioned in Section 14.1.1, initramfs, the boot process starts with a minimum set of drivers that can be used with most hardware configurations. init starts an initial hardware scanning process that determines the set of drivers suitable for your hardware configuration. The names of the modules needed for the boot process are written to INITRD_MODULES in /etc/sysconfig/kernel. These names are used to generate a custom initramfs that is needed to boot the system. If the modules are not needed for boot but for coldplug, the modules are written to /etc/sysconfig/hardware/hwconfig-*. All devices that are described with configuration files in this directory are initialized in the boot process.

Loading the Installation System or Rescue System

As soon as the hardware has been properly recognized, the appropriate drivers have been loaded, and udev has created the device special files, init starts the installation system, which contains the actual YaST installer, or the rescue system.

Starting YaST

Finally, init starts YaST, which starts package installation and system configuration.

Linux忘记root密码怎么办[转]

12:34:00 AM 0 Comments

在机器启动到grub进行操作系统选择时,

对于Redhat linux:

用上下键将光标放在linux系统上,按“e”

在有kernel那一行按“e”,输入“空格 single”,然后回车

按“b”,启动,系统会自动进入单用户模式,

使用passwd root命令,按提示输入新口令

修改口令后,输入reboot 命令重启系统即可

对于SUSE linux:

先按"esc"键,从grub的图形界面转至字符界面

然后,用上下键将光标放在linux系统上,按“e”

在有kernel那一行按“e”,输入“空格 1”,然后回车

按“B”启动,系统会自动进入“runlevel 1”。

然后执行“passwd”,按提示输入新口令

修改完口令后,输入reboot命令重启系统即可。

---------------------------------------------------------------------

一. lilo
1. 在出现 lilo: 提示时键入 linux single
画面显示 lilo: linux single
2. 回车可直接进入linux命令行
3. #vi /etc/shadow
将第一行,即以root开头的一行中root:后和下一个:前的内容删除,
第一行将类似于
root::......
保存
4. #reboot重启,root密码为空

二. grub
1. 在出现grub画面时,用上下键选中你平时启动linux的那一项(别选dos哟),然后按e键
2. 再次用上下键选中你平时启动linux的那一项(类似于kernel /boot/vmlinuz-2.4.18-14 ro root=LABEL=/),然后按e键
3. 修改现在见到的命令行,有两种方法:
a.加入single,结果如下:
kernel /boot/vmlinuz-2.4.18-14 single ro root=LABEL=/
b.在行末加入run level,比如想进入run level 3,结果如下:
kernel /boot/vmlinuz-2.4.18-14 ro root=LABEL=/ 3
由于是忘记root密码,则可进入run level 1,结果如下:
kernel /boot/vmlinuz-2.4.18-14 ro root=LABEL=/ 1
4. 回车返回,然后按b键启动,即可直接进入linux命令行
5. #vi /etc/shadow
将第一行,即以root开头的一行中root:后和下一个:前的内容删除,
第一行将类似于
root::......
保存
6. #reboot重启,root密码为空
7. 这是网上的教程,但我实际操作时,老提示不能修改只读文件,于是先用chmod +w shadow命令将shadow文件改为可写。之前
所作的修改,留下了.shadow.swp文件,使用vi shadow就没有问题了。

另外还有一类,可能是比较老版本的linux,不得而知,方法如下:
  随着Linux的流行,越来越多的服务器上安装了Linux操作系统。但是问题也随之而来——忘记了服务器的密码怎么办?不用着急,使用下面介绍的三招杀手锏就可以使你在不重装Linux的情况下轻松解决密码问题。

  第一招:如果你的系统是通过LILO管理器启动的,可以在LILO启动提示符"LILO boot:"后输入"Linux single"(不包括两个双引号),回车后即可启动Linux系统进入单用户模式。这时候你就可以用passwd命令来修改你的密码了。修改完成后重新 启动系统就可以使用新的密码登录了。这一着在一些系统下行得通,但是在另一些系统下则行不通。这是你可以试试用第二招来清除Linux的密码。

  第二招:用安装系统时制作的boot盘启动,当出现"LILO boot:"提示符时输入"Linux mount =/dev/xxxx" (不包括两个双引号),其中xxxx代表Linux所在的分区。在Linux中,第一个IDE硬盘的设备名是hda,所以第一硬盘的第一分区为hda1, 第二分区为hda2,依此类推;第二个IDE硬盘的设备名是hdb,同理,第二硬盘的第一分区为hdb1,第二分区为hdb2,依此类推;如果你使用的是 SCSI硬盘,则第一硬盘的设备名是sda,第一硬盘的第一分区为sda1,第二分区为sda2,依此类推;第二个SCSI硬盘的设备名是sdb,则第二 硬盘的第一分区为sdb1,第二分区为sdb2,依此类推。正确输入硬盘的设备名及分区号后启动Linux,系统将自动把Linux的分区mount到 /mnt下。这时候你只要进入/mnt/etc下,用vi命令打开passwd文件,将root行中的密码去掉,退出并保存文件。然后重新引导系统后,在 超级用户下执行password命令,重新生成一个密码即可。这里需要注意一个问题:如果你的系统同时含有passwd和shadow两个文件,则需要修 改的密码文件是/mnt/etc下的shadow。因为shadow是passwd的一个映像,是真正存放密码的文件。如果你的Linux系统不能识 别"Linux mount =/dev/xxxx"命令也不要紧,我们还有第三招——通用方法来解决它。

  第三招:使用应急引导盘。目前各个版本的Linux都带有随盘发行的应急引导盘,一般有两张:一张是boot盘,另一张是root盘。这两张盘 一般是以img或gz格式的文件存放在光盘上,文件名各个版本都差不多,主文件名形如rescxxxx,扩展名是.img或.gz。我所使用的是 rescboot.img和rescroot.img。找到这两个文件后使用随盘附带的IMG文件写盘工具rawrite.exe将 rescboot.img和rescroot.img分别写入两张空白磁盘,然后使用这两张盘引导Linux。启动后在超级用户下执行如下命令:

  :mount/dev/xxxx/mnt
  #cd/mnt
  vi/mnt/etc/passwd

  然后将超级用户密码删除即可,删除方法同第二招。命令中的xxxx的含义与第二招中的相同。当然,如果你的系统同时含有passwd和shadow两个文件,则只需要修改/mnt/etc下的shadow即可解决问题。