Chinaunix首页 | 论坛 | 博客
  • 博客访问: 923567
  • 博文数量: 358
  • 博客积分: 8185
  • 博客等级: 中将
  • 技术积分: 3751
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-15 16:27
个人简介

The views and opinions expressed all for my own,only for study and test, not reflect the views of Any Company and its affiliates.

文章分类

全部博文(358)

文章存档

2012年(8)

2011年(18)

2010年(50)

2009年(218)

2008年(64)

我的朋友

分类: LINUX

2010-11-01 18:50:37

http://hi.baidu.com/gl_peixun/blog/item/a9076883b4582d99f603a611.html
Linux添加硬盘
      在为主机添加硬盘前,首先要了解Linux系统下对硬盘和分区的命名方法。   在Linux下对IDE的设备是以hd命名的,第一个ide设备是hda,第二个是hdb。依此类推   一般主板上有两个IDE接口,一共可以安装四个IDE设备。主IDE上的两个设备分别对应hda和hdb,第二个IDE口上的两个设备对应hdc和hdd。  一般硬盘安装在主IDE的主接口上,所以是hda   光驱一般安装在第二个IDE的主接口上,所以是hdc(应为hdb是用来命名主IDE上的从接口)   SCSI接口设备是用sd命名的,第一个设备是sda,第二个是sdb。依此类推   分区是用设备名称加数字命名的。例如hda1代表hda这个硬盘设备上的第一个分区。
  每个硬盘可以最多有四个主分区,作用是1-4命名硬盘的主分区。逻辑分区是从5开始的,每多一个分区,数字加以就可以。  比如一般的系统都有一个主分区用来引导系统,这个分区对应大家常说的C区,在linux下命名是hda1。后面我们分三个逻辑分区对应常说的D、E、F,在linux下命名是hda5、hda6、hda7 字串1  给硬盘分区   在slackware下有两个分区软件fdisk和cfdisk
  例如现已经有一个硬盘了,现在添加另一个硬盘到系统
  那么根据命名规则知道这个新添加的硬盘应该是hdb。可用下面命令给硬盘分区   fdisk /dev/hdb
