Chinaunix首页 | 论坛 | 博客
  • 博客访问: 196040
  • 博文数量: 42
  • 博客积分: 1455
  • 博客等级: 上尉
  • 技术积分: 365
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-19 10:20
文章分类

全部博文(42)

文章存档

2016年(1)

2013年(8)

2012年(7)

2011年(2)

2010年(1)

2008年(4)

2007年(13)

2006年(6)

我的朋友

分类: LINUX

2006-03-20 20:16:36

第一章:Linux的安装每次学习我碰到的第一个问题就是环境问题,我总想第一时间搭建一个学习的环境。尤其是Linux这种的企鹅动物类的确是一个需要亲历亲为才能掌握的冬冬。于是我,一个Linux新手,第一件事情就是在自己常去的技术网站和google寻找RHEL的最新的安装盘片了。(我总是喜新厌旧,总想要找到最新的版本,不过也是,最新版本应该也是最简单的版本,因为软件总是在不断进步的,越来越好用才对。)不辞辛苦,你总能找到的,我就在以下网站()找到iso盘片,下载并安装的。如果在公司使用有盗版问题的话,对于RHEL来说,CentOS是一个很好的替代品,其实就是用redhat源代码重新编译,大家可以去centos.org下载,其实是完全一样的东西,而且是free的,很棒哦。我都开始转向CentOS了,懒得去每次找RHEL的最新版本。有了安装盘片,就可以开始安装了。可以在自己的家用电脑上安装windows+linux双系统,如果在公司,我想大家最好的办法还是使用VMWare或者是Virtual PC这样的虚拟机。虽然本人觉得VMWare更好用和更健壮,不过Virtual PC没有版权问题,对于我们这种只是用于学习的人来说也是已经足够的了。我个人就在家使用vmware,在公司使用virtual pc。我以前安装过RHEL3,感觉RHEL4的安装过程更加友好了,不过在virtual pc上却给我带来很多的麻烦。我把我的安装经历和我觉得应该知晓的预备知识document在这里。一.           预备知识:        分区PC的BIOS的工作真的是很简单,做完机器自检之后,如果是从硬盘启动的,只会认定硬盘的0磁面0磁道1扇区,将之读入内存,并将控制权交给它。这个0磁面0磁道1扇区就是我们常常称为硬盘主引导扇区的MBR (Master Boot Record),我们知道一个扇区只有512个字节,还被分成了三个部分:前面部分是启动代码,叫作主引导记录,共446个字节,接着后面的是64个字节是硬盘分区表DPT (Disk Partition Table),用于存放主分区信息,MBR的最后是结束标志2字节。由于PC硬盘的最初的分区方案只允许4个主分区(Primary Partition )。实际使用中这太少了,为克服这个设计问题,人们发明了扩展分区(Extended Partition)。这个方法允许将基本分区分为若干子分区,这个基本分区被称为扩展分区,而其子分区被称为逻辑分区(Logical Partition)。硬盘是一个整体,每个主分区都有一个启动扇区。最简单的主引导记录包括一段小程序,读入分区表,检查哪个分区是活动分区(即启动分区),并读入活动分区的第一个扇区:该分区的启动扇区(MBR是整个硬盘的启动扇区)。这个启动扇区包括另一个小程序,读入这个分区(假设是可启动的)上操作系统的第一个部分,然后把控制权交给它。大家都知道在Linux中一切都是文件,包括我们的硬盘和分区!在Linux 里硬盘和分区都是设备文件,存放在/dev目录下。IDE设备是/dev/hdX,而SCSI设备是/dev/sdX,X是设备标签。IDE设备标签一般从a到d ,为什么,因为我们只有两个IDE接口,而每个IDE接口只能接最多两个硬盘。/dev/hda代表主板上主IDE插口上的主设备,/dev/hdb代表主板上主IDE插口上的从设备,/dev/hdc代表主板上从IDE插口上的主设备,/dev/hdd代表主板上从IDE插口上的从设备。我没有SCSI硬盘,所以不做过多讲述。如果我们有了一个连接在主板上主IDE插口上的主设备位置的硬盘/dev/hda ,我们开始为硬盘分区,从上面所讲,我们知道硬盘最多可以有4个主分区,而在Linux就这么约定的1-4是主分区(不管实际上有几个主分区),5-8是逻辑分区(不管它在哪个基本分区中),所以从/dev/hda1到/dev/hda4 这4个分区设备文件是为主分区预留的。扩展分区可以是从/dev/hda2到/dev/hda4中的任意一个,但逻辑分区只能是从/dev/hda5开始,而且一定是从/dev/hda5开始的。分区使用的fdisk我想大家应该都会使用吧,而且在Linux安装过程之中可以使用图形化的工具Disk Druid,很容易,使用确省选项就很好。在windows之中每个硬盘或者分区都有个盘符,好像C:, D:之类的。这一点Linux是与之大不相同的,在Linux之中一切皆文件,我们知道/dev之下的设备文件代表了这个硬盘或者分区,如果分区要能够被我们使用的话,其实最终也需要在其上建立文件系统(就是格式化啊),并最终成为一个目录。所以可能/usr和/boot是在两个不同的分区(甚至硬盘)之下的。不要认为大家都在/之下就认为在一个分区之内。我把这种目录叫做接挂点(mount point),比如/opt与/不在同一个分区之内,如果我只是把/ mount了,而没有mount /opt,我会发现虽然在/之下有一个/opt目录(怎么发现,使用ls或者dir命令嘛),但是这时候你会发现/opt这时只是一个空目录而已。所有的接挂目录都必须事先存在的,好像我们要mount一个cdrom到/mnt/cdrom,我们必须事先建立一个空的/mnt/cdrom目录。Note:e2label又是什么东西呢,我觉得就是我们给分区取的别名。比如我们把hda1分区的mount point设为了/boot,那么我们如果引用/boot的时候,其实也就是在引用hda1。这种资料应该记录在分区的super block之中。在使用fdisk等分区工具创建新的分区的时候,已经帮我们用接挂目录建立了别名。当然我们可以通过e2label命令进行更改,不过最好不要更改,因为如果在Bootloader或者其他什么脚本使用了LABEL=/之类的引用的话,会导致我们的linux的无法正常启动。有兴趣可以做个小实验,启动linux之后,在shell之中打入以下命令,使用fdisk –p /dev/hda 列出分区(不要用swap分区做实验,swap分区没有别名的),然后使用e2label /dev/hda? 逐个查看一下它的别名,找到/boot分区,我知道一般GRUB会用LABEL来引用他们,现在使用e2label /dev/hda? newlabel来更改它的别名,不要再叫/boot。好了, reboot后看看结果吧。        BootLoaderBootloader的出现也是因为原来的引导代码只是将控制交给活动分区的启动扇区,这样的代码实在太简单了,现实之中有很多更多的需要,比如我们要实现在多个系统之中选择性的启动某个系统。于是出现了更加强大的启动代码,在Linux之中常用的就是以下两个:LILO和GRUB。现在我们没有必要知道这两个Bootloader的不同之处,反正这两个都可以被安装在MBR之中(直接控制启动过程)或者安装在某个分区(需要是活动分区或者需要其他Bootloader的配合)完成启动的任务,GRUB是更新的产品,所以一定比LILO更好些。对于启动Linux的主要任务是接手控制,加载指定内核,并最终把控制交给内核。        PC的Linux启动过程我简叙我所理解的Linux的启动过程:1.BIOS读取MBR主引导扇区(LILO或者GRUB的一部分一般已经写入MBR);2.于是LILO或者GRUB被加载入内存;3.LILO或者GRUB会负责加载LINUX内核;4.内核取得控制权之后会接挂根文件系统/,启动init,一切进程的“鼻祖”,读取/etc/inittab文件;5.允许所有运行级别1指定的脚本程序;6.在运行级别1的结尾处告诉系统前进到运行级别n(/etc/inittab之中指定);允许所有运行级别n(/etc/inittab之中指定)指定的脚本程序;系统就绪;         双系统通过硬盘分区和相应的BootLoader可以使Windows和Linux在一台电脑上和平共处。虚拟机的安装1.        VMWare,我是用的VMWare workstation 52.        Virtual PC 详细安装略。三.           RHEL4的安装VMWare Workstation V5下的安装:1.        New一个virtual machine,记得选择redhat的enterprise 4。2.        将CD-ROM选择用下载的第一张CD3.        接下来power on这台virtual machine4.        基本上一切的选用default,中间切换一下CD就搞定了四.           深入BootLoader我详细讲解一下两种Linux下的Bootloader:LILO和GRUB。        Linux的启动方式基本方式有如下三种:1、        Bootloader大多数启动都是通过这种方式。Linux的Bootloader可以安装在MBR或者某个分区(第二Bootloader)。2、        LoadlinLoadlin是一个DOS命令,可以在DOS之中启动Linux。3、        软盘启动当然可以通过软盘来启动Linux,这样可以将MBR留给其他操作系统的Bootloader。MBR只是硬盘的第一个扇区,容量只有512k字节,一般来说复杂的bootloader会分2个阶段来执行。Stage 1 / Stage 2Stage 1:这一阶段必须安装在MBR或者分区的引导扇区。Stage 2:第二阶段载入bootloader的所有配置文件,好像GRUB是在/boot之下。 Bootloader除了引导系统,另外一个重要的功能是可以指向另外一个分区的引导扇区,也就是另外一个Bootloader。比如我的hda1分区安装的是windows,hda2分区内安装的是Linux的/boot,那么在MBR内的GRUB就可以实现以下几种开机方法:?        直接交给Linux的内核开机?        将控制权交给/dev/hda2的启动扇区,有可能安装的是LILO?        将控制权交给/dev/hda1的启动扇区,应该是windows的Loader但是windows的bootloader总是要写入MBR,这样就无法识别Linux的bootloader了,所以一般来说我们需要先安装windows然后再安装Linux。
 
