Sunday, July 29, 2007

linux 启动过程(一直没有时间看,先保留)

本文以RedHat9.0和i386平台为例,剖析了从用户打开电源直到屏幕出现命令行提示符的整个Linux启动过程。并且介绍了启动中涉及到的各种文件。

  阅读Linux源代码,无疑是深入学习Linux的最好方法。在本文对Linux启动过程的介绍中,我们也尝试从源代码的视角来更深入的剖析Linux 的启动过程,所以其中也简单涉及到部分相关的Linux源代码,Linux启动这部分的源码主要使用的是C语言,也涉及到了少量的汇编。而启动过程中也执行了大量的shell(主要是bash shell)所写脚本。为了方便读者阅读,笔者将整个Linux启动过程分成以下几个部分逐一介绍,大家可以参考下图:

  当用户打开PC 的电源,BIOS开机自检,按BIOS中设置的启动设备(通常是硬盘)启动,接着启动设备上安装的引导程序lilo或grub开始引导Linux, Linux首先进行内核的引导,接下来执行init程序,init程序调用了rc.sysinit和rc等程序,rc.sysinit和rc当完成系统初始化和运行服务的任务后,返回init;init启动了mingetty后,打开了终端供用户登录系统,用户登录成功后进入了Shell,这样就完成了从开机到登录的整个启动过程。

下面就将逐一介绍其中几个关键的部分:



  第一部分:内核的引导(核内引导)

  Red Hat9.0可以使用lilo或grub等引导程序开始引导Linux系统,当引导程序成功完成引导任务后,Linux从它们手中接管了CPU的控制权,然后CPU就开始执行Linux的核心映象代码,开始了Linux启动过程。这里使用了几个汇编程序来引导Linux,这一步泛及到Linux源代码树中的“arch/i386/boot”下的这几个文件:bootsect.S、setup.S、video.S等。

  其中 bootsect.S是生成引导扇区的汇编源码,它完成加载动作后直接跳转到setup.S的程序入口。setup.S的主要功能就是将系统参数(包括内存、磁盘等,由BIOS返回)拷贝到特别内存中,以便以后这些参数被保护模式下的代码来读取。此外,setup.S还将video.S中的代码包含进来,检测和设置显示器和显示模式。最后,setup.S将系统转换到保护模式,并跳转到 0x100000。

  那么0x100000这个内存地址中存放的是什么代码?而这些代码又是从何而来的呢?

  0x100000这个内存地址存放的是解压后的内核,因为Red Hat提供的内核包含了众多驱动和功能而显得比较大,所以在内核编译中使用了“makebzImage”方式,从而生成压缩过的内核,在RedHat中内核常常被命名为vmlinuz,在Linux的最初引导过程中,是通过"arch/i386/boot/compressed/"中的head.S利用 misc.c中定义的decompress_kernel()函数,将内核vmlinuz解压到0x100000的。

  当CPU跳到 0x100000时,将执行"arch/i386/kernel/head.S"中的startup_32,它也是vmlinux的入口,然后就跳转到 start_kernel()中去了。start_kernel()是"init/main.c"中的定义的函数,start_kernel()中调用了一系列初始化函数,以完成kernel本身的设置。start_kernel()函数中,做了大量的工作来建立基本的Linux核心环境。如果顺利执行完 start_kernel(),则基本的Linux核心环境已经建立起来了。

  在start_kernel()的最后,通过调用init ()函数,系统创建第一个核心线程,启动了init过程。而核心线程init()主要是来进行一些外设初始化的工作的,包括调用 do_basic_setup()完成外设及其驱动程序的加载和初始化。并完成文件系统初始化和root文件系统的安装。

  当 do_basic_setup()函数返回init(),init()又打开了/dev/console设备,重定向三个标准的输入输出文件stdin、 stdout和stderr到控制台,最后,搜索文件系统中的init程序(或者由init=命令行参数指定的程序),并使用 execve()系统调用加载执行init程序。到此init()函数结束,内核的引导部分也到此结束了。