**********************************************************************
实例解说Linux中fdisk分区使用方法
一、fdisk 的介绍  fdisk - Partition table manipulator for Linux ,译成中文的意思是磁盘分区表操作工具;本人译的不太好,也没有看中文文档;其实就是分区工具  fdsik 能划分磁盘成为若干个区,同时也能为每个分区指定分区的文件系统,比如linux 、fat32、 linux 、linux swap 、fat16 以及其实类Unix类操作系统的文件系统等;当然我们用fdisk 对磁盘操作分区时,并不是一个终点,我们还要对分区进行格式化所需要的文件系统;这样一个分区才能使用;这和DOS中的fdisk 是类似的  二、合理规划您的硬盘分区  在操作分区之前,我们要明白硬盘分区一点理论,比如硬盘容量和分区大小的计算;对一个硬盘如何规划分区等,请参考如下文档,谢谢  《合理规划您的硬盘分区》  三、fdisk -l 查看硬盘及分区信息  通过《合理规划您的硬盘分区》 ,我们知道主分区(包括扩展分区)的总个数不能超过四个;也不能把扩展分区包围在主分区之间;根据这个原则,我们划分硬盘分区就比较容易的多;也能为以后减少不必要的麻烦  1、通过fdisk -l 查看机器所挂硬盘个数及分区情况[root@localhost beinan]# fdisk -l
Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 765 6144831 7 HPFS/NTFS
/dev/hda2 766 2805 16386300 c W95 FAT32 (LBA)
/dev/hda3 2806 9729 55617030 5 Extended
/dev/hda5 2806 3825 8193118+ 83 Linux
/dev/hda6 3826 5100 10241406 83 Linux
/dev/hda7 5101 5198 787153+ 82 Linux swap / Solaris
/dev/hda8 5199 6657 11719386 83 Linux
/dev/hda9 6658 7751 8787523+ 83 Linux
/dev/hda10 7752 9729 15888253+ 83 Linux
Disk /dev/sda: 1035 MB, 1035730944 bytes
256 heads, 63 sectors/track, 125 cylinders
Units = cylinders of 16128 * 512 = 8257536 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 25 201568+ c W95 FAT32 (LBA)
/dev/sda2 26 125 806400 5 Extended
/dev/sda5 26 50 201568+ 83 Linux
/dev/sda6 51 76 200781 83 Linux  通过上面的信息,我们知道此机器中挂载两个硬盘(或移动硬盘),其中一个 是hda 另一个是sda ;如果我们想查看单个硬盘情况,可以通过 fdisk -l /dev/hda1 或者fdisk -l /dev/sda1 来操作;以fdisk -l 输出的硬盘标识为准  其中 hda有三个主分区(包括扩展分区),分别是主分区 hda1 hda2 和hda3(扩展分区) ;逻辑分区是 hda5到hda10  其中 sda 有两个主分区(包括扩展分区),分别是 hda1 和hda2 (扩展分区);逻辑分区是 sda5 hda6   硬盘总容量=主分区(包括扩展分区)总容量  扩展分区容量=逻辑分区总容量  通过上面的例子,我们可以得知 hda=hda1+hda2+hda3,其中hda3=hda5+hda6+hda7+hda8+hda9+hda10 …… ……
2、关于fdisk -l 一些数值的说明Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes  这个硬盘是80G的,有255个磁面;63个扇区;9729个磁柱;每个 cylinder(磁柱)的容量是 8225280 bytes=8225.280 K(约为)=8.225280M(约为);分区序列 引导 开始 终止 容量 分区类型ID 分区类型
Device Boot Start End Blocks Id System
/dev/hda1 * 1 765 6144831 7 HPFS/NTFS
/dev/hda2 766 2805 16386300 c W95 FAT32 (LBA)
/dev/hda3 2806 9729 55617030 5 Extended
/dev/hda5 2806 3825 8193118+ 83 Linux
/dev/hda6 3826 5100 10241406 83 Linux
/dev/hda7 5101 5198 787153+ 82 Linux swap / Solaris
/dev/hda8 5199 6657 11719386 83 Linux
/dev/hda9 6658 7751 8787523+ 83 Linux
/dev/hda10 7752 9729 15888253+ 83 Linux  说明:  硬盘分区的表示:在Linux 是通过hd*x 或 sd*x 表示的,其中 * 表示的是a、b、c …… …… x表示的数字 1、2、3 …… …… hd大多是IDE硬盘;sd大多是SCSI或移动存储;  引导(Boot):表示引导分区,在上面的例子中 hda1 是引导分区;  Start (开始):表示的一个分区从X cylinder(磁柱)开始;  End (结束):表示一个分区到 Y cylinder(磁柱)结束;  id和System 表示的是一个意思,id看起来不太直观,我们要在fdisk 一个分区时,通过指定id来确认分区类型;比如 7表示的就NTFS 分区;这个在fdisk 中要通过t功能来指定。下面的部份会提到;  Blocks(容量):这是我翻译的,其实不准确,表示的意思的确是容量的意思,其单位是K;一个分区容量的值是由下面的公式而来的;  Blocks = (相应分区End数值 - 相应分区Start数值)x 单位cylinder(磁柱)的容量  所以我们算一下 hda1的 Blocks 的大小 :  hda1 Blocks=(765-1)x8225.280=6284113.92 K = 6284.113.92M  注:换算单位以硬盘厂家提供的10进位算起,如果以操作系统二进制来算, 这个分区容量应该更少一些,得出的这个值和我们通过 fdisk -l 看到的 /dev/hda1的值是大体相当的,因为换算方法不一样,所以也不可能尽可能的精确;再加上分区时的一点损失之类,有时或大或小是存在的;  我们查看分区大小或者文件的时候,还是用十进制来计算比较直观;推算办法是 byte 向前推小数点三位就是K ,K单位的值向前推小数点三位就是M,M向前推小数点三位就是G…… …… 一般也差不了多少;这么算就行;  3、估算一个存储设备是否被完全划分  我们估算一个硬盘是否完全被划分,我们只要看 fdisk -l 输出的内容中的 cylinders(柱体) 上一个分区的End 和 下一个分区的Start是不是一个连续的数字,另外要看一下每个硬盘设备的fdisk -l 的开头部份,看一下他的 cylinders(柱体)的值;  比如hda设备,我们看到的是 9729 cylinders ;我们通过 hda的分区表可以看到上一个分区的End的值+1 就是下一个分区的Start 的值;比如 hda2的Start的值是 hda1 的End 的值+1,这证明 hda1 和hda2 中间没有空白分区,是连续的,以此类推;在 hda10,我们看到 End 的值是9729 ,而在fdisk -l头部信息中也有9729 cylinders,证明这个硬盘已经完全划分;Disk /dev/sda: 1035 MB, 1035730944 bytes
256 heads, 63 sectors/track, 125 cylinders
Units = cylinders of 16128 * 512 = 8257536 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 25 201568+ c W95 FAT32 (LBA)
/dev/sda2 26 125 806400 5 Extended
/dev/sda5 26 50 201568+ 83 Linux
/dev/sda6 51 76 200781 83 Linux  我们再看看 sda 移动储是不是被完全划分了;sda有 125个cylinders (柱体),有一个主分区和一个扩展分区构成;在扩展分区中,我们看到End的值为125,而这个移动硬盘的cylinder也是125,这能说明这个硬盘 不可能再添加任何主分区了;根据我们上面所说的 sda1 sda2 sda5 sda6 之间未有任何未划分空间,但sda6 的cylinders (柱体)的End值却是 76 ,而 sda总的cylinders (柱体)有125个,由此看来sda 在 sda6后面有未划分区域;  至于sda 有多少未划分空间,我们算一下就知道了;扩展分区总容量是 806400 K ,大约是 806.400M左右,而逻辑分区 sda5 和sda6 的大小加起来是 400M左右,所以还仍有400M左右未划分空间,并且只能划分为链逻辑分区;四、fdisk 对硬盘及分区的操作,进入fdisk 对硬盘操作阶段  我们可以对硬盘进行分区操作,前提是您把fdisk -l 弄明白了;通过fdisk -l ,我们能找出机器中所有硬盘个数及设备名称;比如上面的例子,我们会看到两个设备一个是/dev/hda ,另一个是/dev/sda ;  fdisk 操作硬盘的命令格式如下:  [root@localhost beinan]# fdisk 设备  比如我们通过 fdisk -l 得知 /dev/hda 或者 /dev/sda设备;我们如果想再添加或者删除一些分区,可以用  [root@localhost beinan]# fdisk /dev/hda  或  [root@localhost beinan]# fdisk /dev/sda  注 在以后的例子中,我们要以 /dev/sda设备为例,来讲解如何用fdisk 来操作添加、删除分区等动作;  1、fdisk 的说明;  当我们通过 fdisk 设备,进入相应设备的操作时,会发现有如下的提示;以 fdisk /dev/sda 设备为例,以下同;[root@localhost beinan]# fdisk /dev/sda
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 注:l是列出分区类型,以供我们设置相应分区的类型;
m print this menu 注:m 是列出帮助信息;
n add a new partition 注:添加一个分区;
o create a new empty DOS partition table
p print the partition table 注:p列出分区表;
q quit without saving changes 注:不保存退出;
s create a new empty Sun disklabel
t change a partition's system id 注:t 改变分区类型;
u change display/entry units
v verify the partition table
w write table to disk and exit 注:把分区表写入硬盘并退出;
x extra functionality (experts only) 注:扩展应用,专家功能;  其实我们常用的只有注有中文的,其它的功能我们不常用(呵,主要是我不会用,否则早会卖弄一下了);x扩展功能,也不是常用的;一般的情况下只要懂得 d l m p q t w 就行了;  下面以实例操作来详述,没有例子没有办法就,新手也看不懂;  2、列出当前操作硬盘的分区情况,用pCommand (m for help): p
Disk /dev/sda: 1035 MB, 1035730944 bytes
256 heads, 63 sectors/track, 125 cylinders
Units = cylinders of 16128 * 512 = 8257536 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 25 201568+ c W95 FAT32 (LBA)
/dev/sda2 26 125 806400 5 Extended
/dev/sda5 26 50 201568+ 83 Linux
/dev/sda6 51 76 200781 83 Linux  3、通过fdisk的d指令来删除一个分区Command (m for help): p 注:列出分区情况;
Disk /dev/sda: 1035 MB, 1035730944 bytes
256 heads, 63 sectors/track, 125 cylinders
Units = cylinders of 16128 * 512 = 8257536 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 25 201568+ c W95 FAT32 (LBA)
/dev/sda2 26 125 806400 5 Extended
/dev/sda5 26 50 201568+ 83 Linux
/dev/sda6 51 76 200781 83 Linux
Command (m for help): d 注:执行删除分区指定;
Partition number (1-6): 6 注:我想删除 sda6 ,就在这里输入 6 ;
Command (m for help): p 注:再查看一下硬盘分区情况,看是否删除了?
Disk /dev/sda: 1035 MB, 1035730944 bytes
256 heads, 63 sectors/track, 125 cylinders
Units = cylinders of 16128 * 512 = 8257536 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 25 201568+ c W95 FAT32 (LBA)
/dev/sda2 26 125 806400 5 Extended
/dev/sda5 26 50 201568+ 83 Linux
Command (m for help):  警告:删除分区时要小心,请看好分区的序号,如果您删除了扩展分区,扩展分区之下的逻辑分区都会删除;所以操作时一定要小心;如果知道自己操作错了,请不要惊慌,用q不保存退出;切记切记!!!!在分区操作错了之时,千万不要输入w保存退出!!!
4、通过fdisk的n指令增加一个分区Command (m for help): p
Disk /dev/sda: 1035 MB, 1035730944 bytes
256 heads, 63 sectors/track, 125 cylinders
Units = cylinders of 16128 * 512 = 8257536 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 25 201568+ c W95 FAT32 (LBA)
/dev/sda2 26 125 806400 5 Extended
/dev/sda5 26 50 201568+ 83 Linux
Command (m for help): n 注:增加一个分区;
Command action
l logical (5 or over) 注:增加逻辑分区,分区编号要大于5;为什么要大于5,因为已经有sda5了;
p primary partition (1-4) 注:增加一个主分区;编号从 1-4 ;但sda1 和sda2都被占用,所以只能从3开始;
p
Partition number (1-4): 3
No free sectors available 注:失败中,为什么失败?  注:我试图增加一个主分区,看来是失败了,为什么失败?因为我们看到主分区+扩展分区把整个磁盘都用光了,看扩展分区的End的值,再看一下 p输出信息中有125 cylinders;最好还是看前面部份;那里有提到;  所以我们只能增加逻辑分区了Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l 注:在这里输入l,就进入划分逻辑分区阶段了;
First cylinder (51-125, default 51): 注:这个就是分区的Start 值;这里最好直接按回车,如果您输入了一个非默认的数字,会造成空间浪费;
Using default value 51
Last cylinder or +size or +sizeM or +sizeK (51-125, default 125): +200M 注:这个是定义分区大小的,+200M 就是大小为200M ;当然您也可以根据p提示的单位cylinder的大小来算,然后来指定 End的数值。回头看看是怎么算的;还是用+200M这个办法来添加,这样能直观一点。如果您想添加一个10G左右大小的分区,请输入 +10000M ;
Command (m for help):  5、通过fdisk的t指令指定分区类型Command (m for help): t 注:通过t来指定分区类型;
Partition number (1-6): 6 注:要改变哪个分区类型呢?我指定了6,其实也就是sda6
Hex code (type L to list codes):L 注:在这里输入L,就可以查看分区类型的id了;
Hex code (type L to list codes): b 注:如果我想让这个分区是 W95 FAT32 类型的,通过L查看得知 b是表示的是,所以输入了b;
Changed system type of partition 6 to b (W95 FAT32) 注:系统信息,改变成功;是否是改变了,请用p查看;
Command (m for help): p
Disk /dev/sda: 1035 MB, 1035730944 bytes
256 heads, 63 sectors/track, 125 cylinders
Units = cylinders of 16128 * 512 = 8257536 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 25 201568+ c W95 FAT32 (LBA)
/dev/sda2 26 125 806400 5 Extended
/dev/sda5 26 50 201568+ 83 Linux
/dev/sda6 51 75 201568+ b W95 FAT32  6、fdisk 的退出,用q或者 w  其中 q是 不保存退出,w是保存退出  Command (m for help): w