initrd
在载入内核的过程之中,都只会mount根目录/,而且一般只以readonly的方式挂接。为了更加方便接挂驱动之类,通常会使用虚拟磁盘(Ramdisk)来辅助实现,这就是initrd和linuxrc了。initrd映像会被一起载入,Linux内核系统会设置虚拟磁盘,并使用linuxrc这个程序的功能来进行模块的加载。完成加载驱动的工作之后,initrd所建立的虚拟磁盘就会被从内存之中去除了。Initrd并非必要的,不过现在的版本好像都有initrd。Linuxrc一般要符合以下条件:
?        文件名必须是linuxrc
?        放置在initrd的最顶层目录
?        是可以被内核执行的
        LILO
如果按照之前的default安装,将会选定GRUB作为Bootloader,所以如果要使用LILO的话,需要自己安装LILO包。可以使用rpm命令安装。具体操作如下:
将安装盘4装入CD-ROM
$mount /mnt/cdrom
$cd /mnt/cdrom/RedHat/RPMS
$rpm –Uvh lilo*
记住这只是LILO软件的安装,并不代表LILO已经安装至MBR或者Linux的分区。如果要将LILO安装成真正的Bootloader,(当然Linux安装过程已经帮我们做了这些事情)跟着以下步骤:
第一步,编辑lilo的配置文件
第二步,运行lilo命令。
LILO的stage 1和stage 2的两个部分通过lilo命令都被写入了MBR或者是分区的启动扇区之中。
Notes:
Lilo命令的作用是读取LILO的配置文件(一般是/etc/lilo.conf,可在命令行指定),然后更新MBR或者分区启动扇区的引导纪录,在引导纪录之中包含了诸如内核文件,initrd文件的在硬盘位置之类的寻址资料,所以每次配置文件有变化,或者内核文件和initrd文件的任何可能移动都要重新运行lilo更新MBR或者启动扇区内的LILO引导纪录。Lilo命令和/etc/lilo.conf文件只是安装LILO的辅助工具。其实在PC启动过程之中是完全无用甚至是不可见的。
配置文件的部分参数解释:
全局参数:
boot = /dev/hda           # The boot device is /dev/had
指定LILO安装的设备,如果是硬盘/dev/had这样的没有数字在后面的,会写入硬盘的MBR,如果是分区后面带有数字比如/dev/hda1,则只会写入分区的启动扇区。
map = /boot/map           # Save the map file as /boot/map
指定map文件的位置,预设是 /boot/map
install=boot-sector
使用指定文件作为新的boot sector.预设是/boot/boot.b.
password=password
启动时候进入交互模式的访问密码。并未加密。
default=name
设定预设的启动image,如果没有设定将会按顺序的第一个。
delay=tsecs
进入default image的等待时间。1/10秒为单位,30表示3秒。
message=message-file
指定message文件。最大 65,535 bytes.
prompt
显示boot:命令行模式。
linear
生成并使用liner sector addresses寻址。
Image选项:
image=pathname
指定Linux内核文件。
label=name
为image指定一个名称。如果没有指定就是文件名(不包括路径)
alias=name
还可以再指定一个别名。
loader=chain-loader
对于非Linux系统,可以指定下一个bootloader,预设是/boot/chain.b,这个预设的chain loader会交给other选项指定的设备,或者是第一个硬盘的活动分区的启动扇区。
password=password
image的密码。
other=devicename
非Linux系统,指定该系统的安装分区。
内核Kernel选项:
其中的append, read-only, read-write, root, 和vga 也可以作为全局参数配置。
append=string
会传送给内核的参数,比如BIOS无法识别大于64M内存时可以使用 append = "mem=128M"。
initrd=filename
指定initrd的ramdisk映像文件。
noinitrd
不使用ramdisk?
root=root-device
指定root分区。
vga=mode
VGA模式设定。
read-only
启动时以readonly方式mount根,这个只是启动第二阶段的根,不是最后我们所看到的根,一般都会使用read-only方式
read-write
启动时以read write方式mount根,这个只是启动第二阶段的根,不是最后我们所看到的根

LILO配置文件示例:
1、(摘自RHCE Red Hat Certified Engineer Linux Study Guide (Exam RH302), Fourth Edition):
prompt                               
timeout=50
default=linux
boot=/dev/hda
map=/boot/map
install=/boot/boot.b
message=/boot/message
linear
image=/boot/vmlinuz-2.4.21-3
        label=linux
        initrd=/boot/initrd-2.4.21-3.img
        read-only
        append="hdc=ide-scsi root=LABEL=/"
other=/dev/hda1
        label=Win98
        table=/dev/hda
2、(摘自Linux in a Nutshell, 3rd Edition):
prompt
default=linux
boot=/dev/hda
install=/boot/boot.b
map=/boot/map
image=/boot/vmlinuz
  label=linux
  root=/dev/hda2
  read-only ## Image section: For testing a new Linux kernel image=/testvmlinuz
  label=testlinux
  root=/dev/hda2
  read-only
  optional               # Omit image if not available when map is
                            built ## Image section: For booting DOS
other=/dev/hda1
  label=dos
  loader=/boot/chain.b
  table=/dev/hda         # The current partition table ## Image section:
                              For booting Windows 95
other=/dev/hda1
  label=win95
  loader=/boot/chain.b
  table=/dev/hda
LILO的交互模式:
有必要在这里介绍一下LILO的交互模式。可以进行配置(主要是内核参数)的调试。不过交互模式不会帮你修改配置文件,调试完成后需要自己更改配置文件并重新运行lilo更新MBR或者是相应的分区。
?        如果设定了prompt , LILO总会停留在等待画面,等待用户的输入。如果你选择按CTRL+X进入text的命令行模式,你可以再指定内核参数。
?        如果没有设定prompt,当出现 "LILO"的时候,按 Control, Shift,或者 Alt,就会到 boot:的text命令行模式。
?        在boot:之下,你可以使用tab来选择image,就是之前的label名称,也可以输入。而且可以在后面增加参数。例如:boot:linux single
以下参数可以在这时传送给内核:
debug
打印所有内核消息到console。
hd=cylinders,heads,sectors
指定硬盘参数。
load_ramdisk=n
指定多少个ram disk会传送给内核。
mem=size
指定内存参数。
noinitrd
如果设定后,不会进行the two-stage的启动,而且保留在/dev/initrd的内容,于是启动后还可见。
number
指定runlevel。
ro
Mount根为readonly。
rw
Mount根为read-write。如果没有制定ro或者rw,将会用rw方式。
single
启动单用户模式。对排错很有帮助。
        GRUB
GRUB同样支持菜单和命令行两种方式来控制启动。
GRUB通过filesystem进行寻址并将内核读入内存。
GRUB启动过程:
1、        GRUB启动时会在/boot/grub/中寻找一个名字为menu.lst的配置文件
2、        如果找不到此文件则不进入菜单模式而直接进入命令行模式。
3、        找到文件后根据文件显示菜单
4、        用户选择后,根据配置文件制定的路径加载内核
5、        将控制交给Linux内核
安装到MBR或者分区:
GRUB的软件安装在这里就不做多讲了,这里讲讲如何重新安装GRUB到MBR或者某个分区。好比我一直使用LILO,现在我想换成GRUB了,需要做什么。
方法一:
$grub-install install_device
方法二:
$grub
grub>setup install_device
两种方法都可以有不同的选项。可以自行察看帮助文件。
GRUB的文件系统规范
GRUB支持FAT、FFS、minix、ext2 和 ReiserFS 分区。
GRUB之中的的一些约定与Linux的约定不尽相同,大家需要注意一下。所谓此root不是彼root,很容易搞混淆,所以我打算先说说这一点。hd还是hd的,这点没有区别,接下去就不同了。GRUB使用数字来区别硬盘,不象Linux的had-hdd的字母表示,所以在GRUB之中的对应分别是hd0-hd3,我们也可以看出在GRUB之中一切都是从0开始计数的。分区怎么表示呢,在GRUB完整的分区表示是这样的:(hd0,0)。最后一个位只是需要用Linux的分区规则减一就好了。重点是GRUB的所谓root,GRUB作为一个多系统的bootloader,并不关心启动之后的事情,所以对于GRUB的root通常就是Linux内核文件的放置位置,一般是/boot。当然如果/boot没有自己的分区,就是/了。定义了root之后在之后的配置之中所有的文件将会是相对于这个root的,比如内核是/boot/vmlinuz,而/boot又是一个独立的分区,那么在配置文件里我们应该使用kernel /vmlinuz而不是kernel /boot/vmlinuz。后者会让GRUB去寻找/boot/boot/vmlinuz的。

利用 chain loader 的方式:
Chain loader就是将控制权交给下一个bootloader。启动事也交给下一个bootloader,所以需要知道的只是下一个bootloader的分区和所在的磁盘位置,GRUB可以指定那个扇区。比如我们的windows安装在hda1,Linux安装在hda2,在MBR的GRUB的有关启动windows的设定如下:
title windows partition
   root (hd0,0)
   chainloader +1