第二部分:运行init



  init的进程号是1,从这一点就能看出,init进程是系统所有进程的起点,Linux在完成核内引导以后,就开始运行init程序,。 init程序需要读取配置文件/etc/inittab。inittab是一个不可执行的文本文件,它有若干行指令所组成。在Redhat系统中, inittab的内容如下所示(以“###"开始的中注释为笔者增加的):

  #
  # inittab This file describes how the INIT process should set up
  # the system in a certain run-level.
  #
  # Author: Miquel van Smoorenburg,
  # 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 havenetworking)
  # 3 - Full multiuser mode
  # 4 - unused
  # 5 - X11
  # 6 - reboot (Do NOT set initdefault to this)
  #
  ###表示当前缺省运行级别为5(initdefault);
  id:5:initdefault:

  ###启动时自动执行/etc/rc.d/rc.sysinit脚本(sysinit)
  # System initialization.
  si::sysinit:/etc/rc.d/rc.sysinit

  l0:0:wait:/etc/rc.d/rc 0
  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
  ###当运行级别为5时,以5为参数运行/etc/rc.d/rc脚本,init将等待其返回(wait)
  l5:5:wait:/etc/rc.d/rc 5
  l6:6:wait:/etc/rc.d/rc 6

  ###在启动过程中允许按CTRL-ALT-DELETE重启系统
  # 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"

  ###在2、3、4、5级别上以ttyX为参数执行/sbin/mingetty程序,打开ttyX终端用于用户登录,
  ###如果进程退出则再次运行mingetty程序(respawn)
  # Run gettys in standard runlevels
  1:2345:respawn:/sbin/mingetty tty1
  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

  ###在5级别上运行xdm程序,提供xdm图形方式登录界面,并在退出时重新执行(respawn)
  # Run xdm in runlevel 5
  x:5:respawn:/etc/X11/prefdm -nodaemon

 以上面的inittab文件为例,来说明一下inittab的格式。其中以#开始的行是注释行,除了注释行之外,每一行都有以下格式:



  id:runlevel:action:process

  对上面各项的详细解释如下:

  1. id

  id是指入口标识符,它是一个字符串,对于getty或mingetty等其他login程序项,要求id与tty的编号相同,否则getty程序将不能正常工作。

  2. runlevel

  runlevel是init所处于的运行级别的标识,一般使用0-6以及S或s。0、1、6运行级别被系统保留:其中0作为shutdown 动作,1作为重启至单用户模式,6为重启;S和s意义相同,表示单用户模式,且无需inittab文件,因此也不在inittab中出现,实际上,进入单用户模式时,init直接在控制台(/dev/console)上运行/sbin/sulogin。在一般的系统实现中,都使用了2、3、4、5几个级别,在 Redhat系统中,2表示无NFS支持的多用户模式,3表示完全多用户模式(也是最常用的级别),4保留给用户自定义,5表示XDM图形登录方式。7- 9级别也是可以使用的,传统的Unix系统没有定义这几个级别。runlevel可以是并列的多个值,以匹配多个运行级别,对大多数action来说,仅当runlevel与当前运行级别匹配成功才会执行。

  3. action

  action是描述其后的process的运行方式的。action可取的值包括:initdefault、sysinit、boot、bootwait等:

  initdefault是一个特殊的action值,用于标识缺省的启动级别;当init由核心激活以后,它将读取inittab中的 initdefault项,取得其中的runlevel,并作为当前的运行级别。如果没有inittab文件,或者其中没有initdefault项, init将在控制台上请求输入runlevel。

  sysinit、boot、bootwait等action将在系统启动时无条件运行,而忽略其中的runlevel。

  其余的action(不含initdefault)都与某个runlevel相关。各个action的定义在inittab的man手册中有详细的描述。

  4. process

  process为具体的执行程序。程序后面可以带参数。

  第三部分:系统初始化

  在init的配置文件中有这么一行:

  si::sysinit:/etc/rc.d/rc.sysinit

  它调用执行了/etc/rc.d/rc.sysinit,而rc.sysinit是一个bash shell的脚本,它主要是完成一些系统初始化的工作,rc.sysinit是每一个运行级别都要首先运行的重要脚本。它主要完成的工作有:激活交换分区,检查磁盘,加载硬件模块以及其它一些需要优先执行任务。

  rc.sysinit约有850多行,但是每个单一的功能还是比较简单,而且带有注释,建议有兴趣的用户可以自行阅读自己机器上的该文件,以了解系统初始化所详细情况。由于此文件较长,所以不在本文中列出来,也不做具体的介绍。

  当rc.sysinit程序执行完毕后,将返回init继续下一步。

第四部分:启动对应运行级别的守护进程



  在rc.sysinit执行后,将返回init继续其它的动作,通常接下来会执行到/etc/rc.d/rc程序。以运行级别3为例,init将执行配置文件inittab中的以下这行:

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

  这一行表示以5为参数运行/etc/rc.d/rc,/etc/rc.d/rc是一个Shell脚本,它接受5作为参数,去执行 /etc/rc.d/rc5.d/目录下的所有的rc启动脚本,/etc/rc.d/rc5.d/目录中的这些启动脚本实际上都是一些链接文件,而不是真正的rc启动脚本,真正的rc启动脚本实际上都是放在/etc/rc.d/init.d/目录下。而这些rc启动脚本有着类似的用法,它们一般能接受 start、stop、restart、status等参数。

  /etc/rc.d/rc5.d/中的rc启动脚本通常是K或S开头的链接文件,对于以以S开头的启动脚本,将以start参数来运行。而如果发现存在相应的脚本也存在K打头的链接,而且已经处于运行态了(以 /var/lock/subsys/下的文件作为标志),则将首先以stop为参数停止这些已经启动了的守护进程,然后再重新运行。这样做是为了保证是当 init改变运行级别时,所有相关的守护进程都将重启。

  至于在每个运行级中将运行哪些守护进程,用户可以通过chkconfig或setup中的"System Services"来自行设定。常见的守护进程有:

  amd:自动安装NFS守护进程
  apmd:高级电源管理守护进程
  arpwatch:记录日志并构建一个在LAN接口上看到的以太网地址和IP地址对数据库
  autofs:自动安装管理进程automount,与NFS相关,依赖于NIS
  crond:Linux下的计划任务的守护进程
  named:DNS服务器
  netfs:安装NFS、Samba和NetWare网络文件系统
  network:激活已配置网络接口的脚本程序
  nfs:打开NFS服务
  portmap:RPC portmap管理器,它管理基于RPC服务的连接
  sendmail:邮件服务器sendmail
  smb:Samba文件共享/打印服务
  syslog:一个让系统引导时起动syslog和klogd系统日志守候进程的脚本
  xfs:X Window字型服务器,为本地和远程X服务器提供字型集
  Xinetd:支持多种网络服务的核心守护进程,可以管理wuftp、sshd、telnet等服务

  这些守护进程也启动完成了,rc程序也就执行完了,然后又将返回init继续下一步。

第五部分:建立终端



  rc执行完毕后,返回init。这时基本系统环境已经设置好了,各种守护进程也已经启动了。init接下来会打开6个终端,以便用户登录系统。通过按Alt+Fn(n对应1-6)可以在这6个终端中切换。在inittab中的以下6行就是定义了6个终端:

  1:2345:respawn:/sbin/mingetty tty1
  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

  从上面可以看出在2、3、4、5的运行级别中都将以respawn方式运行mingetty程序,mingetty程序能打开终端、设置模式。同时它会显示一个文本登录界面,这个界面就是我们经常看到的登录界面,在这个登录界面中会提示用户输入用户名,而用户输入的用户将作为参数传给 login程序来验证用户的身份。

  第六部分:登录系统,启动完成

  对于运行级别为5的图形方式用户来说,他们的登录是通过一个图形化的登录界面。登录成功后可以直接进入KDE、Gnome等窗口管理器。而本文主要讲的还是文本方式登录的情况:

  当我们看到mingetty的登录界面时,我们就可以输入用户名和密码来登录系统了。

  Linux的账号验证程序是login,login会接收mingetty传来的用户名作为用户名参数。然后login会对用户名进行分析:如果用户名不是root,且存在/etc/nologin文件,login将输出nologin文件的内容,然后退出。这通常用来系统维护时防止非 root用户登录。只有/etc/securetty中登记了的终端才允许root用户登录,如果不存在这个文件,则root可以在任何终端上登录。 /etc/usertty文件用于对用户作出附加访问限制,如果不存在这个文件,则没有其他限制。

  在分析完用户名后,login将搜索/etc/passwd以及/etc/shadow来验证密码以及设置账户的其它信息,比如:主目录是什么、使用何种shell。如果没有指定主目录,将默认为根目录;如果没有指定shell,将默认为/bin/bash。

  login程序成功后,会向对应的终端在输出最近一次登录的信息(在/var/log/lastlog中有记录),并检查用户是否有新邮件 (在 /usr/spool/mail/的对应用户名目录下)。然后开始设置各种环境变量:对于bash来说,系统首先寻找/etc/profile脚本文件,并执行它;然后如果用户的主目录中存在.bash_profile文件,就执行它,在这些文件中又可能调用了其它配置文件,所有的配置文件执行后后,各种环境变量也设好了,这时会出现大家熟悉的命令行提示符,到此整个启动过程就结束了。

  希望通过上面对Linux启动过程的剖析能帮助那些想深入学习Linux用户建立一个相关Linux启动过程的清晰概念,进而可以进一步研究Linux接下来是如何工作的。

***************************************************************************************
***************************************************************************************

 由于操作系统正在变得越来越复杂,所以开机引导和关机下电的过程也越来越智能化。从简单的DOS系统转移到 Windows NT系统,人们已经亲身感受到了这些变化——这已不仅仅是核心操作系统的启动引导和关闭了,还包括必须要同时启动或者关闭相当数量的服务项目。类似于 Windows NT,Linux系统启动过程需要打开的服务项目也是数量极大的。

  这里,我们假设大家已经熟悉其它操作系统的引导过程,了解硬件的自检引导步骤,就只从Linux操作系统的引导加载程序(对个人电脑而言通常是LILO)开始,介绍Linux开机引导的步骤。

  加载内核

  LILO启动之后,如果你选择了Linux作为准备引导的操作系统,第一个被加载的东西就是内核。请记住此时的计算机内存中还不存在任何操作系统, PC(因为它们天然的设计缺陷)也还没有办法存取机器上全部的内存。因此,内核就必须完整地加载到可用RAM的第一个兆字节之内。为了实现这个目的,内核是被压缩了的。这个文件的头部包含着必要的代码,先设置CPU进入安全模式(以此解除内存限制),再对内核的剩余部分进行解压缩。

  执行内核

  内核在内存中解压缩之后,就可以开始运行了。此时的内核只知道它本身内建的各种功能,也就是说被编译为模块的内核部分还不能使用。最基本的是,内核必须有足够的代码设置自己的虚拟内存子系统和根文件系统(通常就是ext2文件系统)。一旦内核启动运行,对硬件的检测就会决定需要对哪些设备驱动程序进行初始化。从这里开始,内核就能够挂装根文件系统(这个过程类似于Windows识别并存取C盘的过程)。内核挂装了根文件系统之后,将启动并运行一个叫做 init的程序。

  注意:在这里我们故意略去了Linux内核启动的许多细节,这些细节只有内核开发人员才感兴趣。如果你好奇的话,可以访问http://www.redhat.com:8080地址处的 “Kernel Hackers Guide”。

  init进程

  init进程是非内核进程中第一个被启动运行的,因此它的进程编号PID的值总是1。init读它的配置文件/etc/inittab,决定需要启动的运行级别(Runlevel)。从根本上说,运行级别规定了整个系统的行为,每个级别(分别由0到6的整数表示)满足特定的目的。如果定义了 initdefault级别,这个值就直接被选中,否则需要由用户输入一个代表运行级别的数值。

  输入代表运行级别的数字之后,init根据/etc/inittab文件中的定义执行一个命令脚本程序。缺省的运行级别取决于安装阶段对登录程序的选择:是使用基于文本的,还是使用基于X-Window的登录程序。

  rc命令脚本程序

  我们已经知道,当运行级别发生改变时,将由/etc/inittab文件定义需要运行哪一个命令脚本程序。这些命令脚本程序负责启动或者停止该运行级别特定的各种服务。由于需要管理的服务数量很多,因此需要使用rc命令脚本程序。其中,最主要的一个是/etc/rc.d/rc,它负责为每一个运行级别按照正确的顺序调用相应的命令脚本程序。我们可以想象,这样一个命令脚本程序很容易变得难以控制!为了防止这类事件的发生,需要使用精心设计的方案。

  对每一个运行级别来说,在/etc/rc.d子目录中都有一个对应的下级目录。这些运行级别的下级子目录的命名方法是rcX.d,其中的X就是代表运行级别的数字。比如说,运行级别3的全部命令脚本程序都保存在/etc/rc.d/rc3.d子目录中。

  在各个运行级别的子目录中,都建立有到/etc/rc.d/init.d子目录中命令脚本程序的符号链接,但是,这些符号链接并不使用命令脚本程序在 /etc/rc.d/init.d子目录中原来的名字。如果命令脚本程序是用来启动一个服务的,其符号链接的名字就以字母S打头;如果命令脚本程序是用来关闭一个服务的,其符号链接的名字就以字母K打头。

  许多情况下,这些命令脚本程序的执行顺序都很重要。如果没有先配置网络接口,就没有办法使用DNS服务解析主机名!为了安排它们的执行顺序,在字母S 或者K的后面紧跟着一个两位数字,数值小的在数值大的前面执行。比如:/etc/rc.d/rc3.d/S50inet就会在 /etc/rc.d/rc3.d/S55named之前执行(S50inet配置网络设置,S55named启动DNS服务器)。

  存放在/etc/rc.d/init.d子目录中的、被符号链接上的命令脚本程序是真正的实干家,是它们完成了启动或者停止各种服务的操作过程。当 /etc/rc.d/rc运行通过每个特定的运行级别子目录的时候,它会根据数字的顺序依次调用各个命令脚本程序执行。它先运行以字母K打头的命令脚本程序,然后再运行以字母S打头的命令脚本程序。对以字母K打头的命令脚本程序来说,会传递Stop参数;类似地对以字母S打头的命令脚本程序来说,会传递 Start参数。

  编写自己的rc命令脚本

  在维护Linux系统运转的日子里,肯定会遇到需要系统管理员对开机或者关机命令脚本进行修改的情况。有两种方法可以用来实现修改的目的:

  ● 如果所做的修改只在引导开机的时候起作用,并且改动不大的话,可以考虑简单地编辑一下/etc/rc.d/rc.local脚本。这个命令脚本程序是在引导过程的最后一步被执行的。

  ● 如果所做的修改比较细致,或者还要求关闭进程使之明确地停止运行,则需要在/etc/rc.d/init.d子目录中添加一个命令脚本程序。这个命令脚本程序必须可以接受Start和Stop参数并完成相应的操作。

  第一种方法,编辑/etc/rc.d/rc.local脚本,当然是两种方法中比较简单的。如果想在这个命令脚本程序中添加内容,只需要使用喜欢的编辑器程序打开它,再把打算执行的命令附加到文件的末尾就可以了。这对一两行的修改来说的确很便利。

  如果确实需要使用一个命令脚本程序,这时必须选择第二个方法。编写一个rc命令脚本程序的过程并不像想象中那么困难。我们下面就给出一个例子,看看它是怎样实现的(顺便说一句,你可以把我们的例子当作范本,按照自己的需要进行修改和添加)。

  假设你打算每隔60分钟调用一个特殊的程序来弹出一条消息,提醒自己需要从键盘前面离开休息一会儿,命令脚本程序将包括下面几个部分:

  ● 关于这个命令脚本程序功能的说明(这样就不会在一年之后忘记它);

  ● 在试图运行它之前验证这个命令脚本程序确实存在;

  ● 接受start和stop参数并执行要求的动作。

  参数给定后,我们就可以编写命令的脚本程序。这个程序很简单,大家可以自己编写一下,我在这里就不给出了。

  编写好新的命令脚本程序之后,再从相关的运行级别子目录中加上必要的符号链接,来控制这个命令脚本程序的启动或者停止。在我的印象中,只想让它在运行级别3或者运行级别5中启动,原因是我认为只有这两个运行级别才是日常工作的地方。最后,希望这个命令脚本程序在进入运行级别6(重启动)的时候被关闭。

  激活或者禁止服务项目

  有的时候会发现,在引导的时候并不需要某个特定的服务被启动。如果你正在考虑使用Linux替换Windows NT的文件和打印服务器,就更是如此。

  我们已经知道,在特定的运行级别子目录中给符号链接改个名称,就可以让该服务不被启动,如把其名称的第一个字母由S改为K。一旦熟练掌握了命令行和符号链接,就会发现这是激活或者禁止服务的最快办法。

  在学习这个改名方法的时候,可能会觉得图形化的操作界面ksysv比较容易掌握。虽然它原来是设计使用在KDE环境里的,但在 Red Hat Linux 7.2下缺省安装的GNOME环境里也运行得很好。如果想启动它,只需简单地打开一个xterm窗口,并输入ksysv命令就可以了。屏幕上会出现一个窗口,其中列出了能够修改的全部参数,需要时还包括在线帮助。

  警告:如果是在一个现实中的系统上学习本文的知识,要多多运用常识。当试着对启动脚本程序进行修改的时候,要记住所做的修改可能会造成你的系统不能正常工作,而且无法采用重启动的方法恢复。不要在正常运转的系统上实验新的设置,对你准备修改的文件要全部进行备份。最重要的是,在手边要准备一张引导盘以防不测。

**************************************************************************************
**************************************************************************************

1) 从BIOS到内核

