实例解说Linux中fdisk分区使用方法-zt

上一篇 / 下一篇  2011-02-10 16:45:10 / 个人分类:linux

转自:http://hi.baidu.com/zhangzhiyin88/blog/item/597e4afab87bf8859f514658.html

一、
fdisk的介绍;

 fdisk - Partition table manipulator for Linux,(磁盘分区表操作工具),其实就是linux下的分区工具;

二、fdisk 对硬盘及分区的操作,进入fdisk 对硬盘操作阶段;

我们会看到两个设备一个是/dev/sda ,另一个是/dev/sdb

fdisk 操作硬盘的命令格式如下:
# fdisk /dev/sda

 #fdisk /dev/sdb

注:在以后的例子中,我们要以 /dev/sdb设备为例,来讲解如何用fdisk 来操作添加、删除分区等动作;

1、fdisk 的说明;
当我们通过 fdisk 设备,进入相应设备的操作时,会发现有如下的提示;以 fdisk /dev/sda 设备为例,以下同;
 # fdisk /dev/sdb

Command (m for help):    // input 'm' and enter key for help
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) // 扩展应用,专家功能

 2、列出当前操作硬盘的分区情况,用p

Command (m for help):p

Disk /dev/sdb: 2032 MB, 2032664576 bytes
63 heads, 62 sectors/track, 1016 cylinders
Units = cylinders of 3906 * 512 = 1999872 bytes

Device Boot    Start     End    Blocks   Id   System
/dev/sdb1               1     500    976469   83   Linux
/dev/sdb2            501     700    390600   83   Linux
  /dev/sdb3            701    1016    617148    5   Extended


3、通过fdisk的d指令来删除一个分区

Command (m for help):d
Partition number (1-5):3 // 我想删除 sdb3,就在这里输入 3

Command (m for help):// 再查看一下硬盘分区情况,看是否删除了?

Disk /dev/sdb: 2032 MB, 2032664576 bytes    
63 heads, 62 sectors/track, 1016 cylinders
Units = cylinders of 3906 * 512 = 1999872 bytes

Device Boot    Start     End    Blocks   Id   System
/dev/sdb1                1     500    976469   83   Linux
/dev/sdb2            501     700    390600   83   Linux

Command (m for help):

警告:删除分区时要小 心,请看好分区的序号,如果您删除了扩展分区,扩展分区之下的逻辑分区都会删除;所以操作时一定要小心;如果知道自己操作错了,请不要惊 慌,用q不保存退出;切记切记!!!!在分区操作错了之时,千万不要输入w保存退出!!!

 4、通 过fdisk的n指令增加一个分区;

Command (m for help):n // input 'n' key
Command action
e   extended
p   primary partition (1-4)
 e // input 'e' key to choose extended
Partition number (1-4):// input 3 to add /dev/sdb3
First cylinder (701-1016, default 701):  // default enter
Using default value 701
Last cylinder or +size or +sizeM or +sizeK (701-1016, default 1016):  // default enter
Using default value 1016

Command (m for help):p

Disk /dev/sdb: 2032 MB, 2032664576 bytes
63 heads, 62 sectors/track, 1016 cylinders
Units = cylinders of 3906 * 512 = 1999872 bytes

Device Boot    Start       End    Blocks   Id  System
/dev/sdb1                1       500    976469   83  Linux
/dev/sdb2             501      700    390600   83  Linux
/dev/sdb3             701     1016    617148    5  Extended

Command (m for help):n
Command action
l   logical (5 or over)
p   primary partition (1-4)
// input 'l' to choose logical
First cylinder (801-1016, default 801):
Using default value 801
Last cylinder or +size or +sizeM or +sizeK (801-1016, default 1016):
Using default value 1016

Command (m for help):p

Disk /dev/sdb: 2032 MB, 2032664576 bytes
63 heads, 62 sectors/track, 1016 cylinders
Units = cylinders of 3906 * 512 = 1999872 bytes

Device Boot    Start       End    Blocks   Id  System
/dev/sdb1               1       500    976469   83  Linux
/dev/sdb2           501       700    390600   83  Linux
/dev/sdb3           701     1016    617148    5  Extended
/dev/sdb5           701       800    195269   83  Linux
/dev/sdb6           801     1016    421817   83  Linux

Command (m for help):

 5、通过fdisk的t指令指定分区类型

Command (m for help):t
Partition number (1-6):1 // choose first sector /dev/sdb1
Hex code (type L to list codes):6 // choose Linux System to Fat16 System
Changed system type of partition 1 to 6 (FAT16)

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

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

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

Command (m for help):p

Disk /dev/sdb: 2032 MB, 2032664576 bytes
63 heads, 62 sectors/track, 1016 cylinders
Units = cylinders of 3906 * 512 = 1999872 bytes

Device Boot    Start       End    Blocks   Id  System
/dev/sdb1                1       500    976469    6  FAT16
/dev/sdb2            501       700    390600    6  FAT16
/dev/sdb3            701     1016    617148    5  Extended
/dev/sdb5            701       800    195269    6  FAT16
/dev/sdb6            801     1016    421817    6  FAT16

Command (m for help):

 6、fdisk 的退出,用q或者w
Command (m for help):w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.

7、OK 大功告成。。。

TAG: fdisk Linux linux 分区

bjangle.happy的个人空间 引用 删除 bjangle.happy   /   2011-02-10 17:05:46
经典,实用!
 

评分:0

我来说两句

Open Toolbar