文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>RHCE033--硬件配置与管理1

RHCE033--硬件配置与管理1

时间:2010-10-01  来源:twenty_four

 
一、设备文件
  1. Linux沿袭Unix的风格,将所有设备认成一个文件。
设备文件分为两种
块设备文件(b)
字符设备文件(c)
  1. 设备文件一般存放在/dev目录下
[root@51cto dev]# pwd
/dev
[root@51cto dev]# ll |more       //可以查看对应的块设备和字符设备
 
二、常用的块设备文件
/dev/hd[a-t]:IDE设备
由于hda表示的是第一个IDE接口,因此had一般就是我们的primary master硬盘。
如果hda是我们的硬盘,hda[n]则表示该硬盘上的第n个分区。
[root@51cto ~]# fdisk -l  //查看分区表
/dev/sd[a-z]:SCSI设备
/dev/fd[0-7]:标准软驱
/dev/md[0-31]:软raid设备
linux支持软raid,即用多个硬盘分区来模拟raid功能。模拟出来的软raid分区,用md[n]表示。
loop[0-15]:本地回访设备
ram[0-19]:内存
 
三、常用的字符设备文件
/dev/null:无限数据接收设备
       /dev/null作为数据输出对象时(一般指在使用重定向时),所有输出给它的数据直接被丢弃。
/dev/zero:无限零资源
/dev/tty[0-31]:虚拟终端
/dev/ttyS[0-9]:串口
/dev/lp[0-3]:并口
       /dev/lp0表示第一个并口设备,一般对应我们的打印机。
/dev/console:控制台
/dev/fb[0-31]:framebuffer
 
四、设备文件的使用
用户可以通过操作设备文件来完成对设备的操作。
  1. 在第一个tty终端上显示一个‘hello’
[root@51cto ~]# echo hello > /dev/tty1
[root@51cto ~]# echo hello 1> /dev/tty1
  1. 将第一个软驱中的软盘拷入第二个软驱中的软盘
[root@51cto ~]# cp /dev/fd0 /dev/fd1
  1. 备份第一个硬盘上的mbr为/root目录下的mbr文件
[root@51cto ~]# dd if=/dev/sda of=/root/mbr bs=512 count=1     //具体参考如下dd命令
1+0 records in
1+0 records out
512 bytes (512 B) copied, 0.000148893 seconds, 3.4 MB/s
[root@51cto ~]# pwd
/root
[root@51cto ~]# ll mbr
-rw-r--r-- 1 root root 512 09-29 22:46 mbr
  1. dd
dd指令是一个功能强大的copy命令
常用参数
if=文件名:指定源文件
of=文件名:指定目标文件
bs=xxx:指定块的大小
count=n:指定复制块的数量
 
五、硬盘结构
对于每一个硬盘:
  1. 主引导记录/Master Boot Record/MBR
  2. 硬盘分区表/Standard Partition Table/SPT
          //硬盘的前512个字节(如IDE硬盘的第一个扇区)记录着硬盘的主引导记录(MBR)与
硬盘分区表(SPT)。MBR是指硬盘的前446个字节,告诉计算机如何去引导操作系统的核心。
SPT是硬盘第447字节到510字节的64个字节。其后两位则是校验码,表示之前的数据有效。
  1. 主分区/Primary Partition
  2. 扩展分区/Extended Partition
    --逻辑分区/Logical Partition
 
六、硬盘分区
一块硬盘只能有四个主分区
用户可以也只可以将一个主分区变成扩展分区
在扩展分区上,用户可以以链表方式建立逻辑分区
Red Hat Linux对一块IDE硬盘最多支持到63个分区,SCSI硬盘支持到15个。
fdisk工具最多只能辨认出16个分区。
SPT只有64个字节,每一条分区记录需要16个字节,所以一块IDE硬盘只能有四个主分区。
分别对应/dev/hda1到/dev/hda4。逻辑分区是建立在扩展分区之上,
所以第一块IDE硬盘的第一个逻辑分区,其设备文件名是/dev/hda5。
 
七、为硬盘分区、挂载文件系统
硬盘分区工具
  1. disk druid:方便的分区工具,只能在安装时使用,不作具体介绍
  2. fdisk:运用广泛的字符界面下硬盘分区工具