BIOS自检

计算机在接通电源之后首先由BIOS进行自检,即进行所谓的POST(Power On Self
Test),然后依据BIOS内设置的引导顺序从硬盘、软盘或CDROM中读入“引导块”。 在 PC 中,引导 Linux 是从 BIOS 中的地址 0xFFFF0 处开始的。BIOS 的第一个步骤是加电自检(POST)。POST 的工作是对硬件进行检测。BIOS 的第二个步骤是进行本地设备的枚举和初始化。给定 BIOS 功能的不同用法之后,BIOS 由两部分组成:POST 代码和运行时服务。当 POST 完成之后,它被从内存中清理了出来,但是 BIOS 运行时服务依然保留在内存中,目标操作系统可以使用这些服务。

要引导一个操作系统,BIOS 运行时会按照 CMOS 的设置定义的顺序来搜索处于活动状态并且可以引导的设备。引导设备可以是软盘、CD-ROM、硬盘上的某个分区、网络上的某个设备,甚至是 USB 闪存。通常,Linux 都是从硬盘上引导的,其中主引导记录(MBR)中包含主引导加载程序。MBR 是一个 512 字节大小的扇区,位于磁盘上的第一个扇区中(0 道 0 柱面 1 扇区)。当 MBR 被加载到 RAM 中之后,BIOS 就会将控制权交给 MBR。