Command (m for help): q  7、一个添加分区的例子;  本例中我们会添加两个200M的主分区,其它为扩展分区,在扩展分区中我们添加两个200M大小的逻辑分区Command (m for help): p 注:列出分区表;
Disk /dev/sda: 1035 MB, 1035730944 bytes
256 heads, 63 sectors/track, 125 cylinders
Units = cylinders of 16128 * 512 = 8257536 bytes
Device Boot Start End Blocks Id System
Command (m for help): n 注:添加分区;
Command action
e extended
p primary partition (1-4)
p 注:添加主分区;
Partition number (1-4): 1 注:添加主分区1;
First cylinder (1-125, default 1): 注:直接回车,主分区1的起始位置;默认为1,默认就好;
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-125, default 125): +200M 注:指定分区大小,用+200M来指定大小为200M
Command (m for help): n 注:添加新分区;
Command action
e extended
p primary partition (1-4)
p 注:添加主分区
Partition number (1-4): 2 注:添加主分区2;
First cylinder (26-125, default 26):
Using default value 26
Last cylinder or +size or +sizeM or +sizeK (26-125, default 125): +200M 注:指定分区大小,用+200M来指定大小为200M
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e 注:添加扩展分区;
Partition number (1-4): 3 注:指定为3 ,因为主分区已经分了两个了,这个也算主分区,从3开始;
First cylinder (51-125, default 51): 注:直接回车;
Using default value 51
Last cylinder or +size or +sizeM or +sizeK (51-125, default 125): 注:直接回车,把其余的所有空间都给扩展分区;
Using default value 125
Command (m for help): p
Disk /dev/sda: 1035 MB, 1035730944 bytes
256 heads, 63 sectors/track, 125 cylinders
Units = cylinders of 16128 * 512 = 8257536 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 25 201568+ 83 Linux
/dev/sda2 26 50 201600 83 Linux
/dev/sda3 51 125 604800 5 Extended
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l 注:添加逻辑分区;
First cylinder (51-125, default 51):
Using default value 51
Last cylinder or +size or +sizeM or +sizeK (51-125, default 125): +200M 注:添加一个大小为200M大小的分区;
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l 注:添加一个逻辑分区;
First cylinder (76-125, default 76):
Using default value 76
Last cylinder or +size or +sizeM or +sizeK (76-125, default 125): +200M 注:添加一个大小为200M大小的分区;
Command (m for help): p 列出分区表;
Disk /dev/sda: 1035 MB, 1035730944 bytes
256 heads, 63 sectors/track, 125 cylinders
Units = cylinders of 16128 * 512 = 8257536 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 25 201568+ 83 Linux
/dev/sda2 26 50 201600 83 Linux
/dev/sda3 51 125 604800 5 Extended
/dev/sda5 51 75 201568+ 83 Linux
/dev/sda6 76 100 201568+ 83 Linux  然后我们根据前面所说通过t指令来改变分区类型;  最后不要忘记w保存退出
五、对分区进行格式化,以及加载  先提示一下;用 mkfs.bfs mkfs.ext2 mkfs.jfs mkfs.msdos mkfs.vfatmkfs.cramfs mkfs.ext3 mkfs.minix mkfs.reiserfs mkfs.xfs 等命令来格式化分区,比如我想格式化 sda6为ext3文件系统,则输入;  [root@localhost beinan]# mkfs.ext3 /dev/sda6  如果我想加载 sda6到目前系统来存取文件,应该有mount 命令,但首先您得建一个挂载目录;比如 /mnt/sda6 ;[root@localhost beinan]# mkdir /mnt/sda6
[root@localhost beinan]# mount /dev/sda6 /mnt/sda6
[root@localhost beinan]# df -lh
Filesystem 容量 已用 可用 已用% 挂载点
/dev/hda8 11G 8.4G 2.0G 81% /
/dev/shm 236M 0 236M 0% /dev/shm
/dev/hda10 16G 6.9G 8.3G 46% /mnt/hda10
/dev/sda6 191M 5.6M 176M 4% /mnt/sda6  这样我们就能进入 /mnt/sda6目录,然后存取文件了***********************************************************************  
  你也可以用cfdisk来分区,命令如下  cfdisk /dev/hdb   格式化硬盘
  格式化成ext3格式 字串8  mkfs.ext3 /dev/hdb1  格式化成reiserfs的格式  mkfs.reiserfs /dev/hdb1***********************************************************************一 单机资源共享
    1 在Linux系统中共享Windows系统资源之“装载(mount)”篇
    在一部电脑机上装有Linux和Windows作业系统的用家,可能会需要在Linux中用到包括软磁碟 光碟以及Windows分区中的文档,例如当你在Windows作业系统中上网,却下载了Linux的应用软件的时候就是这样。
    1)准备知识
    在Linux系统中想要使用这些磁碟驱动器的话,要先把它们装载到系统中,装载指令mount的格式如下:
mount -t 文档系统类型 设备文档名 装载目录a 文档系统类型
一般来说就是分区格式,依作业系统的不同而不同。下面将Linux系统支持的文档系统类型择要分列如表一:
文档类型 说明
msdos MS-DOS兼容格式。可以是分区为FAT 16以及FAT 32的磁磁
vfat 分区为FAT 32的磁磁,支持长文档名
iso9660 光碟文档系统类型
ext2 Linux文档系统类型的磁碟
hpfs HPFS文档系统类型
nfs filesystem for mounting partitions from remote systems
swap Linux的交换分区
┅┅b 设备文档名
在Linux作业系统中,各个驱动器设备的命名和Windows中的A: C:的规则有很大的区别。所有的系统硬件设备都可以在/dev目录下找到对应的设备文件名。例如/dev/mouse就用来表示系统中的滑鼠。磁盘驱动器的各个不同分区所对应的设备文档名列表如下:设 备 设备文档名
第一软驱 /dev/fd0
第二软驱 /dev/fd1
第一IDE驱动器 /dev/hda
第一IDE硬碟第1分区 /dev/hda1
┅┅
第二IDE驱动器 /dev/hdb
┅┅
第一SCSI驱动器 /dev/sda
第一SCSI硬碟第1分区 /dev/sda1
┅┅
第二SCSI驱动器 /dev/sdb
┅┅    假设第一个IDE硬碟驱动器被分割成数个分区,通常,第一个分区可以肯定其设备文件名为/dev/hda1,但其它分区的设备文件名就不是可以依次类推得 到的(特别是当用家使用了诸如PTM之类的磁盘分区工具的时候)。如果你想要知道硬碟各分区所对应的设备文档名,可以在console上执行cfdisk 的指令,则各分区的设备文档名大多可以一目了然了。(一如图某)
c 装载目录
    通常我们都会在/mnt目录下面为需要装载的磁碟驱动器创建一个目录,不过这并不意味着它们不可以被装载在其它未被使用的目录中。再者,所谓装载目录,并 不是将被装载的磁碟驱动器整个复制到本地,而仅仅是在本地提供一个装载点用以联系其它需要装载的磁碟驱动器。
    Linux作业系统对字符的大小写是敏感的,但是在Windows中就不是这样。而当你装载一个Windows系统中的驱动器後,对其上的文档操作时,字 符的大小写就变得不敏感了,这意味着用家不可以试图在装载的Windows驱动器上建立这麽两个文档:ABC.TXT和abc.txt,因为在 Windows系统中,它们代表同一个文档。    2)装载实例:
    a 装载软磁碟
    首先在/mnt目录下为软磁碟创建一个目录floppy(有可能Linux系统在安装的时候已经为你做了这一步):
