日期:2014-05-16  浏览次数:20640 次

linux fdisk 分区、格式化、挂载!

关于硬盘分区:主分区(包含扩展分区)、逻辑分区,主分区最多有4个(包含扩展分区)。

因此我们在对硬盘分区时最好划分主分区连续,比如说:主分区一、主分区二、扩展分区。

此文章以fdisk工具为例,对一个硬盘划分。

1、fdisk -l 查看系统上的硬盘,找到需要分区的硬盘后比如说:/dev/sdb.

然后,fdisk /dev/sdb

进入该设备。此时出现:

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) 注:扩展应用,专家功能;

具体每个参数的含义,请仔细阅读。常用的就是:d l m p q t w

2、列出当前操作硬盘的分区情况,用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????????? 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