Running Linux 5th Edition 学习笔记 一 (chapt..
时间:2006-10-26 来源:david0927
Chapter 2 Preinstallation and Installation
目前的linux发行版感觉有很多的样子,美国人喜欢用的Red Hat,Fedora Core了,欧洲市场比较流行的Maderake了,Novel公司的suse了,还有老牌子的Debian了,还有最近我比较感兴趣的Ubuntu(很怪的名字不是嘛,去了它的网页,是个古非洲语单词,表示对他人的博爱。“humanity to others” or “i am what i am because who we all are”。有一种境界的味道,我就喜欢这样。)
至于下载的地方,推荐大家去http://download.chinaunix.net/(CU的下载频道),此外还有很多,有需要的话我以后会列举。 走回正题看书。
安装linux的一般方法书里做了个总结,还不错,下面是步骤列表:
1、Repartition your hard drive(s).(重新给硬盘分区)
2、Boot the Linux installation medium.(从安装介质CDROM/FLOPPY等引导启动)
3、Create Linux partitions. (创建linxu分区)
4、Create filesystems and swap space.(创建文件系统和交换分区)
5、Install the software on the new filesystems. (在新的文件系统上安装软件)
下面分开说明一下:
2.2.2. Repartitioning Concepts
主要是要在原有硬盘上空出空间以供linux使用。
提到的概念有: MBR(master boot record)该记录位于磁盘的第一个扇区(sector),用于记录一张分区表(partition table)。
分区的三种类别:primary、extend、logical。由于MS-DOS和WINDOWS的糟糕设计(poor design),使得分区表的大小有了限制,于是我们只能在一个磁盘上最多创建4个primary分区。其实UNIX和Linux并没有这种限制来着。extend分区相当于一个容器(container),其中用于放置多个logical分区。每个磁盘上extend分区只能有一个,logical没有限制。
2.2.3. Linux Partition Requirements
在Unix系统中(当然包括linxu),文件存储在一个叫做文件系统(filesystem)的东西上。每一个文件系统与一个特定的目录树(directory tree)相关联。例如/ 文件系统,/usr 文件系统。这里需要注意区别/usr 文件系统和位于/ 下的/usr 目录是不一样的。
在Unix系统中,每一个文件系统必须位于一个独立的分区上。 在安装Linux前,系统必须有至少一个文件系统(root),所有的linux文件都放在/ 下,这样很方便,但是也有些不好的地方,偷个懒,稍后说。
为什么要多弄几个文件系统哪?比如把/,/usr,/home等分开。
第一就是安全(safety),也是最重要的。一个文件系统坏了,其他的通常是不受损害的。
第二是能够很容易的更新系统,并且不会危及到你重要的数据。
第三是可以在多块硬盘上分开存储。
总结一下,linux需要至少一个root文件系统的分区,如果要创建多个文件系统,那么就针对每个文件系统都要创建一个分区。
此外要考虑的是是否要创建swap空间(swap space),swap space是磁盘上用于临时存放客户已经装载(load)但是没有使用的程序的空间。使用linux并不是一定要swap space,但是如果少于256M内存,建议还是创建吧。
创建swap space的方法有两个选项,一个是使用swap file(exists on one of your linux filesystem);第二个是创建一个swap partition(需要是一个独立的分区)。大部分人使用第二种方法。 一个swap file或者swap partition最多可以到2GB的容量,超过2GB(根本没有必要),就需要创建多个file或者partition。注意:这个2GB的值是基于Intel处理器的,在其他体系结构下可能会高点或者低点。
介绍一下分区的命令fdisk。
命令格式:#fdisk partition 在第一个SCSI设备上运行fdisk的方法: #fdisk /dev/sda
在第一个IDE设备上运行fdisk的方法:#fdisk /dev/hda (书中提及这个选项也是缺省的选项,但是在我的Fedora Core4上面测试,该选项不能省略)
如果要在多个磁盘驱动器上创建分区,那么就要在每一个驱动器上运行fdisk。(hda、hdb等)
# fdisk /dev/hda
Command (m for help):m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help)
以上是fdisk的运行界面以及命令列表。
n命令用来创建新分区。
q命令用来不保存操作并退出。
w命令用来保存操作后推出。
p命令用来显示硬盘当前的分区表。(建议马上抄下来^_^)
下面举例说明fdisk的用法:
第一:p命令
Command (m for help): p
Disk /dev/hda: 16 heads, 38 sectors, 683 cylinders
Units = cylinders of 608 * 512 bytes
Device Boot Begin Start End Blocks Id System
/dev/hda1 * 1 1 203 61693 6 DOS 16-bit >=32M
Command (m for help):
解释一下里面的几个概念:
head:磁头
sector:扇区
cylinder:柱面
block:块
/dev/hda1,这个表示的是位于第一个IDE设备上的第一个primary分区。
Blocks大小为61693,大约合到60MB大小(在linux系统中,1个block大小是1024bytes)。
示例里面的分区从1号柱面开始,到203号柱面结束,这块硬盘一共有683个柱面,所以该硬盘仍有480个柱面的空闲空间可供创建linux分区。
第二:n命令
创建分区时使用。这里我们创建2个primary分区(/dev/hda2和/dev/hda3)以供linux使用。
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p #创建primary分区
Partition number (1-4):2 #表示创建第二个primary分区
/dev/hda2 First cylinder (204-683):204 #输入该分区起始柱面数,在Fedora Core4里面缺省为204
Last cylinder or +size or +sizeM or +sizeK (204-683): +80M #设定分区大小,格式有3种 +数字、+数字M、+数字K。只是单位的不同,这里表示大小80M。
同样的再创造/dev/hda3
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (474-683): 474
Last cylinder or +size or +sizeM or +sizeK (474-683): +10M
最后再显示一下修改后的partition table:
Command (m for help): p
Disk /dev/hda: 16 heads, 38 sectors, 683 cylinders
Units = cylinders of 608 * 512 bytes
Device Boot Begin Start End Blocks Id System
/dev/hda1 * 1 1 203 61693 6 DOS 16-bit >=32M
/dev/hda2 204 204 473 82080 83 Linux native
/dev/hda3 474 474 507 10336 83 Linux native
很多系统还需要你使用fdisk下的t命令来将分区转换为linux swap,代码为82。使用l命令可以看到所有分区类型的代码。
最后,使用w命令将修改写入磁盘。
Command (m for help): w
#
此外。linux必须在磁盘上1023(含)以下的柱面内启动,所以必须把linxu的root分区放置在1023(含)以下的柱面范围内。高于1024的话,可能会无法启动,此时需要用Floppy或者CDROM作为介质进行引导。
fdisk对分区表进行修改后,有些版本的linux必须进行重启,新的版本的fdisk在核心(kernel)中自动更新的分区表的信息,可以不用重启。我们的意见是,重启…………(觉得挺无聊的一段话)
2.2.4. Creating Swap Space
命令格式为:mkswap -c partition
举例,将/dev/hda3转换为swap partition
#mkswap -c /dev/hda3
-c选项的作用是检查bad block。(可省略,但是强烈推荐使用)
格式化好swap partition后,需要在系统中使其生效,这个过程一般在系统重启中会自动执行,现在我们还没有安装linux,所以手工输入命令:
#swapon /dev/hda3
2.2.5. Creating the Filesystems
在使用分区安装linux之前,必须在上面先创建文件系统。
最常用的linux文件系统有:
Second Extend Filesystem(ext2fs)
Third Extend Filesystem(ext3fs)
这两个文件系统允许最多256个字符的文件名,以及32terabytes的文件系统大小(1terabyte=1000GB)。
创建ext3fs文件系统的命令:mke2fs -j -c partition
mke2fs命令可以创建ext2fs或者ext3fs两种文件系统,靠参数进行分别。
举例:#mke2fs -j -c /dev/hda2
-j 表示创建一个journalled、ext3fs的文件系统
-c 表示进行bad block check
2.2.6. Installing the Software
三种软件包的安装方式:
1、Selection by task
2、Selection of individual packages by series
3、Selection of individual packages sorted alphabetically
另外还有一种安装的设计,就是dependency tracking(依赖型跟踪),就是说选择软件包的时候系统会考虑它的依赖型,如果安装A必须要安装B,那么就会进行提示。或者安装了A就不能用B,那么也会提示。
2.2.7. Creating the Boot Floppy or Installing GRUB
Floppy:里面包含了一份配置好了去使用刚才创建的root文件系统的linux核心(which contains a Linux kernel configured to use your newly created root filesystem.)
GRUB:是一个用于修改master boot record的程序。(用于管理多个OS的启动程序)。