mkdir /mnt/floppy
接着用装载指令将软磁碟中的内容装载到这一目录中:
mount -t msdos /dev/fd0 /mnt/floppy
    此后你就可以在/mnt/floppy下完全访问到软磁碟中的内容了。当然你亦可以用vfat这一文档系统类型代替msdos以使你能正确访问到其上的长文档名字,或者是用ext2代替它以令你可以访问到Linux文档格式的软磁碟。   b 装载FAT 32格式的C盘
    在/mnt目录下为之创建一个目录winc(winc以及其它的装载目录 是笔者的假设,你可以用自己喜欢的别的合法字符去命名这些目录):
mkdir /mnt/winc
用装载指令将C盘内容装载入该目录:
mount -t vfat /dev/hda1 /mnt/winc     c 装载光碟
    在/mnt目录下为你的光碟驱动器创建一个目录cdrom(或者你的系统也为你完成了这件事):
mkdir /mnt/cdrom
    如果你的光碟驱动器安装在primary slave上,设备文件名就是/dev/hdb;如果安装在secondary master上,设备文件名就是/dev/hdc。假设你的光碟驱动器是挂在secondary master的话,可以用下面的装载指令:
mount -t iso9600 /dev/hdc /mnt/cdrom
由於Linux版本的不同,你所用的系统或者会使用这样的指令来装载光碟:
mount /dev/cdrom
或 mount /mnt/cdrom    d 卸载
    如果你已经用指令将软磁碟装载进相应目录,是不应该直接将它们从软驱中取出来的,否则可能会导致信息丢失;已经装载的光碟驱动器更是会令到面板上的弹出键暂时失效以阻止你将它们直接取出。
    在你取出它们之前,首先要确定已经没有用户对它们进行访问操作,包括没有工作窗口处在该磁碟驱动器被装载的目录。卸载指令的格式如下:
