linux中fdisk分区方法

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

[root@localhost beinan]# fdisk /dev/sda
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) 注:扩展应用,专家功能;

通过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 for help): n 注:增加一个分区;
Command action
l logical (5 or over) 注:增加逻辑分区,分区编号要大于5;为什么要大于5,因为已经有sda5了;
p primary partition (1-4) 注:增加一个主分区;编号从 1-4 ;但sda1 和sda2都被占用,所以只能从3开始;
p
Partition number (1-4): 3
No free sectors available 注:失败中,为什么失败?

  注:我试图增加一个主分区,看来是失败了,为什么失败?因为我们看到主分区+扩展分区把整个磁盘都用光了,看扩展分区的End的值,再看一下 p输出信息中有125 cylinders;最好还是看前面部份;那里有提到;

  所以我们只能增加逻辑分区了

Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l 注:在这里输入l,就进入划分逻辑分区阶段了;
First cylinder (51-125, default 51): 注:这个就是分区的Start 值;这里最好直接按回车,如果您输入了一个非默认的数字,会造成空间浪费;
Using default value 51
Last cylinder or +size or +sizeM or +sizeK (51-125, default 125): +200M 注:这个是定义分区大小的,+200M 就是大小为200M ;当然您也可以根据p提示的单位cylinder的大小来算,然后来指定 End的数值。回头看看是怎么算的;还是用+200M这个办法来添加,这样能直观一点。如果您想添加一个10G左右大小的分区,请输入 +10000M ;
Command (m for help):

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

Command (m for help): t 注:通过t来指定分区类型;
Partition number (1-6): 6 注:要改变哪个分区类型呢?我指定了6,其实也就是sda6
Hex code (type L to list codes):L 注:在这里输入L,就可以查看分区类型的id了;
Hex code (type L to list codes): b 注:如果我想让这个分区是 W95 FAT32 类型的,通过L查看得知 b是表示的是,所以输入了b;
Changed system type of partition 6 to b (W95 FAT32) 注:系统信息,改变成功;是否是改变了,请用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 75 201568+ b W95 FAT32

  6、fdisk 的退出,用q或者 w

  其中 q是 不保存退出,w是保存退出

  Command (m for help): w
  或
  Command (m for help): q

通过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保存退出!!!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值