提取 MBR 的信息

要查看 MBR 的内容,请使用下面的命令:

# dd if=/dev/hda of=mbr.bin bs=512 count=1 # od -xa mbr.bin

这个 dd 命令需要以 root 用户的身份运行,它从 /dev/hda(第一个 IDE 盘) 上读取前 512 个字节的内容,并将其写入 mbr.bin 文件中。od 命令会以十六进制和 ASCII 码格式打印这个二进制文件的内容。
(2)启动GRUB/LILO

GRUB和LILO都是引导加载程序。最简单地讲,引导加载程序(boot loader) 会引导操作系统。当机器引导它的操作系统时,BIOS 会读取引导介质上最前面的 512 字节(即人们所知的 主引导记录(master boot record,MBR))。在单一的 MBR 中只能存储一个操作系统的引导记录,所以当需要多个操作系统时就会出现问题。所以需要更灵活的引导加载程序。

GRUB 与 LILO 的比较

如本文开始处所述,所有引导加载程序都以类似的方式工作,满足共同的目的。不过,LILO 和 GRUB 之间有很多不同之处:

* LILO 没有交互式命令界面,而 GRUB 拥有。
* LILO 不支持网络引导,而 GRUB 支持。
* LILO 将关于可以引导的操作系统位置的信息物理上存储在 MBR 中。如果修改了 LILO 配置文件,必须将 LILO 第一阶段引导加载程序重写到 MBR。相对于 GRUB,这是一个更为危险的选择,因为错误配置的 MBR 可能会让系统无法引导。使用 GRUB,如果配置文件配置错误,则只是默认转到 GRUB 命令行界面。

安全提示:

关于安全性,任何可以接触到引导磁盘/CD 的人,只需要使用没有设置安全性的 grub.conf 或 lilo.conf,就可以绕过本文中提及的所有安全措施。特别是使用 GRUB 时,因为能够引导到单用户模式,所以是一个严重的安全漏洞。解决此问题的一个简单方法是在机器的 BIOS 中禁止通过 CD 和软盘进行引导,并确保为 BIOS 设置了一个口令,使得其他人不能修改这些设置。
(3)加载内核

当内核映像被加载到内存之后,内核阶段就开始了。内核映像并不是一个可执行的内核,而是一个压缩过的内核映像。通常它是一个 zImage(压缩映像,小于 512KB)或一个 bzImage(较大的压缩映像,大于 512KB),它是提前使用 zlib 进行压缩过的。在这个内核映像前面是一个例程,它实现少量硬件设置,并对内核映像中包含的内核进行解压,然后将其放入高端内存中,如果有初始 RAM 磁盘映像,就会将它移动到内存中,并标明以后使用。然后该例程会调用内核,并开始启动内核引导的过程。