umount 卸载目录
假如用家想要卸载软磁碟,可以用如下的指令:
umount /mnt/floppy
***********************************************************************  让硬盘启动自动挂载
  去“/etc”,找到“fstab”。根据你对分区编号的了解,添内容吧。
你可以把分区挂在任何空目录下面。有内容的目录,如果你把分区挂在
那里,在你把该分区卸掉前,那个目录里的内容将一直被该分区里的内
容屏蔽。
以下是我的“fstab”:
/dev/hda9 / ext3 defaults 1 1
/dev/hda10 /usr ext3 defaults 1 1
/dev/hda6 swap swap defaults 0 0
/dev/hda17 /opt/backup ext3 defaults,ro 1 1
/dev/hda11 /opt/home ext3 defaults 1 1
/dev/hda16 /opt/prog ext3 defaults 1 1
/dev/cdrom /mnt/cdrom iso9660 noauto,owner,ro 0 0
/dev/fd0 /mnt/floppy ext3 noauto,owner 0 0
none /proc proc defaults 0 0
none /dev/pts devpts gid=5,mode=620 0 0
/dev/hda1 /opt/zzz/msw98se vfat default,ro,codepage=936,iocharset=cp936 0 0
/dev/hda12 /opt/zzz/msw2kpr vfat default,ro,codepage=936,iocharset=cp936 0 0
/dev/hda15 /opt/zzz/public vfat default,ro,codepage=936,iocharset=cp936 0 0
说明一下,“default”表示启动自动加载;“ro”表示该文件系统
挂装为只读;“vfat”是Window$/DOS 分区格式,但如果你的Window$
分区是“ntfs”就别用“vfat”;“codepage=936,iocharset=cp936”给
非红旗系统用,以图避免浏览Window$/DOS 分区中文乱码,但是似乎对
RedHat Linux 9.0 无效。对于“ext2”、“ext3”和“vfat”,不指定分
区格式,系统一般也能自动识别。
按照你自己的意志修改吧。查看硬盘分区信息可以运行 fdisk -l .查看文件系统空间占用情况 用fd命令。“df -k”,以KB为单位显示;“df -m”,以MB 为单位显示。