这里root就是代表了windows所在的分区hda1,而chainloader的+1就是代表第一个扇区。
配置文件:(/boot/grub/grub.conf或者/boot/grub/menu.lst,后者是前者的链接)
全局选项
default=0
GRUB的计数都是从0开始的。
timeout=3
表示默认等待的时间,这儿是3秒钟。超过3秒,用户还没有作出选 择的话,系统将自动选择默认的操作系统。
root=device
指定GRUB的root,就是stage 2的所在分区。
splashimage=pathname
指定开机画面文件的位置

Title选项
类似LILO的image部分。
title description
为每个启动设定义一个说明
root=device
指定GRUB的root,就是stage 2的所在分区。
kernel=pathname
指定Linux内核文件。
initrd=pathname
指定initrd映像文件。
chainloader +1
指定下一个bootloader的位置。
内核Kernel选项:
同LILO,请参照LILO相应部分。
命令行的交互模式:
GRUB的命令行模式比LILO更加强大,一般用于调试配置。基本命令基本与上面一些配置选项相同:
1、grub>root (hd0,0)                #设置GRUB的root
2、grub>kernel /vmlinuz root=LABEL=/
3、grub>initrd /initrd.img
4、boot
详细命令可以参照help。
GRUB配置文件示例:
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this # file
# NOTICE: You do not have a /boot partition. This means that
# all kernel and initrd paths are relative to /, eg.
# root (hd0,0)
# kernel /boot/vmlinuz-version ro root=/dev/hda1
# initrd /boot/initrd-version.img
#boot=/dev/hda
default=0
timeout=3
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
title Red Hat Linux (2.4.18-14)
   root (hd0,0)
   kernel /boot/vmlinuz-2.4.18-14 ro root=LABEL=/
   initrd /boot/initrd-2.4.18-14.img
title Microsoft Windows XP
   map (hd0) (hd1)
   map (hd1) (hd0)
   root (hd1,0)
   chainloader (hd1,0)+1
      boot
        总结
LILO不认识filesystem,所以将相关绝对寻址存入了MBR之中,每次变动都需要运行lilo来更新启动扇区或者MBR。
GRUB可以读取filesystem内(主要是/boot下)的文件,而不必存储内核在硬盘的绝对指针,取而代之的是路径相对路径。所以更改配置文件或者更新移动内核后无需重新安装MBR或者启动扇区部分代码。
 
第二章:文件系统和RPM
我们知道在Linux之中一切皆文件,好像硬盘和分区的设备文件,各种串口并口以及USB在Linux之中都是一个文件。
根/
在Linux之中只表现单一的层次结构,所有的其他目录都是根/的子目录。
Mount和umount文件系统
硬盘要在Linux之中使用,必须要分区,然后格式化,我想这一点所有的操作系统应该都一致的。分区格式化之后就可以摆放我们自己或者系统软件的文件了。任何硬盘分区的文件系统只有mount接挂之后才可以被使用,而且是有一定先后顺序的,我们必须先mount接挂根/目录,才能接挂其它的文件系统到/的某个目录下,第一章之中我把它叫做接挂点(mount point)。所以不是因为同在/下就一定在同一分区下。如果某个目录被挂接成另外的文件系统,那么它以前的内容将不可访问,直到被接挂的文件系统被umount。除了硬盘分区之外,我们也可以mount网络文件系统,比如nfs,smb等,以及CDROM和软盘等等。
分区和文件系统类型:
我们知道windows使用的是FAT或者NTFS文件系统。而在Linux里则是ext2和ext3。我想大家知道磁盘的物理结构就是一些磁道,扇区之类了。文件系统的出现当然是为了更好的管理文件,文件系统的主要特征,我想是它的逻辑结构。FAT,NTFS或者ext2都是这样,不过大家的定义总是有一些不同,搞的大家很麻烦。以后不知哪个牛人可以创建一个让微软和其他unix厂商都信服的文件系统呢,一统江湖。
我大致说说ext2的逻辑结构:
Superblock        是分区的第一个Block,比如文件系统的大小,起始扇区地址,以及其他一些重要信息存放于此。如果损坏,整个分区将回天乏术了。
Block group        实际每个ext2分区后都会分成几个block group的,每个group之中都有自己的
superblock / group description / block bitmap / inode bitmap / inode table / data blocks
Group Description        Block group的说明信息
Block bitmap        对应所有Block的使用状况
Inode bitmap        对应所有inode的使用状况
Inode table        类似于以前我们学的文件分配表,文件的各种属性将放于此,而具体内容将放于Block区。同时在inode之中也会有文件的地址信息,从而找到文件。
Block area        sector扇区的2的n次方,是文件系统最小的读写单位。当然在合理范围内越大读写相对越快,不过对于小文件浪费空间。
要点:
1、        Superblock,block bitmap,inode bitmap就是metadata
2、        格式化ext2分区的时候决定了inode table和block area的大小,而且格式化之后再不可改变。一般为每4kb分配一个inode,每个inode的大小是128b,block size一般大小是1024/2048/4096等。
3、        Inode table的大小决定了能够存放文件的多少。
4、        Inode并不存放文件名称,文件名称和相应的inode信息存放于目录的block area之中。
               
做个总结,我们需要编辑/etc/passwd下的一个文件,Linux的基本操作应该大致是这样:
1、        根据/的block area信息找到对应的/etc目录的inode信息
2、        再用/etc的inode信息在inode table之中找到对应/etc项,找到对应的/etc的目录block area区域,找到/etc/passwd的inode信息
3、        再到inode table之中根据/etc/passwd的inode信息找到对应项,这样我们就找到了这个文件的block area地址了。
4、        根据地址读出文件
清楚了吧,其实文件系统的实现原理也基本一样,理解了FAT的文件分区表,也很好理解这个inode table的。
ext3只是ext2的加强,增加了日志功能(journaling)。当然写的时候会慢些,不过恢复的时候会快很多,而且增加了文件系统的稳定性。
Linux所支持的主要的文件系统:
?        Linux的VFS (Virtual Filesystem Switch)
Linux的内核通过这个VFS来管理和读取其他文件系统的。这样的话,其他的应用并不需要知道各种文件系统的存取模式就可以读取不同文件系统之中的文件了,因为所有这些,VFS已经为我们做了。对于软件开发商来说这的确是一件大好事。
?        传统文件系统
ext2 / minix / MS-DOS / FAT / iso9660
?        日志型文件系统
ext3 / ReiserFS / NTFS / JFS / XFS
?        网络型文件系统
NFS / SMBFS
好了,接下来说一说分区和建立文件系统:
使用fdisk建立分区:
$fdisk –l           #可以列出所有设备
$fdisk devicename    #管理指定设备的分区,device是整个硬盘
进入fdisk之后我想大有DOS的fdisk使用经验的话,很容易掌握Linux下的fdisk的使用。改变分区之后,应该要重新启动,才可对新的分区进行操作。
使用mke2fs建立文件系统:
$mke2fs devicename   #这里是分区
可以使用参数-b指定block size
可以使用参数-j创建ext3文件系统
等等…详细请察看man手册

Swap分区和swap文件
在windows95的时候我们就知道了有虚拟内存的概念,Linux世界也是一样,在Linux之中实现虚拟内存可以使用专门的分区,也可以使用swap文件来实现。
一般我们建立我们内存2倍大的swap。
swap分区:
1、        fdisk建立一个新的分区,并将其partition ID设为82。
2、        mkswap devicename   刚才的那个分区
3、        swapon devicename   来启动虚拟内存
swap文件:
1、        建立swap文件,比如dd if=/dev/zero of=/tmp/myswap bs=4k coung=16382会创建一个64k的文件/tmp/swap
2、        mkswap filename将文件变成swap格式
3、        swapon filename来启动这个文件的虚拟内存
LVM和RAID我打算以后找个篇幅专门说说,也有待我再研究。
如果希望可以建立一个可以扩充的文件系统,就必须要使用LVM的有关卷的概念,如果使用partition magic之类的工具调整分区大小,最多也不能超过该硬盘的大小。
 
