本文摘要:
本文通过对U盘的分区实例,描述了fdisk命令的用法及格式化命令。


分区示例:
将U盘分为两个区,一个为FAT格式,一个为EXT格式。

#fdisk /dev/sdb 

注意事项:
对磁盘进行分区操作之前,需要先卸载该磁盘。


『显示当前分区情况的命令』

Command (m for help): p 

『删除分区:』

Command (m for help): d 
Selected partition 1  

『修改磁盘参数:』

Command (m for help): x 

Expert command (m for help): c 
Number of cylinders (1-1048576, default 1021): 239

Expert command (m for help): h 
Number of heads (1-256, default 61): 255

Expert command (m for help): s
Number of sectors (1-63, default 62): 63 
Warning: setting sector offset for DOS compatiblity

Expert command (m for help): r 

注意事项:
修改磁盘参数操作为非必须操作,可跳过此步骤,按照默认参数。


『新建分区』
主分区1,指定分区大小为10;

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

『新建分区』
主分区2,全部可用空间

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

注意事项
1.指定分区类型(主分区/逻辑分区)和分区号;
2.指定启始扇区号(一般采用默认值);
3.指定结束扇区号(决定分区大小);


『设置分区类型』

Command (m for help): t 
Selected partition 1 
Hex code (type L to list codes): 6 
Changed system type of partition 1 to 6 (FAT16)

『激活启动分区』

Command (m for help): a 
Partition number (1-4): 1  

『保存并退出』

Command (m for help): w 

格式化命令:
1.格式化为FAT16格式

#mkfs.msdos -F 16 /dev/sdb1 -n FAT16

-F 指定FAT格式(FAT16/FAT32)
-n 指定卷标名称

2.格式化为ext3格式

#mkfs.ext3 /dev/sdb2 -L EXT3

-L 表示指定卷标名称

注意事项:

不同格式的格式化命令不同,所指定的参数也不同,具体命令具体分析。


磁盘分区(fdisk)命令说明

基本命令:

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): x
Expert command (m for help): m
Command action
   b move beginning of data in a partition
   c change number of cylinders (修改柱面信息)
   d print the raw data in the partition table
   e list extended partitions
   f fix partition order
   g create an IRIX (SGI) partition table
   h change number of heads (修改柱头信息)
   m print this menu(查看命令清单)
   p print the partition table(打印分区表)
   q quit without saving changes(不保存退出)
   r return to main menu (返回主菜单)
   s change number of sectors/track (修改磁道扇区数)
   v verify the partition table
   w write table to disk and exit(保存并退出)

无损分区软件

sudo apt-get install gparted