****************************************************************************************************************************************************************
Linux添加硬盘并分区格式化
文章分类:操作系统
一.Linux的硬盘识别

2.6 kernel以后,linux会将识别到的硬件设备,在/dev/下建立相应的设备文件.如:

sda        表示第1块SCSI硬盘.

hda        表示第1块IDE硬盘(即连接在第1个IDE接口的Master口上).

scd0        表示第1个USB光驱.

当添加了新硬盘后,在/dev目录下会有相应的设备文件产生.cciss的硬盘是个例外,它的

设备文件在/dev/cciss/目录下.一般使用”fdisk -l”命令可以列出系统中当前连接的硬盘

设备和分区信息.新硬盘没有分区信息,则只显示硬盘大小信息.

二.在linux系统中添加新硬盘

下面说明一下,在GTES 11上,添加一块10G硬盘到第一个IDE口的Slave接口上.

安装好硬盘后,开机进入Turbolinux.以root身份登录.

执行fdisk -l命令显示当前系统的硬盘设备.

[root@g11-64-1 ~]# fdisk -l
Disk /dev/hda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1          13      104391   83  Linux
/dev/hda2              14          89      610470   82  Linux swap / Solaris
/dev/hda3              90        2610    20249932+  83  Linux
Disk /dev/hdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/hdb doesn't contain a valid partition table

[root@g11-64-1 ~]#
显示hdb没有分区信息,大小为10G.

使用fdisk命令对hdb进行分区.

[root@g11-64-1 ~]# fdisk /dev/hdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.
The number of cylinders for this disk is set to 1305.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
输入: n 表示新建分区.
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
输入: p 表示建立一个原始分区.
p
Partition number (1-4): 1
输入: 1 表示此分区编号为1.
First cylinder (1-1305, default 1):

输入: 回车 表示使用默认起始柱面号.如果要分多个区的话,先盘算好要多大,再输入数字

Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1305, default 1305):
输入: 回车 表示使用默认结束柱面号.即此分区使用整个硬盘空间.
Using default value 1305
Command (m for help): w

输入: w 存盘,退出fdisk.

The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
再使用fdisk -l命令查看分区情况.

[root@g11-64-1 ~]# fdisk -l
Disk /dev/hda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1          13      104391   83  Linux
/dev/hda2              14          89      610470   82  Linux swap / Solaris
/dev/hda3              90        2610    20249932+  83  Linux
Disk /dev/hdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/hdb1               1        1305    10482381   83  Linux
显示/dev/hdb上有一个hdb1分区,为linux格式.

分区后,需要对这个分区进行格式化.
[root@g11-64-1 ~]# mkfs.ext3 /dev/hdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
1310720 inodes, 2620595 blocks
131029 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 39 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

将新建分区挂在到/mnt/hdb1上.