接下来说说文件系统之中的具体的文件。
在Linux之中有以下的文件类型:
使用ls -l命令可以知道文件的类型,在Linux之中有以下7中文件类型:
目录                                                        d
普通文件                                                -
字符设备                                                c
块设备                                                b
本地套接口                                                s
有名管道                                                p
链接(类似windows的快捷方式)                l
文件的属性资料(存储在inode之中的)我想在用户权限的时候再详细说明。
相对路径(relative)和绝对路径(absolute):
以根目录/开头的就是绝对路径,而以其他开头的路径就是相对路径,表示相对当前路径而言,相对路径变成绝对路径会加上pwd命令返回的当前路径。
目录树:
FHS (Filesystem Hierarchy Standard)是一个规范,很多Linux厂商已经开始遵照它了。不过FHS很笼统,只规定了两级目录的规范。其一是根目录/下的主要目录以及应该摆放什么文件,比如/etc应该摆放各种配置文件,而/bin和/sbin应该摆放可执行文件等,第二级则主要针对/usr和/var做出了更深层目录的定义。以下我大致说说每个目录在Linux之中的作用。
/
根目录/,一般建议根目录下只放目录,尽量不要将文件直接放于其中。/是首先加载的文件系统。
/boot
第一章已经提到了,放置内核以及bootloader的文件。主要用于启动。
/dev
设备文件全部在这个目录,硬盘,分区,键盘,鼠标,USB,tty等等。
/bin
最小的系统操作性所需要的执行文件。
/etc
配置文件的集中营。
/home
用户的家。
/lib
C库和C编译器。
/sbin
系统管理所需要的一些命令。包括引导,修复等命令,我想是system admin bin的意思。
/tmp
临时文件目录。每次重新启动就会被系统自动删除。
/usr
次要的文件和命令。由FHS定义的第二层目录,类似windows之中的program files。
?        /usr/bin, /usr/sbin:user和系统管理员的大部分命令
?        /usr/include:c/c++等程序的header
?        /usr/lib:应用软件用到的库
?        /usr/local:用户自行安装的软件
?        /usr/share:共享文件的目录
?        /usr/share/doc:应用软件的说明文件
?        /usr/share/man:manpage
?        /usr/src:Linux的源代码
?        /usr/X11R6:X window的执行文件等
/var
由FHS定义的第二层目录。主要放些一些应用的专用数据和配置文件,比如named的/var/named就放了zone文件,当然一般log日志文件也是在这个目录。
?        /var/cache:系统的缓存
?        /var/lib:执行的运行库
?        /var/log:日志
?        /var/lock:锁
?        /var/run:进程的pid
?        /var/spool:队列的目录,包括邮件,打印和cron的schedule。
/mnt
/media
挂接点,比如CDROM通常在/mnt/cdrom
/opt
类似/usr/local,应用软件的安装点
/lost+found
系统不正常时候,无法在inode table找到的孤儿,就会放在这里,通常是fcsk命令产生,会在每个分区的最高层目录,比如/boot是单独分区的话,会有/boot/lost+found
/srv
一些服务用到的文件,比如www
/root
root的家
/proc
使虚目录,主要是内核等等信息,比如:/proc/cpuinfo, /proc/dma, /proc/interrupts, /proc/ioports, /proc/net 等。
不可单独分区的目录:
因为Linux启动时,一般只有/被挂接,所以启动所需的文件皆不可单独分区。比如/etc,/bin,/sbin,/dev,/lib等。
建议单独分区的目录:
/home, /usr, /var, /tmp,这些目录可能会因应需要不断扩展的,单独分区容易管理。
 
RPM
RPM就是Redhat Package Manager的简称。也就是用套件的方式来管理应用程序。rpm包最大的特点是已经编译成二进制程序(所以我们下载的时候一定要认清楚不同硬件平台和不同发行版本的包,不同平台的包或者不同发行版本的包应该是不兼容的),我们无需再进行配置和编译,而且包含包的相关信息,比如包的相关性。而且安装完毕后会有安装资料纪录库,记录在/var/lib/rpm目录之中。不过我觉得rpm最大的烦恼就是包的相关性的问题。
命令简介:
常附加用参数:
--nodeps       
强制安装,不检查包的相关性。当然不检查的话,风险是可能无法使用。
--nomd5       
不检查rpm之中的MD5信息。
--noscripts       
不执行rpm包治中的自动执行命令。因为rpm安装可以做一些初始化的工作,使用这个参数表示你不想系统作这些。
--replacefiles       
当出现文件已经安装的信息时候,可以强制覆盖文件。覆盖后不可复原。
--replacepkgs       
重新安装已经安装的rpm包。
--force       
也就是--replacefiles 和 --replacepkgs 同时使用。
--test       
测试套件是否可被安装,并不会真正安装

1、        安装
使用方法:
$rpm -ivh package_names
参数:
-i :install的意思
-v :察看详细安装画面
-h :进度表示
示例:
我们在第一章之中这样安装lilo包
$rpm –ivh /mnt/cdrom/RedHat/RPMS/lilo*
注意我们可以一次过安装多个包
2、        升级
使用方法:
$rpm -Uvh package_name
$rpm -Fvh package_name
参数:
-u :update的意思,如果已经安装则更新到新版本,如果没有安装就安装
-f :如果已经安装则更新到新版本,如果没有安装就不安装
-v :察看详细安装画面
-h :进度表示
示例:
我们更新lilo包
$rpm –Uvh /mnt/cdrom/RedHat/RPMS/lilo*
3、        查询
使用方法:
$rpm -q
参数:
-q  :后面跟packagename,查询包是否已安装
-qa :列出所有已经安装的包
-qi :后面跟packagename,查询包的信息
-ql :后面跟packagename,查询包内的文件列表
-qc :后面跟packagename,查询包的配置文件名称,已经安装在/etc之内的
-qd :后面跟packagename,列出与man有关的文件名
-qR :后面跟packagename,列出相关性包 (Required 的意思)
-qf :后面跟任何文件名,可以查询文件属于哪个包
示例:
查询lilo包是否已经安装
$rpm –q lilo
查询系统安装的所有包
$rpm –qa
查询lilo包的信息
$rpm –qi lilo
查询lilo包的文件列表
$rpm –ql lilo
查询lilo包的配置文件列表
$rpm –ql lilo   #lilo.conf并不包含于lilo包之内哦
查询lilo包的doc
$rpm –qd lilo
查询lilo包的相关文件
$rpm –qR lilo
查询/etc/passwd所属包
$rpm –qf /etc/passwd                  #passwd文件属于setup包
4、        反安装
使用方法:
$rpm –e packagename
参数:
-e:解除安装
示例:
      反安装lilo
$rpm –e lilo
       
5、        验证
使用方法:
$rpm -V
参数:
-V  :后跟packagename,改变过的包会被列出来
-Va :列出所有改变的文件,包括所有包
-Vp :后跟packagename,改变过的文件会被列出来
-Vf :后跟文件名,如果改变过会被列出来
显示结果说明:
S :file Size differs
M :Mode differs (includes permissions and file type)
5 :MD5 sum differs
D :Device major/minor number mis-match
L :readLink(2) path mis-match
U :User ownership differs
G :Group ownership differs
T :mTime differs
   rpm包内的文件类型:
c :config file
d :documentation
g :ghost file
l :license file
r :read me
示例:
      检查lilo之中的文件是否变化过
$rpm –V lilo
列出所有发生过变化的包
$rpm –Va
列出lilo之中的变化过的文件
$rpm –Vp lilo
列出/etc/passed是否改变过
$rpm –Vf /etc/passwd
 
第三章:基本的系统管理和用户管理
学习Linux并不是只为了能够使用Linux,而是要能够管理它,甚至控制它,前面的两章基本都是些Linux的周边知识,这一章我们进入了怎么使用和管理Linux的篇章。
系统管理篇:
一、        再谈Boot Process
从第一章可以知道大致的启动过程,这里只提及的Linux部分,而不管bootloader部分。
1、bootloader加载内核
内核是个压缩文件,程序包含一个解压程序,内核取得控制后会自行解压。
2、建立initrd虚拟磁盘并加载各种驱动程序
如果支持虚拟磁盘的内核,会根据所传递的initrd的参数建立虚拟磁盘,initrd之中包括很多可以动态加载的驱动。我们前面说过,内核会执行/initrd/linuxrc程序来进行驱动加载。
3、内核加载完毕后,执行init程序
内核加载完毕之后,/也已经被mount了。接下来init是系统第一个被执行的程序,所以它的进程号pid始终会是1,所有的其他程序进程都是由init负责产生的,所以我们说init是所有进程的“鼻祖”了。init执行后会读取/etc/inittab文件,一般这时候都只有/被挂接了,如果/etc有自己的独立的文件系统或者是分区,我想大家都知道会发生什么事了。
Linux的run-level:
0:halt                                        关机
1:single user mode                        单用户模式
2:multi-user without Network        不支持网络的多用户模式
3:full multi-user mode                完整的多用户模式
4:unused                                保留
5:X                                        x window模式
6:reboot                                重新启动
/etc/inittab之中定义了开机之后的run-level以及其他有关启动的设定,在inittab之中有一个基本的语法:
[id]:[run-levels]:[action]:[process]
[id]是一个代号,最好不要超过4个字符,超过了大部分版本的解释器不支持。
[run-levles]是运行的级别,可以指定多个级别,比如2345表示在2,3,4,5级别都执行。
[action]init的行动,有以下几种:
respawn:
表示process如果terminate结束后会被重新启动,好比mingetty,用户logout之后会重新启动一个mingetty等待用户login。
wait:
这种process只会启动一次,并且init会等待process结束。
once:
这种process只会启动一次,init不会等待process结束。
boot:
启动时运行,run-levels会被忽略
bootwait:
同boot,而且init会等待process的结束,好像/etc/rc
off:
什么也不做
ondemand:
特定的run-level执行,可能是a,b,c之类。(没有试过,不知道怎么用。)
initdefault:
启动后要进入的run-level
sysinit:
启动时运行,会在boot和bootwait的process之前运行,忽略run-levels
powerwait
电源错误时候,init会等待这个process结束
powerfail
电源错误时候运行
powerokwait
电源恢复时候运行,init会等待这个process结束
powerfailnow
电源(UPS)即将没电时执行
ctrlaltdel:
顾名思义,CTRL+ALT+DEL的处理
kbrequest:
指定的键盘热键的处理,可以在自己的keymaps之中指定热键,指定后要loadkeys一下。
[process]
要执行的程序包括脚本,如果以+开始,表示init不会为process做utmp和wtmp的工作。
以下是我电脑之中的/etc/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 have networking)
#   3 - Full multiuser mode
#   4 - unused
#   5 - X11
#   6 - reboot (Do NOT set initdefault to this)
#
# 这里使用initdefault指定系统启动后进入的run-level
id:5:initdefault:

# 这里使用sysinit来指定系统初始化的脚本,可以指定为其他脚本
# System initialization.
si::sysinit:/etc/rc.d/rc.sysinit

# 每个run-level自己的初始化脚本
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
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

# 处理powerfail事件
# 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"
# 处理powerokwait事件
# If power was restored before the shutdown kicked in, cancel it.
pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"
# 定义虚拟控制台tty,2-5都有6个text的控制台,用的是respawn,每次logout后init又会
# 产生一个新的mingetty进程
# 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
# 如果run-level = 5,定义x window控制器
# Run xdm in runlevel 5
x:5:respawn:/etc/X11/prefdm -nodaemon
 
4、init执行/etc/rc.d/rc.sysinit
在/etc/inittab之中sysinit定义的初始化脚本,可以使用不同的名称,主要做系统的初始化,大家可以打开看看自己的/etc/rc.d/rc.sysinit都作了些什么。主要有:
1〉        设置网络配置参数
读取/etc/sysconfig/network,并据此设置环境变量
在我的/etc/ sysconfig/network很简单,就是下面两个:
$cat /etc/sysconfig/network
   NETWORKING=yes
   HOSTNAME=test
2〉        接挂/proc
Init接着会接挂/proc,我们前面说过/proc是虚拟的文件系统,是我们访问内核
的一种途径。接着还会检查usb硬件,动态配置usb,挂接在/proc/usb/bus关于
usb,其实我们可以通过访问/dev下的设备文件直接访问,在/proc之中挂接的
最大好处是可以支持usb的动态配置,好像热插拔之类。
3〉        检查SELinux状态
设置SELinux,安全加强型的Linux。
4〉        提示输入I可以进入交互启动状态
这时候,会在控制台打印一句话,提示输入I可以进入交互模式启动。不过,好像选择了I,也不是马上反应的,屏幕上刷刷的还是一串串字符。
5〉        设定控制台
根据控制台的参数设置来设定控制台,好像字体之类。
6〉        初始化硬件,加载驱动

7〉        内核配置
会根据sysctl调整内核参数。
8〉        设定clock
设置clock
9〉        fsck和remount /
这时候会fsck检查/目录,如果没有错误的话,init会把readonly的/重新moount成为read
write模式。
10〉        umount虚拟内存磁盘/initrd
11〉        Quota
需要内核的支持,如果内核支持的话,这时候根据配置会设定quota
12〉        设定RAID和LVM
如果有raid和lvm这时候会设定这两样
13〉        清除/tmp
init会每次启动都将/tmp内的文件清空,所以不要把重要文件放在这个目录。
14〉        启动swap分区或者文件
15〉        将信息写入/vat/log/dmesg
最后会把屏幕上的信息写入dmesg,可以使用dmesg命令访问或者直接打开文件看。
6、init然后根据run-level执行/etc/rc.d的脚本
这是些wait的process,init会等待进程结束后才会继续其他。大部分的服务会在这个时候启动。系统支持的服务的脚本会在/etc/rc.d/init.d,这种脚本一般都支持三种参数,start,stop和restart。其他的在/etc/rc.d/rcX.d内的脚本基本都是会调用/etc/rc.d/init.d内的脚本来启动或者停止服务。另外使用chkconfig也可以配置服务。chkconfig –list可以列出这些服务和预设的启动状态。
7、init执行/etc/rc.d/rc.local脚本
init还会执行/etc/rc.d/rc.local脚本,好像dos的autoexec.bat文件。可以自己加入些命令,不过这是系统级的动作,对于整个Linux系统起作用,记住我们的Linux可是真正的多用户操作系统。如果想要用户级的初始化,请参照用户设定篇。
8、init初始化控制台,等待用户登陆
Init最后会启动mingetty的虚拟控制台,当然也可以配置其他的控制台。如果用户输入了用户名之后,mingetty就会把用户名传递给login程序,当然login会提示用户输入密码之类了,密码正确了,就会进入shell。
 
二.        单用户模式
run-level如果等于1的话,就会进入单用户模式了。一般进入单用户模式不用输入密码,所以,如果忘记root密码的话,我们可以进入单用户模式,然后用passwd来更改。
单用户模式没有网络,那些在chkconfig之中看到的服务也没有启动,进入/etc/rc.d/rc1.d,用ls命令看看里面有些什么文件:
[attach]a01[/attach]
我们会发现里面只有两个S开头的文件,其他全部是K开头的文件。S是代表start,而K代表kill。
在Bootloader之中我们有讲到传递给内核的参数有single,会进入单用户模式,那么那种单用户模式与run-level=1的单用户模式有没有什么不同么?
另外我们好可以在bootloader传递init=/bin/bash给内核,与单用户模式又有什么不同呢。
第二个问题,还好理解,就是让内核把bash当成init来启动所以init所作的事情是一件也不会做的,内核加载完毕后就会将控制交给shell了。启动信息简短了很多:
[attach]a02[/attach]
这时候所加载的/应该还只是内核所加载的/,一般我们是以readonly加载的(还记得第一章的那些参数吧),所以在这种环境下的所有文件也是readonly的。当然如果我们想更改文件内容的话,是可以remount根目录/。
先看看这时候系统都mount了些什么:
$mount
/dev/mapper/VolGroup00 on / type ext3 (rw)
None on /proc type proc (rw)
我不太明白结果第一行的(rw)是不是read write的含义,不过这时候的/的确是readonly的。
重新mount根目录/成read write:
$mount –o remount rw /
一切OK,这时候我们可以编辑我们所需要的文件了。不过记住init和shell的功能是大不相同的,这只是一个很不完整的Linux环境,很多东西都不能玩。
那么bootloader的参数single与run-level=1呢,我们假设/etc/inittab因为种种原因,就丢失了,重新启动后,init得到控制后找不到/etc/inittab,于是要求输入runlevel,可以无论你输入什么1-5,都会死机的,因为init根本不知道要做什么。
[attach]a03[/attach]
怎么办呢?
试试传递参数single给内核的方法(不会忘了吧),我们会发现虽然init找不到/etc/inittab,但是却把控制交到了shell的手上。
[attach]a04[/attach]
真的是很有趣。
 
 

三、        run-level的切换
我们知道了Linux下的各个run-level,我们也知道可以通过设定/etc/inittab的initdefault来设置机器每次启动进入的run-level。其实Linux可以直接从一个run-level到另外一个run-level而不用重新启动。这就是命令telinit了:
$telinit run-level
我们前面提到了/etc/rc.d/init.d,我们知道所有的启动初始化脚本其实都放在这个位置,而其他的每个run-level目录底下/etc/rc.d/rcX.d的S和K文件都是/etc/rc.d/init.d的链接,下面这张图是我的电脑上的/etc/rc.d/rc3.d的ls –l 的结果:
机器启动的时候,init运行run-lelve=0的S教本,再运行initdefault设置的run-level的S开头相关脚本,同样相反,系统关机的时候,会执行相关K开头的脚本。
init处理从低到高run-level时,比较两个run-level的S和K文件不同之处,按照数字递增的运行在低run-level不存在的以S开头的脚本,按照数字递减的运行在高run-level不存在的以K开头的脚本。
而处理从高到低的时候,比较两个run-level的S和K文件不同之处,按照数字递减的运行在低run-level不存在的以K开头的脚本,按照数字递增的运行在高run-level不存在的以S开头的脚本。
不会关闭两个run-level都存在的服务。
使用runlevel命令可以知道现在的run-level。
 

四、        Rescue模式
接下来我想说说rescue模式,很多时候对于我们这些新手出了问题的时候,紧急盘也许是唯一的解救方法。可以使用安装盘的第一张作为rescue盘,也可以制作软盘的应急盘,这里主要介绍安装盘第一张作为rescue盘。
假设我们系统的/etc/fstab不见了,无法进入系统,现在我们尝试使用rescue的方法解决这个问题:
首先mv /etc/fstab /etc/fstab.bak 再重新启动。这下无法进入linux了。
[attach]01.gif[/attach]
当然我们可以输入root密码进入shell进行修改,不过我们这里会用rescue的方式来进行修复。
1. 使用安装盘1进入安装界面,在画面之中输入 linux rescue 然后回车
[attach]02.gif[/attach]
可以使用linux rescue askmethod进行网络的安装,安装源会在/mnt/source。
[attach]03.gif[/attach]
2. 然后选择语言和键盘格式
[attach]04.gif[/attach]
[attach]05.gif[/attach]
3. 选择是否需要配置网络
一般在rescue模式都不需要网络,除非需要从网络安装rpm包。
选择完键盘之类会有画面选择rescue方式:
[attach]06.gif[/attach]
4. 选择是否然让系统查找硬盘上的linux 系统
[attach]07.gif[/attach]
可以选择继续,系统将会尝试寻找linux然后将它们挂接到/mnt/sysimage,如果选择read-only,系统做同样事情,然后挂接成readonly。Skip会略过这步,系统不会尝试挂接任何文件系统。
5. 硬盘上的文件系统并没有被找到
好像rescue并不识别lvm,所以并没有找到我的文件系统,rhel4缺省使用了lvm进行安装/。
[attach]08.gif[/attach]
[attach]09.gif[/attach]
6. 如果找到的话,我们知道会北挂接在/mnt/sysimage下,现在没有找到/,怎么办?我们进入到了一个shell。
详细的lvm将会在后面详细介绍,这里用简单方法找出文件系统,然后moun它:
$lvm
lvm>pvdisplay
lvm>vgdisplay
lvm>lvdisplay
[attach]10.gif[/attach]
可以看到我的两个logical volume:
/dev/VolGroup00/LogVol00和/dev/VolGroup00/LogVol01,根据它的大小我们也可以一眼就知道/dev/VolGroup00/LogVol00是我们的/。我们可以在lvm环境看到我们的lvm,是不是可以马上就mount为/mnt/sysimage呢?我尝试mount它:
$mkdir /mnt/sysimage
$mount -t ext3 /dev/VolGroup00/LogVol00 /mnt/sysimage
[attach]11.gif[/attach]
怎么提示没有文件或目录呢,/mnt/sysimage是已经创建了的啊。其实是设备文件不存在,rescue环境只是一个很简单的linux环境,并不会把我们以前创建的设备文件拷贝过来,我的/都没有mount,甚至都找到。
怎么办,看看/dev吧,看看都有些什么咚咚:
$ls /dev
[attach]12.gif[/attach]
的确是没有lvm的设备文件,甚至连cdrom都没有,我的cdrom是ide-0的,找不到hda啊。没办法了,只能是想办法创建我们需要的设备文件了,才能完成我们的mount啊。不是有MAKEDEV,makenod么,找找吧:
$whereis MAKEDEV
[attach]13.gif[/attach]
没有啊,经过一轮查找我发现(可以看看rescue的PATH变量),rescue环境的大部分命令都存在于/usr/bin下,里面有一个makedevs命令。
[attach]14.gif[/attach]

