Linux认证 > 综合辅导 > 文章内容

linux从入门到精通(21)

2016-6-21编辑:ljnbset

规划硬盘中的分区——fdisk

  fdisk [磁盘设备]

  使用此命令可进入交互操纵,您可以在下面的交互操纵里面胡作非为,但是切记离开时必须按q命令,不能按w

#找出系统中所在根目录所在磁盘,并查阅该硬盘内的相关信息
[root@localhost ~]# df / <==重点找出磁盘文件名而已 文件系统 1K-块 已用 可用 已用% 挂载点 /dev/hda2 9920624 2968604 6439952 32% / [root@localhost ~]# fdisk /dev/hda ==>进入交互操纵模式,注意这里不要写具体的数字 The number of cylinders for this disk is set to 2610. 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): m <==等待输入,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 ==>不存储,直接离开fdisk程序 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)

  常见操作有:创建主分区、创建扩展分区(将硬盘的所有剩余空间作为扩展分区)、创建逻辑分区、改变分区的系统代码、保存分区表信息、用partprobe探测硬盘分区变化

 下面举出几例做测试,离开时不保存:

 Command (m for help): p  ==>查看磁盘分区表,和终端命令模式下的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        1288    10241437+  83  Linux
/dev/hda3            1289        1925     5116702+  83  Linux
/dev/hda4            1926        2610     5502262+   5  Extended
/dev/hda5            1926        1989      514048+  82  Linux swap / Solaris

Command (m for help): d  
Partition number (1-5): 4   ==>删除第4个分区

Command (m for help): d    ==>删除第3个分区
Partition number (1-4): 3

Command (m for help): p  ==>再次显示时观察下面只显示了前两个分区,第5个没显示

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        1288    10241437+  83  Linux

Command (m for help): n  ==>创建一个分区
Command action
   e   extended
   p   primary partition (1-4)
p  ==>选择创建的分区类型为主分区
Partition number (1-4): 4 ==>选择4号做主分区
First cylinder (1289-2610, default 1289): 
Using default value 1289   ==>起始柱面若直接按enter键就是使用默认值
Last cylinder or +size or +sizeM or +sizeK (1289-2610, default 2610): +512M

Command (m for help): p  ==>再次查看分区表,发现多了一个刚从建立的分区4

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        1288    10241437+  83  Linux
/dev/hda4            1289        1351      506047+  83  Linux

Command (m for help): n  ==>再建一个分区
Command action
   e   extended
   p   primary partition (1-4)
e   ==>建立扩展分区
Selected partition 3  ==>这个是系统主动选择的分区
First cylinder (1352-2610, default 1352): 
Using default value 1352
Last cylinder or +size or +sizeM or +sizeK (1352-2610, default 2610): 
Using default value 2610

Command (m for help): p

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        1288    10241437+  83  Linux
/dev/hda3            1352        2610    10112917+   5  Extended  ==>看,刚新建的扩展分区
/dev/hda4            1289        1351      506047+  83  Linux

Partition table entries are not in disk order

Command (m for help): n  ==>再多建几个分区玩玩,反正后面不保存就行了,,呵呵
First cylinder (1352-2610, default 1352): 
Using default value 1352
Last cylinder or +size or +sizeM or +sizeK (1352-2610, default 2610): +2084
Value out of range.
Last cylinder or +size or +sizeM or +sizeK (1352-2610, default 2610): +2084M

Command (m for help): n   ==>有没有发现,最后建立2个分区的时候根本没有询问我们要建立是主分区还是扩展分区,为啥?因为分区已经超过4了,您别无选择,只能是扩展分区了。。。
First cylinder (1606-2610, default 1606): 
Using default value 1606
Last cylinder or +size or +sizeM or +sizeK (1606-2610, default 2610): 
Using default value 2610

Command (m for help): p

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        1288    10241437+  83  Linux
/dev/hda3            1352        2610    10112917+   5  Extended
/dev/hda4            1289        1351      506047+  83  Linux
/dev/hda5            1352        1605     2040223+  83  Linux  ==>这是后面又新建的2个分区
/dev/hda6            1606        2610     8072631   83  Linux

Partition table entries are not in disk order

Command (m for help): q  ==>这里一定要按q啊,因为我刚才仅仅是演示操作,还破坏性的删除了2个分区,你要是真要分区,那就要按w保存了。

[root@localhost ~]# 

  磁盘分好区后,要更新下内核,否则您使用fdisk -l 可能看不到分区后的变化,只有重启才可以。但是使用partprobe强制让内核重新找一次分区表就行了。

[root@localhost ~]# partprobe [/dev/hda ]   <==强制让内核重新找一次分区表,则可以立刻看出分区的变化

     注意:普通用户没有权限进行硬盘分区,只有root用户可以,但最好是在单用户模式下比较安全,此外,在进行分区的时候,若该硬盘某个分区正在使用当中,则很有可能系统内核会无法加载硬盘的分区表,解决的方法就是将该使用中的分区给卸载,然后再重新分区一次,重新写入分区表。

linux从入门到精通(20)

热点推荐

登录注册
触屏版电脑版网站地图