[root@g11-64-1 ~]# mkdir /mnt/hdb1
[root@g11-64-1 ~]# mount /dev/hdb1 /mnt/hdb1
[root@g11-64-1 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/hda3              19G  8.2G  9.7G  46% /
/dev/hda1              99M   16M   79M  17% /boot
tmpfs                 250M     0  250M   0% /dev/shm
/dev/hdb1             9.9G  151M  9.2G   2% /mnt/hdb1
[root@g11-64-1 ~]#
hdb1已挂载到/mnt/hdb1上,剩余空间为9.2G.

在此分区上创建文件.

[root@g11-64-1 ~]# cd /mnt/hdb1
[root@g11-64-1 hdb1]# ls > a
[root@g11-64-1 hdb1]# ls -hl
total 20K
-rw-r--r-- 1 root root  13 Nov  3 08:45 a
drwx------ 2 root root 16K Nov  3 08:44 lost+found
[root@g11-64-1 hdb1]#

卸载hdb1分区.

[root@g11-64-1 hdb1]# cd
[root@g11-64-1 ~]# umount /mnt/hdb1
[root@g11-64-1 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/hda3              19G  8.2G  9.7G  46% /
/dev/hda1              99M   16M   79M  17% /boot
tmpfs                 250M     0  250M   0% /dev/shm
[root@g11-64-1 ~]#


三.设置新硬盘开机自动挂载

在/etc/fstab中添加新硬盘的挂载信息.添加下面一行:

/dev/hdb1       /mnt/hdb1               ext3 defaults         1       2(如果还有一个分区就是1      3,以此类推)

这样,每次开机后,系统会自动将/dev/hdb1挂载到/mnt/hdb1上.
http://wdp107.javaeye.com/blog/690594

***************************************************************************************************************************************************************
[root@pipe dev]# ls
arpd       loop2    md19  net       ram4     tap12    tty17  tty38  tty59     vcs4
console    loop3    md2   nflog     ram5     tap13    tty18  tty39  tty6      vcs5
core       loop4    md20  null      ram6     tap14    tty19  tty4   tty60     vcs6
disk       loop5    md21  par0      ram7     tap15    tty2   tty40  tty61     vcs7
dnrtmsg    loop6    md22  parport0  ram8     tap2     tty20  tty41  tty62     vcs8
event0     loop7    md23  parport1  ram9     tap3     tty21  tty42  tty63     vcsa
fd         lp0      md24  parport2  ramdisk  tap4     tty22  tty43  tty7      vcsa1
full       lp1      md25  parport3  random   tap5     tty23  tty44  tty8      vcsa2
fwmonitor  lp2      md26  port      rawctl   tap6     tty24  tty45  tty9      vcsa3
gpmctl     lp3      md27  ppp       root     tap7     tty25  tty46  ttyS0     vcsa4
hda        MAKEDEV  md28  ptmx      route    tap8     tty26  tty47  ttyS1     vcsa5
hda1       mapper   md29  pts       route6   tap9     tty27  tty48  ttyS2     vcsa6
hda2       md0      md3   ram       rtc      tcpdiag  tty28  tty49  ttyS3     vcsa7
hda3       md1      md30  ram0      shm      tty      tty29  tty5   ttyS4     vcsa8
hdc        md10     md31  ram1      skip     tty0     tty3   tty50  ttyS5     xfrm
hw_random  md11     md4   ram10     stderr   tty1     tty30  tty51  ttyS6     XOR
initctl    md12     md5   ram11     stdin    tty10    tty31  tty52  ttyS7     zero
input      md13     md6   ram12     stdout   tty11    tty32  tty53  urandom
ip6_fw     md14     md7   ram13     systty   tty12    tty33  tty54  usersock
kmsg       md15     md8   ram14     tap0     tty13    tty34  tty55  vcs
log        md16     md9   ram15     tap1     tty14    tty35  tty56  vcs1
loop0      md17     mem   ram2      tap10    tty15    tty36  tty57  vcs2
loop1      md18     mice  ram3      tap11    tty16    tty37  tty58  vcs3
[root@pipe dev]# fdisk -l

Disk /dev/hda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1        6374    51199123+  83  Linux
/dev/hda2            6375        6896     4192965   82  Linux swap
/dev/hda3            6897       19457   100896232+  83  Linux

Disk /dev/hdc: 320.0 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
[root@pipe dev]# fdisk /dev/hdc

The number of cylinders for this disk is set to 38913.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-38913, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-38913, default 38913):
Using default value 38913

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@pipe dev]# fdisk -l

Disk /dev/hda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1        6374    51199123+  83  Linux
/dev/hda2            6375        6896     4192965   82  Linux swap
/dev/hda3            6897       19457   100896232+  83  Linux

Disk /dev/hdc: 320.0 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hdc1               1       38913   312568641   83  Linux
[root@pipe dev]# mkfs.ext3 /dev/hdc1
mke2fs 1.35 (28-Feb-2004)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
39075840 inodes, 78142160 blocks
3907108 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=79691776
2385 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616

Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 24 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@pipe dev]# cd mnt
-bash: cd: mnt: No such file or directory
[root@pipe dev]# cd /mnt
[root@pipe mnt]# ls
[root@pipe mnt]# mkdir hdc1
[root@pipe mnt]# ls
hdc1
[root@pipe mnt]# cd hdc1
[root@pipe hdc1]# pwd
/mnt/hdc1
[root@pipe hdc1]# mount /dev/hdc1 /mnt/hdc1
[root@pipe hdc1]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/hda1              49G   22G   25G  47% /
none                 1001M     0 1001M   0% /dev/shm
/dev/hda3              95G   81G  9.5G  90% /u01
/dev/hdc1             294G   97M  279G   1% /mnt/hdc1
[root@pipe hdc1]#

阅读(5637) | 评论(0) | 转发(1) |
1

上一篇:20101027

下一篇:J2ME开发环境

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