真的可以,于是我尝试创建了hda:
$makedevs /dev/hda b 3 0 0 0 s          
$mkdir /mnt/cdrom
$mount –t iso9660 /dev/hda /mnt/cdrom
真的成功了哦。那剩下来要做的是要创建lvm的设备文件,我想大家翻看详细的资料应该可以知道要创建些什么设备文件,我找到了一个简单的办法:
启动时在rc.sysinit不是会启动lvm的支持么:
我找到了这么几句:
if /sbin/lvm.static vgscan --mknodes --ignorelockingfailure > /dev/null 2>&1 ; then
action $”…..” /sbin/lvm.static vgchange –a y --ignorelockingfailure
fi
[attach]15.gif[/attach]
于是我试了一下:
$lvm
lvm>vgscan --mknodes --ignorelockingfailure 
lvm>vgchange -ay --ignorelockingfailure 
lvm>quit
$ls /dev
真的为我们创建了lvm的设备文件。
接下来就很简单了
$mkdir
$mount –t ext3 /dev/mapper/VolGroup00-LogVol00 /mnt/sysimage
[attach]16.gif[/attach]
把/etc/fstab.bak拷贝回/etc/fstab,问题解决。
如果是rescue环境下找不到的其他分区,可以以下方式处理:
$fdisk –l                  #查找已有的分区
$mkdir pathname     #创建你想挂接到的目录
$mount –t ext3 /dev/hdaX  pathname    #挂接文件系统,如果设备文件不存在,按上面的方式可以创建设备文件
6. 如果是rescue找到的文件系统,将会挂接在/mnt/sysimage下。
7. 可以直接进入/mnt/sysimage或者chroot更改出错的配置文件,如果必须重新安装rpm包的话,要chroot到我们的/,否则软件都安装到rescue的环境了,可以按照之前的方法挂接cdrom,然后重新安装,我在第二章有列出基本的rpm命令,可以参考。
8. 完成之后,可以使用exit退出chroot,再exit就退出rescue环境了,就会重新启动。
重点:
1. 如果是文件系统问题,可以直接使用fsck
2. 可以用mount来mount有配置问题或者其他问题的文件系统
3. 可以用chroot切换/到指定的文件系统。(这样可以使用指定文件系统的命令)
基本上rescue的linux更加象是一个单用户或者传递了init=/bin/bash的linux,然后我们可以mount目录,也可以chroot来修复系统,所以等同使用一个软盘版的linux进入shell之后。
 
 
 
 
 
 
点击在新窗口查看全图
CTRL+鼠标滚轮放大或缩小
 
点击在新窗口查看全图
CTRL+鼠标滚轮放大或缩小
 
点击在新窗口查看全图
CTRL+鼠标滚轮放大或缩小
 
点击在新窗口查看全图
CTRL+鼠标滚轮放大或缩小
点击在新窗口查看全图
CTRL+鼠标滚轮放大或缩小
点击在新窗口查看全图
CTRL+鼠标滚轮放大或缩小
 
点击在新窗口查看全图
CTRL+鼠标滚轮放大或缩小
 
点击在新窗口查看全图
CTRL+鼠标滚轮放大或缩小
点击在新窗口查看全图
CTRL+鼠标滚轮放大或缩小
点击在新窗口查看全图
CTRL+鼠标滚轮放大或缩小
点击在新窗口查看全图
CTRL+鼠标滚轮放大或缩小
 
点击在新窗口查看全图
CTRL+鼠标滚轮放大或缩小
感觉到有点累了,做些试验来调剂一下
RHCE的有关启动的排错题目分析
我学Linux的一个简单目标是要考过RHCE,所以我也花了些时间在RHCE的排错题的解决之上。以下只是将网络上我所见之排错题目罗列与此,用实验的方法验证并分析解决之,这次是有关启动的部分。
先是几个是摘自RHCE Study Guide Exam RH302 3rd,有点旧,不过题目蛮好的。
题目一
Debug Exercise I
     In this exercise, you'll be working without an /etc/fstab configuration file. To prepare, rename this file to something that you can remember and restore as required, such as /etc/bak.fstab. You'll also need a rescue disk. If your computer can boot directly from your CD drive, the first Red Hat Installation CD can serve this purpose. Otherwise, you'll also need a boot disk that also allows you access to the actual Red Hat Linux installation files, locally or over a network. And you'll need to know the root password for this system.
     The objective is to learn how /etc/fstab works, as well as the key configuration parameters associated with an /etc/fstab configuration line for your root (/) directory.
1.        Start Red Hat Linux. Rename your /etc/fstab configuration file. One possible name is /etc/bak.fstab.
2.        Make sure you have a boot disk that can serve as a rescue disk. If you know that your computer can boot directly from your Red Hat Linux installation CD, you're set. Otherwise, create a boot disk from the appropriate image file (boot.img, bootnet.img, or pcmcia.img).
3.        Use the reboot command to restart Linux.
4.        When you see your boot loader, probably GRUB, select your current version of Red Hat Linux.
5.        Watch the messages as they scroll across the screen. You'll probably see a message similar to:
WARNING: couldn't open /etc/fstab: No such file or directory
6.        You'll probably be taken to the single-user mode maintenance login prompt. Enter your root password at this prompt.
7.        Find your currently configured partitions with the fdisk -l command. Make a note of each partition device that is formatted to a Linux filesystem.
8.        Check the labels associated with each Linux-formatted partition. For example, if one of the partitions is /dev/hda1, run the e2label /dev/hda1 command. Make a note of the label that you see, such as /boot or /.
9.        Try restoring your /etc/fstab file from your backup. It probably won't work.
10.        Reboot your computer with a Red Hat Linux installation CD or boot disk. Type linux rescue at the boot prompt.
11.        Follow the first basic steps toward installation.
12.        Direct the installation program toward the source for the Red Hat Linux installation files, as required.
13.        When you get to the Rescue menu, select Continue and press ENTER.
14.        Since Linux still can't find your /etc/fstab file, you'll see an error message that suggests that you don't have any Linux partitions. Select OK and press ENTER to continue.
15.        You are now in rescue mode. Run the df command. You probably won't see any of your normal filesystems mounted anywhere.
16.        Try running the man fstab command. You probably won't be able to see the man page for the /etc/fstab configuration file.
17.        Create the /mnt/sysimage directory as required with the mkdir command.
18.        Back in step 8, you found the partition device associated with your root directory. Mount it on the /mnt/sysimage directory.
19.        Restore the basic workings of your directory structure with the chroot /mnt/sysimage command.
20.        Now try to rebuild /etc/fstab. Run the man fstab command. It should work now. Try to remember the settings for each of the columns in /etc/fstab. Using the fstab man page, and the information you gathered with the e2label command, try to rebuild a simple /etc/fstab file. Remember, avoid tabs and keep all configuration settings from wrapping to the next line. Create an /etc/fstab file with at least the settings for your root (/) directory.
21.        Remove the installation floppy and/or CD from their drives.
22.        Reboot your computer. If it works, congratulations. If it doesn't work, try editing /etc/fstab again.
23.        When you've had enough, restore your original /etc/fstab file from your backup. Reboot your computer to make sure everything is all right.
24.        Remember, you don't need to memorize all of the settings for /etc/fstab. However, you should recognize what works and what does not work in an /etc/fstab configuration file.
场景:
/etc/fstab丢失。
分析:
注意每个问题的出错信息,这是我们遇到问题第一能够得到的最好的线索。好比此题的: WARNING: couldn't open /etc/fstab: No such file or directory
已经很清楚的提示了/etc/fstab不存在。那么我们所要做的是要确定/etc/fstab是否存在,如果不存在就要想办法重建它。
在这个练习之中是使用rescue的环境来修复fstab,这正是之前我们练习过的方法。
解决方法:
(假定我们的Linux所在的分区都是普通的硬盘分区,如果是lvm,请参考之前的有关rescue环境的部分)
基本步骤如下:
1、        fdisk –l察看分区表,并记下
2、        使用e2label命令找到/和/boot等分区
3、        如果rescue已经为我们mount了分区,到第5步
4、        如果rescue没有找到分区,或者我们使用了skip直接到了shell状态,创建/mnt/sysimage目录后,自行mount根分区,如果设备文件不存在,使用makedevs自行创建
5、        chroot到/mnt/sysimage,这样我们可以得到很多命令,比如man之类
6、        根据fstab格式用vi自行创建fstab,最好要有/,/boot,/proc,swap,/dev/pts
7、        存盘,后sync后退回rescue环境
8、        exit退出重启动
其他方法1:
1.        启动后系统提示输入root密码可以进入shell,我们看到提示是(Repair filesystem)
2.        重新mount /成read write
$mount –o remount,rw /dev/hdaX /        #这里的hdaX是你的/分区
3.        同上自己创建/etc/fstab (fdisk -l,e2label)
其他方法2:
1.        Bootloader传递启动参数init=/bin/bash,进入shell模式
2.        重新mount /成read write
$mount –o remount,rw /dev/hdaX /        #这里的hdaX是你的/分区
3.        同上自己创建/etc/fstab
fstab本身不属于任何rpm包,即使是不同的机器因为分区的不同也许也不尽相同。无论用何种方法都要求对/etc/fstab有相当了解,当然我们也可以使用man fstab来现场察看fstab的格式。
后两种方法启动并未完成,一般来说bootloader的kernel的一般都是用ro参数的,所以记得要重新mount至rw状态
点击在新窗口查看全图
CTRL+鼠标滚轮放大或缩小