GRUB 中的手工引导

在 GRUB 命令行中,我们可以使用 initrd 映像引导一个特定的内核,方法如下:

grub> kernel /bzImage-2.6.14.2
[Linux-bzImage, setup=0x1400, size=0x29672e]

grub> initrd /initrd-2.6.14.2.img
[Linux-initrd @ 0x5f13000, 0xcc199 bytes]

grub> boot

Uncompressing Linux... Ok, booting the kernel.
如果您不知道要引导的内核的名称,只需使用斜线(/)然后按下 Tab 键即可。GRUB 会显示内核和 initrd 映像列表。
(4)执行init进程

init进程是系统所有进程的起点,内核在完成核内引导以后,即在本线程(进程)空间内加载init程序,它的进程号是1。init进程是所有进程的发起者和控制者。因为在任何基于Unix的系统(比如Linux)中,它都是第一个运行的进程,所以init进程的编号(Process ID,PID)永远是1。如果init出现了问题,系统的其余部分也就随之而垮掉了。

init进程有两个作用。第一个作用是扮演终结父进程的角色。因为init进程永远不会被终止,所以系统总是可以确信它的存在,并在必要的时候以它为参照。如果某个进程在它衍生出来的全部子进程结束之前被终止,就会出现必须以init为参照的情况。此时那些失去了父进程的子进程就都会以init作为它们的父进程。快速执行一下ps -af 命令,可以列出许多父进程ID(Parent Process ID,PPID)为1的进程来。

init的第二个角色是在进入某个特定的运行级别(Runlevel)时运行相应的程序,以此对各种运行级别进行管理。它的这个作用是由/etc/inittab文件定义的。
(5)通过/etc/inittab文件进行初始化

init的工作是根据/etc/inittab来执行相应的脚本进行系统初始化,如设置键盘、字体, 装载模块,设置网络,等等。

对于RedhatLinux来说,执行的顺序为:

* /etc/rc.d/rc.sysinit # 由init执行的第一个脚本
/etc/rc.d/rc.sysinit主要做在各个运行模式中相同的初始化工作,包括:
设置初始的$PATH变量。
配置网络。
为虚拟内存启动交换。
设置系统的主机名。
检查root文件系统,以进行必要的修复。
检查root文件系统的配额。
为root文件系统打开用户和组的配额。
以读/写的方式重新装载root文件系统。
清除被装载的文件系统表/etc/mtab。
把root文件系统输入到mtab。
使系统为装入模块做准备。
查找模块的相关文件。
检查文件系统,以进行必要的修复。
加载所有其他文件系统。
清除几个/etc文件:/etc/mtab、/etc/fastboot和/etc/nologin。
删除UUCP的lock文件。
删除过时的子系统文件。
删除过时的pid文件。
设置系统时钟。
打开交换。
初始化串行端口。
装入模块。
* /etc/rc.d/rcX.d/[KS]

首先终止“K”开头的服务,然后启动“S”开头的服务。

对每一个运行级别来说,在/etc/rc.d子目录中都有一个对应的下级目录。这些运行级别的下级子目录的命名方法是rcX.d,其中的X就是代表运行级别的数字。比如说,运行级别3的全部命令脚本程序都保存在/etc/rc.d/rc3.d子目录中。在各个运行级别的子目录中,都建立有到 /etc/rc.d/init.d子目录中命令脚本程序的符号链接,但是,这些符号链接并不使用命令脚本程序在 /etc/rc.d/init.d子目录中原来的名字。如果命令脚本程序是用来启动一个服务的,其符号链接的名字就以字母S打头;如果命令脚本程序是用来关闭一个服务的,其符号链接的名字就以字母K打头。许多情况下,这些命令脚本程序的执行顺序都很重要。如果没有先配置网络接口,就没有办法使用DNS服务解析主机名!为了安排它们的执行顺序,在字母S或者 K的后面紧跟着一个两位数字,数值小的在数值大的前面执行。比如:/etc/rc.d/rc3.d/S50inet就会在 /etc/rc.d/rc3.d/S55named之前执行。存放在/etc/rc.d/init.d子目录中的、被符号链接上的命令脚本程序是真正的实干家,是它们完成了启动或者停止各种服务的操作过程。当 /etc/rc.d/rc运行通过每个特定的运行级别子目录的时候,它会根据数字的顺序依次调用各个命令脚本程序执行。它先运行以字母K打头的命令脚本程序,然后再运行以字母S打头的命令脚本程序。对以字母K打头的命令脚本程序来说,会传递Stop参数;类似地对以字母S打头的命令脚本程序来说,会传递 Start参数。
* 执行/etc/ec.d/rc.local
Redhat Linux中的运行模式2、3、5都把/etc/rc.d/rc.local做为初始化脚本中的最后一个,所以用户可以自己在这个文件中添加一些需要在其他初始化工作之后,登录之前执行的命令。在维护Linux系统运转的日子里,肯定会遇到需要系统管理员对开机或者关机命令脚本进行修改的情况。如果所做的修改只在引导开机的时候起作用,并且改动不大的话,可以考虑简单地编辑一下/etc/rc.d/rc.local脚本。这个命令脚本程序是在引导过程的最后一步被执行的。
* 执行 /bin/login 程式

login 程序会提示使用者需输入账号及密码, 接着编码并确认密码的正确性, 若二者相合, 则为使用者进行初始化环境, 并将控制权交给 shell,即等待用户登录。
多次为止Linux启动过程全部结束。

最后笔者使用图1解释全部过程。


总结:与 Linux 本身非常类似,Linux 的启动引导过程也非常灵活,可以支持众多的处理器和硬件平台。LILO 引导加载程序对引导能力进行了扩充,但是它却缺少文件系统的感知能力。最新一代的引导加载程序,例如 GRUB将更加灵活。

Tuesday, November 14, 2006

重新装window后 grub的恢复

1.下载grldr到根目录下
2.在boot.ini里加入
c:\grldr="grub"

加入后boot.ini大体如下
[boot loader]
timeout=30
default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /noexecute=optin /fastdetect
c:\grldr="grub"


3。重新启动,选择grub
然后enter command line