可以通过使用fdisk –l /dev/xx可以查询硬盘的分区状况
[root@51cto ~]# fdisk -l /dev/sda
Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1           6       48163+  83  Linux   //Linux native分区
/dev/sda2               7         515     4088542+  83  Linux     //Linux native分区
/dev/sda3             516         949     3486105   83  Linux    //Linux native分区
/dev/sda4             950        1044      763087+   5  Extended     //扩展分区
/dev/sda5             950        1044      763056   82  Linux swap / Solaris   //交换分区
  1. 下面添加一块2G的硬盘进行分区:
  1. 添加完2G的硬盘后查看分区表:
[root@51cto ~]# fdisk -l
 
Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1           6       48163+  83  Linux
/dev/sda2               7         515     4088542+  83  Linux
/dev/sda3             516         949     3486105   83  Linux
/dev/sda4             950        1044      763087+   5  Extended
/dev/sda5             950        1044      763056   82  Linux swap / Solaris
 
Disk /dev/sdb: 2147 MB, 2147483648 bytes           //看出这块硬盘还没分区使用
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
Disk /dev/sdb doesn't contain a valid partition table
  1. 通过fdisk /dev/sdb进行分区:
[root@51cto ~]# fdisk /dev/sdb
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.
 
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
 
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)
  1. 对硬盘划分一个主分区,大小为1g
同时设置开机自动挂载:
Command (m for help): n     //创建一个新分区
Command action
   e   extended
   p   primary partition (1-4)
p        //选择是主分区
Partition number (1-4): 1           //第一个分区号
First cylinder (1-261, default 1): +1g      //增加1G的大小
Last cylinder or +size or +sizeM or +sizeK (122-261, default 261):
Using default value 261
 
Command (m for help): w       //分区信息保存退出
The partition table has been altered!
 
Calling ioctl() to re-read partition table.
Syncing disks.
[root@51cto ~]# fdisk -l     //查看分区信息,到此分区设置还没生效
 
Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1           6       48163+  83  Linux
/dev/sda2               7         515     4088542+  83  Linux
/dev/sda3             516         949     3486105   83  Linux
/dev/sda4             950        1044      763087+   5  Extended
/dev/sda5             950        1044      763056   82  Linux swap / Solaris
 
Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1             122         261     1124550   83  Linux
  1. 顺便利用剩下的空间划分一个扩展分区,然后分出两个逻辑分区
[root@51cto ~]# fdisk /dev/sdb
 
Command (m for help): p     //查看分区信息,相当于fdisk -l
 
Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1             122         261     1124550   83  Linux
 
Command (m for help): n     //创建一个新分区
Command action
   e   extended
   p   primary partition (1-4)
e             //创建一个扩展分区
Partition number (1-4): 1           //提示说第一个主分区被使用了
Partition 1 is already defined.  Delete it before re-adding it.
 
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e
Partition number (1-4): 2      //第二个分区号
First cylinder (1-261, default 1):     //默认全部使用
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-121, default 121):
Using default value 121
 
Command (m for help): p   //查看分区信息
 
Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1             122         261     1124550   83  Linux
/dev/sdb2               1         121      971901    5  Extended   //扩展分区OK
 
Partition table entries are not in disk order
 
Command (m for help): n   //创建一个新分区
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
p             //创建第二个扩展分区
Partition number (1-4): 3
No free sectors available    //提示说没有空间创建了
 
Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l          //重新选择逻辑分区
First cylinder (1-121, default 1): +512m      //指定第一个逻辑分区大小
Last cylinder or +size or +sizeM or +sizeK (62-121, default 121):
Using default value 121
 
Command (m for help): p
 
Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1             122         261     1124550   83  Linux
/dev/sdb2               1         121      971901    5  Extended
/dev/sdb5              62         121      481950   83  Linux
 
Partition table entries are not in disk order
 
Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l          //创建第二个逻辑分区
First cylinder (1-121, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-61, default 61):   //默认大小
Using default value 61
 
Command (m for help): p
 
Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1             122         261     1124550   83  Linux
/dev/sdb2               1         121      971901    5  Extended
/dev/sdb5              62         121      481950   83  Linux    //逻辑分区OK
/dev/sdb6               1          61      489919+  83  Linux    //逻辑分区OK
 
Partition table entries are not in disk order
 
Command (m for help): w       //保存退出
The partition table has been altered!
 
Calling ioctl() to re-read partition table.
Syncing disks.
 
 
 
备注:由于博客文章字数的限制,该文章后半部分请访问
排行榜 更多 +
雷电觉醒安卓版

雷电觉醒安卓版

飞行射击 下载
3D幻影飞车最新版

3D幻影飞车最新版

飞行射击 下载
星河一号战队

星河一号战队

飞行射击 下载