题目二
Debug Exercise II
     In this exercise, you'll be working without an /etc/inittab configuration file. To prepare, rename this file to something that you can remember and restore as required, such as /etc/bak.inittab.
     The objective is to learn the effect of a corrupt or missing /etc/inittab file.
1.        Start Red Hat Linux. Rename your /etc/inittab configuration file. One possible name is /etc/bak.inittab.
2.        Use the reboot command to restart Linux.
3.        Observe the messages as Linux tries to reboot. By default, the reboot command moves to runlevel 6.
4.        If you see a message such as No inittab file found, Linux probably hangs. At this point, you'll need to restart your computer through the physical reset button or on-off switch. Since you no longer have an /etc/inittab file, Linux can't find the processes to stop at runlevel 6.
5.        When you see your boot loader, probably GRUB, select your current version of Red Hat Linux.
6.        Watch the messages as they scroll across the screen. You'll probably see a message similar to:
INIT: No inittab file found
Enter runlevel:
7.        No matter what runlevel you enter, Linux ends up hanging. It's looking to /etc/inittab to find the scripts associated with the runlevel that you select. Since it can't find /etc/inittab, it stops with a no more processes left in this runlevel message.
8.        At this point, you'll need to reboot your computer again. But you can now restart your computer with a boot disk as in the last exercise, or try starting in single-user mode.
9.        When you see your boot loader, probably GRUB, you'll want to add a message to the kernel command line. In GRUB, enter p and type in your password if required. Then enter the a command to modify the kernel command line. You should see something like the following:
grub append> ro root=LABEL=/
10.        Type the word single at the end of this command line and press ENTER. Even though the /etc/inittab file is missing, Linux should boot you into single-user mode.
11.        Now try restoring your /etc/inittab file from the backup that you made. What happens?
12.        Remount your root directory (/) in read/write mode. For example, if your root directory is normally located on /dev/hda2, run the following command:
mount -o remount,rw /dev/hda2
13.        Try restoring your /etc/inittab file from the backup again. You should now be successful.
14.        Try the reboot command again. Linux can now find /etc/inittab and should reboot fairly normally.
场景:
/etc/inittab丢失。
分析:
这个练习我之前也做过,会提示没有找到inittab,无论输入什么run-level都会死机的。
解决方法:
还记得关于rpm命令的-qf参数么,可以查找文件所属的rpm包,当然-Vf可以知道文件发生的变化。
1.        如果有cd可以进入single模式,如果没有cd就是用rescue进入askmethod的网络方式,安装源会在/mnt/source之中
2.        尝试自行创建inittab,inittab比fstab要复杂的多,一般很少会自行创建它
3.        使用rpm –qf /etc/inittab查处所属的rpm包,是initscripts
4.        使用rpm命令重新安装initscripts,记得要使--force参数,如果是resce环境要chroot或者使--root参数指定root为/mnt/sysimage
/etc/inittab比较复杂,安装之后基本也是适用default的值,可以使用重新安装rpm包的方法重新安装,如果要修改,可以重新安装后再修改。

Debug Exercise III
     In this exercise, you'll be working with a modified /boot/grub/grub.conf configuration file. To prepare, copy and back up this file to something that you can remember and restore as required, such as /boot/grub/bak.grub.conf. If a relatively new administrator does not understand the meanings of root in the grub.conf configuration file, he may actually try to set root in the kernel configuration line to the partition associated with the /boot directory.
     The objective is to learn the effect of a corrupt /boot/grub/grub.conf file.
1.        Start Red Hat Linux. Back up your /boot/grub/grub.conf configuration file. One possible name is /boot/grub/bak.grub.conf.
2.        Edit the currently existing /boot/grub/grub.conf configuration file. Change the entry in the kernel command line for root to a different directory. If you normally have a separately mounted /boot directory, use the associated partition device such as /dev/hda1.
3.        Save your modified /boot/grub/grub.conf configuration file.
4.        Use the reboot command to restart Linux.
5.        Examine the boot messages as they scroll across your screen. If the kernel message points to the wrong partition, you'll get a message such as the following:
Kernel panic: No init found. Try passing init= option to kernel.
6.        When you see your boot loader, probably GRUB, you'll want to add a message to the kernel command line. In GRUB, enter p and type in your password if required. Then enter the a command to modify the kernel command line. You should see something like the following:
grub append> ro root=/dev/hda1
7.        Type the word single at the end of this command line and press ENTER. See what happens.
8.        You probably still have a kernel panic. Try to pass an init= option to the kernel. After resetting your computer, wait for the GRUB menu. Add init=/bin/sh to the end of the kernel command line. Try booting again.
9.        Back in the GRUB menu, edit the kernel command line again. Try editing the command to point root to different partitions and see what happens. Repeat as often as desired.
10.        Finally, back in the GRUB menu, point root to the correct partition.
11.        Try restoring your /boot/grub/grub.conf file from the backup.
12.        Try the reboot command again. Linux can now find your root partition and should reboot normally.
Debug Exercise IV
     In this exercise, you'll be practicing with Telnet. The service can be on or off by default. It may be blocked by a firewall. Service may be denied through the /etc/xinetd.d/telnet configuration file or through /etc/hosts.deny. Ideally, you'll be able to check your work through another computer on a LAN.
1.        Start Red Hat Linux. Check for the installation of the telnet package with the rpm -q telnet command. Install the telnet RPM if required.
2.        Check your configuration for a firewall with the /sbin/service iptables status command.
3.        If there are iptables rules active on your system, you may want to back them up with the /sbin/iptables-save > filename command.
4.        If you have iptables rules, flush them with the /sbin/iptables -F command.
5.        Check your /etc/hosts.allow and /etc/hosts.deny files. If there are rules related to in.telnetd or ALL services in either file, comment them out.
6.        Check the default status of Telnet with the /sbin/chkconfig --list telnet command. The response should be off or on. Use chkconfig to turn Telnet on if required.
7.        Check the /etc/xinetd.d/telnet configuration file. If there are only_from or no_access directives in this file, comment them out.
8.        Now you should be able to connect to Telnet. Try it from the local computer with the telnet localhost command. You should be able to log in with a local user name and password. Log out of Telnet.
9.        Repeat the telnet access request from a remote computer. Use the name or the IP address of the Telnet server. Log out of Telnet.
10.        On the Telnet server, add the following line to the /etc/xinetd.d/telnet configuration file:
no_access = 127.0.0.1
11.        From the computer with the Telnet server, try the telnet localhost command. What happens? Is a successful login through Telnet unexpected?
12.        Run the /sbin/service xinetd reload command. Repeat step 11. What happens now? If possible, try to use the telnet command to connect to the Telnet server from a different computer on your LAN. Can you connect?
13.        Restore the original /etc/xinetd.d/telnet configuration file and run /sbin/service xinetd reload command again.
14.        Open the /etc/hosts.deny file in a text editor. Add the following line:
in.telnetd : ALL
15.        Repeat step 11. What happens now? Try this again from another computer on your LAN.
16.        Restore the original /etc/hosts.deny file.
17.        Now try to set up a firewall to block yourself from accessing Telnet on the local computer.
18.        Add the following iptables chain to your firewall (the TCP/IP port for Telnet is 23. You can look up the port you need in /etc/services):
/sbin/iptables -A INPUT -s 127.0.0.1 -p tcp --dport 23 -j DROP
19.        Verify that your computer accepted this new rule with the iptables -L command. You should see that packets destined for Telnet are to be dropped.
20.        Repeat step 11. What happens now? Try to log in via Telnet again from another computer on your LAN.
21.        Note how the response is different when you block access through a firewall and through a file such as /etc/hosts.deny.
22.        Restore your original firewall. Flush the rule that you created with the /sbin/iptables -F command. Then restore the old rules if required with the /sbin/iptables-restore < filename command.
(6)Debug Exercise I
     In this exercise, you’ll be working without an /etc/passwd authentication file. To prepare, rename this file to something that you can remember and restore as required, such as /etc/bak.passwd. You’ll also need a rescue disk. If your computer can boot directly from your CD drive, the first Red Hat Installation CD can serve this purpose. Otherwise, you’ll also need a boot disk that also allows you access to the actual Red Hat Linux installation files, locally, or over a network. And you’ll need to know the root password for this system.
     The objective is to learn more about the authentication process.