然后 root (hd0
然后按tab,选择你的ubuntu安装分区,比如我是root (hd0,2),ext3分区的

setup(hd0,0)

重新启动,就ok了

Saturday, November 11, 2006

How to set default application for running a program

just revise the file
/usr/share/applications/defaults.list
for example:
application/pdf=AdobeReader.desktop
will set acroread as the default application when viewing pdf file
Don't forget make a backup file in the first place ^_^

Sunday, November 05, 2006

Emacs Tips (configuration of .emacs)

Emacs Tips & Tricks
Power tools for Emacs users


This document is available at http://geosoft.no/development/emacs.html


Basic Tips & Tricks

Emacs initialization

When Emacs is launched, a specific initialization file is read. The initialization file can contain Emacs personal preferences like the functions and key bindings examples in this document. In addition it can contain default state settings for Emacs variables. Some examples are given below.

(setq default-frame-alist (append (list
'(width . 81) ; Width set to 81 characters
'(height . 40)) ; Height set to 60 lines
default-frame-alist))

(setq inhibit-startup-message t) ; Don't want any startup message
(setq make-backup-files nil) ; Don't want any backup files
(setq auto-save-list-file-name nil) ; Don't want any .saves files
(setq auto-save-default nil) ; Don't want any auto saving

(setq search-highlight t) ; Highlight search object
(setq query-replace-highlight t) ; Highlight query object
(setq mouse-sel-retain-highlight t) ; Keep mouse high-lightening

(set-face-background 'region "yellow") ; Set region background color
(set-background-color "wheat3") ; Set emacs bg color

In the MS-Windows environment the initialization file should be called _EMACS and should be put in the root directory. In UNIX based systems the file should be called .emacs and should be put in the personal home directory.

Key bindings

For maximum typing and editing efficiency, as many keyboard keys as possible should be bound directly to Emacs functions. Some are already bound when Emacs is installed, but the great variety of keyboards and operating systems available makes it difficult for the Emacs team to pre bind functions in general.

To bind a function to a key, include a statement of the form

(global-set-key key-name 'function-name)

in the initialization file. key-name is either given as an actual name within brackets like [f1] for the F1 function key, or as "\C-q" or "\M-q" for a Control-key or Escape-key sequence respectively.

Remember that function that are not bound to a specific key or key sequence (actually this includes most functions) can always be accessed by typing

Esc-x function-name

This document gives many examples of possible Emacs key bindings. Since the name of the keys may differ between keyboards and operating systems, the following approach can be used to find the name of a specific key. Enter

Esc-x describe-key

and hit the key (or key combination) in question. This will reveal the name of the key as well as the function it is currently bound to.

Complete word

Emacs includes a very useful concept called complete word. Whenever in the minibuffer, it is always possible to hit the space bar to let Emacs try to complete the current input. This can save many key strokes and a lot of time.

For instance when looking for a file one can give one letter of a directory or a file name and, in case it is unique, Emacs will fill in the rest automatically. If it is not unique, Emacs will fill in as much as possible and return the different possible completions to let you choose between them.

The Emacs region

Emacs includes a powerful concept called a region. A region is like a marked area in a conventional word processor, but more useful in the way Emacs functions can be applied to it directly, for instance for sorting just a few lines of a file, or for printing a portion of a file.

A region is set implicitly by many Emacs functions, but can be set manually as well using Ctrl-Space. This specifies the current cursor position as one end of the region, called the mark. The cursor can then be moved around and its position will specify the other end of the region.

Cut, copy and paste key bindings

Based on the description of a region above, defining the common functions Cut, Copy and Paste on the region becomes very useful. The functions should be bound to keys for easy access, for instance like:

(global-set-key [f5] 'copy-region-as-kill) ; Copy
(global-set-key [f6] 'kill-region) ; Cut
(global-set-key [f7] 'yank) ; Paste

An element that is cut or copied this way is put into something called the kill-ring. Calling the yank function always pastes the last entry from the kill-ring. However, after the yank function as called, it is possible to replace the pasted text by the second last entry in the ring and so on by calling the yank-pop (by default boud to the Esc-y key) function repeatedly. In effect, all cut/copy operations of the session is registered, and are easily accessible through this simple sequence of key strokes.

Column handling

A feature that are missing in most editors and word processors is the possibility to cut/copy and paste a vertical region of a file. In Emacs this is simple. The column to cut or copy is marked as a region as described above. It can then be cut calling the function kill-rectangle and re-pasted by yank-rectangle

Navigation key bindings

These are the basic navigation keys. Many keyboard come with two sets of these keys, so each function is bound once for each key. Some of these functions are usually already bound when Emacs is installed.

(global-set-key [kp-home] 'beginning-of-buffer) ; [Home]
(global-set-key [home] 'beginning-of-buffer) ; [Home]
(global-set-key [kp-end] 'end-of-buffer) ; [End]
(global-set-key [end] 'end-of-buffer) ; [End]
(global-set-key [kp-prior] 'my-scroll-down) ; [PgUp]
(global-set-key [prior] 'my-scroll-down) ; [PgUp]
(global-set-key [kp-next] 'my-scroll-up) ; [PgDn]
(global-set-key [next] 'my-scroll-up) ; [PgDn]

Undo

Emacs has the most amazing undo facility. Anything you have typed since your session began is registered and can be undone. Since this obviously is a very useful function it should be bound directly to a key. Using the keypad [-] (subtraction) key for this purpose is convenient since it indicates the nature of the operation as well as being located so far away that it isn't easily accessed by accident.

(global-set-key [kp-subtract] 'undo) ; [Undo]

Insert/overwrite mode

By default Emacs run in insert mode. This state can be toggled with overwrite mode, and is best bound to the Insert key(s) on the keyboard.

(global-set-key [insert] 'overwrite-mode) ; [Ins]
(global-set-key [kp-insert] 'overwrite-mode) ; [Ins]

Goto line

To go to a specific line can be useful, especially when Emacs is used for programming. This common function can be bound to Ctrl-L by:

(global-set-key "\C-l" 'goto-line) ; [Ctrl]-[L]

Window splitting

The Emacs window can be split so that is can display two or more buffers at the same time. This can be useful when comparing two files, or when editing two files simultaneously. Functions for managing window splits:

(global-set-key [f2] 'split-window-vertically)
(global-set-key [f1] 'remove-split)

Frames

As well as displaying more than one buffer in a window, Emacs can also display more than one window (or frames as it is called in Emacs terminology). Creating and deleting frames can conveniently be done by binding the the functions as follows:

(global-set-key "\C-f" 'make-frame) ; [Ctrl]-[F]
(global-set-key "\M-f" 'delete-frame) ; [ESC]-[F]

Getting information

Emacs contains lots of features and possibilities and it can be difficult to comprehend and utilize it all. However, Emacs comes with full documentation included. One of the more useful functions is apropos:

[ESC]-x apropos

This command prompts for a name or a concept and will return list of all functions or variables that relates to the entry given. This is a very useful approach for getting to know Emacs and the possibilities it contains.

Given an Emacs function or a variable it can sometimes be difficult to know exactly what it does. An explanation of a function or a variable can be obtained by:

[ESC]-x describe-function
[ESC]-x describe-variable

They will prompt for a name and return a comprehensive description of it.

Similarly, as described above

[ESC]-x describe-key

prompts for a key and returns the name of the key and the function it is currently bound to.


File Finder

This extension to the powerful Emacs complete-word facility is the major time saver for the frequent Emacs user. It is used within the find-file function and makes it possible to enter a given directory in the minibuffer by just entering a predefined two- to four letter sequence followed by the space key. Three different paths are given in the example below. The list can however be extended indefinetly.

(defun geosoft-parse-minibuffer ()
;; Extension to the complete word facility of the minibuffer
(interactive)
(backward-char 4)
(setq found t)
(cond
; local directories
((looking-at "..cd") (setq directory "c:/users/john/"))
((looking-at ".doc") (setq directory "c:/users/john/documents/"))
((looking-at "java") (setq directory "c:/users/john/src/java/"))
(t (setq found nil)))
(cond (found (beginning-of-line)
(kill-line)
(insert directory))
(t (forward-char 4)
(minibuffer-complete))))

The function is made an extension to the minibuffer complete-word function by:

(define-key minibuffer-local-completion-map " " 'geosoft-parse-minibuffer)


Buffer Switcher

After a file has been loaded once, it is available in an Emacs buffer. Emacs is installed with lots of clever functions for fast retrieval of buffers. The function below is different however. It makes it possible to browse through the buffer list by single key-strokes only. It is also clever in its handling of the buffer stack in the way that the most frequent visited buffers (i.e. files) always are at the top of the stack.

(defvar LIMIT 1)
(defvar time 0)
(defvar mylist nil)

(defun time-now ()
(car (cdr (current-time))))

(defun bubble-buffer ()
(interactive)
(if (or (> (- (time-now) time) LIMIT) (null mylist))
(progn (setq mylist (copy-alist (buffer-list)))
(delq (get-buffer " *Minibuf-0*") mylist)
(delq (get-buffer " *Minibuf-1*") mylist)))
(bury-buffer (car mylist))
(setq mylist (cdr mylist))
(setq newtop (car mylist))
(switch-to-buffer (car mylist))
(setq rest (cdr (copy-alist mylist)))
(while rest
(bury-buffer (car rest))
(setq rest (cdr rest)))
(setq time (time-now)))

The function is bound to a function key (for instance F4) by:

(global-set-key [f4] 'bubble-buffer)

When you are definitely done with a buffer (i.e. a file) it can be convinient to remove it from the buffer stack. To silently remove the current buffer from the stack (and retrieve the next one on the stack), bind the following function to the Ctrl-Del key.

(defun geosoft-kill-buffer ()
;; Kill default buffer without the extra emacs questions
(interactive)
(kill-buffer (buffer-name))
(set-name))

Bind by:

(global-set-key [C-delete] 'geosoft-kill-buffer)
(global-set-key [C-kp-delete] 'geosoft-kill-buffer)


Navigator

For fast navigation within an Emacs buffer it is necessary to be able to move swiftly between words. The functions below change the default Emacs behavour on this point slightly, to make them a lot more usable.

Note the way that the underscore character is treated. This is convinient behaviour in programming. Other domains may have different requirements, and these functions should be easy to modify in this respect.

(defun geosoft-forward-word ()
;; Move one word forward. Leave the pointer at start of word
;; instead of emacs default end of word. Treat _ as part of word
(interactive)
(forward-char 1)
(backward-word 1)
(forward-word 2)
(backward-word 1)
(backward-char 1)
(cond ((looking-at "_") (forward-char 1) (geosoft-forward-word))
(t (forward-char 1))))

(defun geosoft-backward-word ()
;; Move one word backward. Leave the pointer at start of word
;; Treat _ as part of word
(interactive)
(backward-word 1)
(backward-char 1)
(cond ((looking-at "_") (geosoft-backward-word))
(t (forward-char 1))))

Bind the functions to Ctrl-Left and Ctrl-Right with:

(global-set-key [C-right] 'geosoft-forward-word)
(global-set-key [C-left] 'geosoft-backward-word)


Scroller

Scrolling without moving the cursor can be achieved by the functions:

(defun scroll-down-keep-cursor ()
;; Scroll the text one line down while keeping the cursor
(interactive)
(scroll-down 1))

(defun scroll-up-keep-cursor ()
;; Scroll the text one line up while keeping the cursor
(interactive)
(scroll-up 1))

Bind the functions to the /-key and the *-key (on the numeric keypad) with:

(global-set-key [kp-divide] 'scroll-down-keep-cursor)
(global-set-key [kp-multiply] 'scroll-up-keep-cursor)


Emacs for Programmers

Modes

During editing Emacs can be set in different modes. The mode has some knowledge about the structure of the document the user is working on, and can assist on the organization, formatting and editing of this.

This is particularly helpful when Emacs is used for programming, since programming languages in general has rigid sets of restrictions regarding document structure. For instance, programming statements are normally indented according to specific rules, and if the mode know the rules, it can do the indentation for the user automatically.

There exists modes for all major and minor programming languages and most types of documents such as HTML, Perl scripts, shell scripts, Unix Makefiles, CSS etc. The mode is automatically set by Emacs based on the name or the extension of the file edited.

Color coding

A very useful feature is Emacs' ability to render text with different colors and fonts. Emacs packages for color coding analyse the structure of the text and color the text according to the structure. For instance can programming comments get one color, reserved words a different color, function definitions yet another and so on.

A popular color coding package that comes with the standard Emacs distribution is hilite. To use it, include the following statement in the initialization file:

(load "hilit19")

During editing, it is in general impossible for the color coding package to color the text since the structure of the edited part of the document may not yet be complete. Beacuase of this, it is handy to be able to refresh the color coding manually. This is done with the function hilit-highlight-buffer which can be bound to a key combination for convenience.

Including predefined element skeletons

Many of the text elements that are used in programming has a standard form based on common skeletons. The ability to include skeletons like these with a single keystroke can be very useful and time efficient.

For instance, declaration and documentation comments in Java follow the rules dictated by the javadoc automatic documentation system. A typical javadoc method comment will look something like this:

/**
*
* Returns the character at the specified index. An index
* ranges from 0 to length()-1&
*
* @param index of the desired character
* @return the desired character
* @exeption StringIndexOutOfRangeExeption
* if the index is not in the range 0
* to length()-1&.
* @see java.lang.Character#charValue()
*/
public char charAt(int index) {
...
}

To create a skeleton that can be included directly into a java source file, include the following LISP function in the Emacs initialization file:

(defun javadoc-method-comment ()
;; Insert a javadoc method comment at the cursor position
(interactive)
(insert
"/**
*
*
*
*
* @param
* @return
* @exeption
* @see
*/
")/
(previous-line 8)
(end-of-line))

The function can be bound to a key by for instance:

(define-key java-mode-map [f9] 'javadoc-method-comment)

So hitting F9 will in effect include a javadoc method comment skeleton at the cursor position and move the cursor to the position within the comment where the description should start.

Along the same lines it is easy to predefine a large number of code elements, for instance while loops, if-then-else constructions, file headers etc. and make them available by single key strokes or key combinations.


Emacs Links


Thursday, October 19, 2006

change the default display manager

just run
sudo dpkg-reconfigure gdm
and then select which display manager as the default display manager. For KDE, select kdm, for GNOME, corresponding gdm.
or change the file /etc/X11/default-display-manager
/usr/sbin/gdm
or
/usr/sbin/kdm

Wednesday, October 18, 2006

upgrade java 1.4 to 1.5

Ubuntu 6.06

  • Sun Java5: Install it from the Applications -> Add/Remove... menu making sure to check the unsupported and proprietary software checkboxes, or install the sun-java5-bin package.

  • Blackdown Java2 1.4 packages: Install the j2re1.4 package, available in the multiverse repositories. Install it from the Applications -> Add/Remove... menu, or install the j2re1.4 package.


Kubuntu 6.06

  • Sun Java5: Load up Konsole, and type:


sudo apt-get install sun-java5-bin

Accept the licence agreement that appears.

{i} Note: The license may not come up and will cause the package installation to fail, to fix this, do the following:

  • In a terminal, type

sudo apt-get install libqt-perl sudo dpkg-reconfigure debconf
  • The first command will install the needed package for debconf-kde counterpart. The second command will ask a few questions: For the first step, choose "kde". For the second step, choose "high". Then, to fix the packages that did not correctly install, do:

sudo apt-get -f install
  • then you are done.

  • Blackdown Java2 1.4 packages: Install the j2re1.4 package, available in the multiverse repositories. Install it from the Applications -> Add/Remove... menu, or install the j2re1.4 package.

{i} Note: Scroll down to "Selecting the default Java version" section to enable the JRE you have installed.

more information look up

https://help.ubuntu.com/community/Java

Monday, October 16, 2006

How to add the installed application to the application menu

Here we will install the Lumaqq in the directory /home/wason/tools and we will add a shortcut for the application menu of the category internet
In the first place, build a new desktop file for lumaqq
sudo emacs /usr/share/applications/LumaQQ.desktop

然后,在新增的文件内加入下面这几行
[Desktop Entry]
Name=LumaQQ
Comment=QQ Client
Exec=/home/wason/tools/LumaQQ/lumaqq
Icon=/home/wason/tools/LumaQQ/QQ.png
Terminal=false
Type=Application
Categories=Application;Network;

the Categories is independant which one you want to added, we could find corresponding catergory by look up exiested file in /usr/share/applications/

Tips for change MAC ID, GRUB, install KDE, GNOME in Kubuntu and Ubuntu

To change Mac IP, as far as I know there is two ways, one is temporarily change MAC, that means when reboot the system, the original MAC will be recovered. In this way, assume we will alter the MAC of eth0, we can do it by command
ifconfig eth0 down
ifconfig eth0 hw ether 00:10:11:11:11:22
ifconfig eth0 up

if you want to reset your MAC IP permanently, you have to revise some system file. There are two way to do it as well.
1) add the following to the file /etc/rc.local
/etc/init.d/networking stop
ifconfig eth0 hw ether 00:10:11:11:11:22
/etc/init.d/networking start

2)change some contents of the file /etc/network/interfaces, usually, it looks like
iface eth0 inet hdcp(static)
pre-up ifconfig eth0 hw ether 00:10:11:11:11:22
address 141.76.124.81
gateway 141.76.124.1
netmask 255.255.255.0

for DNS, they are stored in /etc/resolv.conf in the format "nameserver [IP Address]", eg
nameserver 123.123.123.123

after this correction, restart the networking by
/etc/init.d/networking restart


My personal GRUB setting
/boot/grub/menu.lst

## default num
# Set the default entry to the entry number NUM. Numbering starts from 0, and
# the entry number 0 is the default if the command is not used.
default 0
#if set 1, windows XP will be the default boot system

# Set a timeout, in SEC seconds, before automatically booting the default entry
# (normally the first entry defined).
timeout 10

title Ubuntu
root (hd0,1)
kernel /boot/vmlinuz-2.6.15-23-386 root=/dev/hda2 ro quiet splash
initrd /boot/initrd.img-2.6.15-23-386
savedefault
boot

#(the following is the system default, but i remove it, and make it elegant)
#title Ubuntu, kernel 2.6.15-23-386 (recovery mode)
#root (hd0,1)
#kernel /boot/vmlinuz-2.6.15-23-386 root=/dev/hda2 ro single
#initrd /boot/initrd.img-2.6.15-23-386
#boot

#title Ubuntu, memtest86+
#root (hd0,1)
#kernel /boot/memtest86+.bin
#boot

### END DEBIAN AUTOMAGIC KERNELS LIST

# This is a divider, added to separate the menu items below from the Debian
# ones.
#title Other operating systems:
#root


# This entry automatically added by the Debian installer for a non-linux OS
# on /dev/hda1
title Microsoft Windows XP
root (hd0,0)
savedefault
makeactive
chainloader +1


How to install KDE in ubuntu? Just to run the command
sudo aptitude install kubuntu-desktop

how to install GNOME in Kubuntu?
sudo aptitude install ubuntu-desktop

set the default display manager revise the file
etc/X11/default-display-manager
For KDM, the file should read /usr/bin/kdm; for GDM, the file should read /usr/sbin/gdm

Purpose of this blogger

For easily look up and check my notes of solution for the problems when use linux. By the way, I am using Ubuntu(Kubuntu) currently, and it work well in my Dell latitude C610.