1.        Start Red Hat Linux. Rename your /etc/passwd configuration file. One possible name is /etc/bak.passwd.
2.        Make sure you have a boot disk that can serve as a rescue disk. If you know that your computer can boot directly from your Red Hat Linux installation CD, you’re set. Otherwise, create a boot disk from the appropriate image file (boot.img, bootnet.img, or pcmcia.img).
3.        Use the reboot command to restart Linux.
4.        When you see your boot loader, probably GRUB, select your current version of Red Hat Linux.
5.        It will look like your computer boots normally.
6.        Now try to log in. Use any account that you’ve previously created on this computer. Note what happens.
WARNING: couldn't open /etc/fstab: No such file or directory
7.        Reboot your computer. Make sure the appropriate installation boot disk or CD is installed.
8.        When you see the Red Hat Linux installation options, type linux rescue at the boot prompt.
9.        Follow the first basic steps toward regular installation of Red Hat Linux.
10.        Direct the installation program toward the source for the Red Hat Linux installation files, as required.
11.        As long as you used the linux rescue command in step 8, you’ll soon see a Rescue menu. When you do, select Continue and press ENTER.
12.        Select OK and press ENTER to continue.
13.        Remember, assuming your normal directories and filesystems are detected, they are mounted on the /mnt/sysimage directory.
14.        Restore the basic workings of your directory structure with the chroot /mnt/sysimage command.
15.        Examine the /etc/passwd- file. Compare it to your original /etc/passwd file. If you followed the suggestion in step 1, you can do this with the diff /etc/passwd- /etc/bak.passwd command. If you’ve added or deleted users recently, you’ll see a difference between the two files.
16.        Copy /etc/passwd- to /etc/passwd (these are two different files). Reboot your computer again. Remember to remove your boot disk or CD before rebooting.
17.        Try logging in as root. Log out again.
18.        Try logging in as one of the regular users in your /etc/passwd- file. Note what happens.
19.        Now restore the original /etc/passwd file. If you followed the suggestion in step 1, run the mv /etc/bak.passwd /etc/passwd command.
20.        Reboot your Linux computer and repeat steps 17 and 18.
(6)Debug Exercise II
     In this exercise, you’ll be working with a modified /etc/inittab configuration file. To prepare, back up this file to something that you can remember and restore as required, such as /etc/bak.inittab.
     The objective is to learn the effect of a corrupt or erroneous /etc/inittab file.
1.        Start Red Hat Linux. Copy and back up your /etc/inittab configuration file. One possible name is /etc/bak.inittab.
2.        Run the ps aux | less command. Note the substantial number of running processes. Save this output to a file, or send it to a printer.
3.        Open your /etc/inittab file in a text editor.
4.        Change the x in the id:initdefault line to 4.
5.        Comment out the l4:4:wait:/etc/rc.d/rc 4 line in /etc/inittab. Save your changes.
6.        Use the reboot command to restart Linux.
7.        Observe the messages as Linux reboots. Note how inittab starts in runlevel 4.
8.        Log in at the text console.
9.        Run the ps aux command. Note the relatively small number of running processes.
10.        Compare the output to the process list running when you started Linux in runlevel 3.
11.        Note the processes that haven’t started. Especially if you’ve already configured network processes such as NFS or Samba, note how those daemons are not active.
12.        Restore your original /etc/inittab file. Use the backup you created in step 1 if required.
(6)Debug Exercise III
     In this exercise, you’ll be working with an erroneous /etc/fstab configuration file. To prepare, copy and back up this file to something that you can remember and restore as required, such as /etc/bak.fstab. A simple mistake in editing /etc/fstab can keep your computer from booting properly.
     You’ll want to observe the result carefully.
     The objective is to learn the effect of an improperly edited /etc/fstab file.
1.        Start Red Hat Linux. Copy and back up your /etc/fstab configuration file. One possible name is /etc/bak.fstab.
2.        Edit the /etc/fstab file. For the filesystem associated with your root (/) directory, delete ext3, the standard Linux format. Save your changes.
3.        Make sure you have a boot disk that can serve as a rescue disk. If you know that your computer can boot directly from your Red Hat Linux installation CD, you’re set. Otherwise, create a boot disk from the appropriate image file (boot.img, bootnet.img, or pcmcia.img).
4.        Use the reboot command to restart Linux.
5.        When you see your boot loader, probably GRUB, select your current version of Red Hat Linux.
6.        Watch the messages as they scroll across the screen. Note the large number of references to a “Read-only file system.” Since the root directory isn’t properly recognized, Red Hat Linux tries to compensate.
7.        The boot process will stop. The actual details depend on the other filesystems that you may have configured in /etc/fstab.
8.        Reboot your computer. When you see your boot loader, probably GRUB, you’ll want to add a message to the kernel command line. In GRUB, enter p and type in your password if required. Then enter the a command to modify the kernel command line. You should see something like the following:
grub append> ro root=/dev/hda1
9.        Type the word single at the end of this command line, and press ENTER. See what happens.
10.        You are taken to single-user mode.
11.        Now try restoring your /etc/fstab file from the backup that you made. What happens?
12.        Remount your root directory (/) in read/write mode. For example, if your root directory is normally located on /dev/hda2, run the following command:
mount -o remount,rw /dev/hda2
13.        Try restoring your /etc/fstab file from the backup again. You should now be successful.
14.        Try the reboot command again. Linux can now find the proper formats from the original /etc/fstab and should reboot fairly normally.
(6)Debug Exercise IV
     In this exercise, you’ll be practicing with an FTP server, wu-ftpd. This is also known as the Washington University FTP server, or WU-FTP. The service can be on or off by default. It may be blocked by a firewall. Service may be denied through the /etc/xinetd.d/telnet configuration file or through /etc/hosts.deny. Ideally, you’ll be able to check your work through another computer on a LAN.
1.        Start Red Hat Linux. Check for the installation of the wu-ftpd package with the rpm -q wu-ftpd command. Install the wu-ftpd RPM if required.
2.        Check your configuration for a firewall with the /sbin/service iptables status command.
3.        If there are iptables rules active on your system, you may want to back them up with the /sbin/iptables-save > filename command.
4.        If you have iptables rules, flush them with the /sbin/iptables -F command.
5.        Check your /etc/hosts.allow and /etc/hosts.deny files. If there are rules related to in.ftpd or ALL services in either file, comment them out.
6.        Check the default status of the WU-FTP server with the /sbin/chkconfig --list wu-ftpd command. The response should be off or on. Use chkconfig to turn WU-FTP on if required.
7.        Check the /etc/xinetd.d/wu-ftpd configuration file. If there are only_from or no_access directives in this file, comment them out.
8.        Now you should be able to connect to the WU-FTP server. Try it from the local computer with the ftp localhost command. You should be able to log in as “anonymous,” or with a local user name and password.
9.        See the files you access if you log in as a real user. Repeat again with an anonymous login. Once you’re finished browsing around, log out of ftp.
10.        Repeat the ftp access request from a remote computer. Use the name or the IP address of the ftp server. Log out of ftp.
11.        On the wu-ftpd server computer, add the following line to the /etc/xinetd.d/wu-ftpd configuration file:
no_access = 127.0.0.1
12.        Try the ftp localhost command. What happens? Is a successful login through ftp unexpected?
13.        Run the /sbin/service xinetd reload command. Repeat step 11. What happens now? If possible, try to use the ftp command to connect to the wu-ftpd server from a different computer on your LAN. Can you connect?
14.        Restore the original /etc/xinetd.d/wu-ftpd configuration file and run /sbin/service xinetd reload command again.
15.        Open the /etc/hosts.deny file in a text editor. Add the following line:
in.ftpd : ALL
16.        Repeat step 11. What happens now? Try this again from another computer on your LAN.
17.        Restore the original /etc/hosts.deny file.
18.        Now try to set up a firewall to block yourself from accessing the WU-FTP server on the local computer.
19.        Add the following iptables chain to your firewall (the TCP/IP port for ftp is 21. You can look up the port you need in /etc/services):
/sbin/iptables -A INPUT -s 127.0.0.1 -p tcp --dport 21 -j REJECT
20.        Verify that your computer accepted this new rule with the iptables -L command. You should see that packets destined for the WU-FTP server are to be dropped.
21.        Repeat step 12. What happens now? Try to log in via ftp again from another computer on your LAN.
22.        Note how the response is different when you block access through a firewall and through a file such as /etc/hosts.deny.
23.        Restore your original firewall. Flush the rule that you created with the /sbin/iptables -F command. Then restore the old rules if required with the /sbin/iptables-restore < filename command.
阅读(5108) | 评论(0) | 转发(1) |
0

上一篇:没有了

下一篇:linux一句话精彩问答

给主人留下些什么吧!~~