fdisk

  是Linux下常用的磁盘分区工具。受mbr分区表的限制,fdisk工具只能给小于2TB的磁盘划分分区。如果使用fdisk对大于2TB的磁盘进行分区,虽然可以分区,但其仅识别2TB的空间,所以磁盘容量若超过2TB,就要使用parted分区工具(后面会讲)进行分区。
fdisk [选项] [设备名] 
-l    显示所有磁盘分区的信息
[root@cs6 ~]# fdisk -l #<==查看当前系统所有磁盘的分区信息。

Disk /dev/sda: 32.2 GB, 32212254720 bytes  #<==磁盘/dev/sda的大小。
255 heads, 63 sectors/track, 3916 cylinders #<==255个虚拟磁头,63个扇区/磁道,3916 个柱面。
Units = cylinders of 16065 * 512 = 8225280 bytes #<==一个柱面大小8225280 bytes。
Sector size (logical/physical): 512 bytes / 512 bytes #<==每个扇区的字节数。
I/O size (minimum/optimal): 512 bytes / 512 bytes #<==每次读写的字节数。
Disk identifier: 0x0001038a Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 3917 30944256 8e Linux LVM Disk /dev/mapper/vg_cs6-lv_root: 28.5 GB, 28462546944 bytes
255 heads, 63 sectors/track, 3460 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000 Disk /dev/mapper/vg_cs6-lv_swap: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000 Device:分区,这里有二个分区;
Boot:启动分区,用*表示的是启动分区;
Start;表示开始的柱面:
End:表示结束的在面;
Blocks:block 块数量;
Id:分区类型Id;
System:分区类型。

在虚拟机(VMware Workstation Pro)模拟磁盘分区实战

步骤1:先在虚拟机关机状态下添加一块1GB硬盘,若是在开机状态下添加,则需要重启系统。
步骤2:重启系统后查看添加的磁盘。 
[root@cs6 ~]# fdisk -l

Disk /dev/sdb: 1073 MB, 1073741824 bytes #<==刚刚新添加的硬盘名为sdb,是第二块盘。
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
还可以直接指定特定分区查看信息。
[root@cs6 ~]# fdisk -l /dev/sdb Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

步骤3:交互式分区实践。

[root@cs6 ~]# ls /dev/sd* #<=需查看分区前设备的状态。
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb [root@cs6 ~]# fdisk /dev/sdb #<==不加参数,直接接设备名就可以分区。
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x34d8eef3.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to #<==提示使用-c关闭dos兼容模式。
sectors (command 'u'). #<==提示-u参数使用扇区为单位分区。 Command (m for help): m #<= m是帮助,需要人工输入m后回车,
Command action
a toggle a bootable flag #<==设置引导扇区。
b edit bsd disklabel #<==编辑bsd卷标。
c toggle the dos compatibility flag #<==设置dos兼容扇区。
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 #<==创建一个新的空DOS分区表,
p print the partition table #<==打印分区表。
q quit without saving changes #<==退出不保存更改
s create a new empty Sun disklabel #<==创建新的空 sun卷标。
t change a partition's system id #<==更改分区系统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): n #<==新建一个分区,需要人工输入n后回车。
Command action
e extended #<==创建扩展分区。
p primary partition (1-4) #<==创建主分区(编号1-4)。
p
Partition number (1-4): 1 #<==设置分区编号为1,需要人工输入1后回车。
First cylinder (1-130, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130): +100M
#<==设置结束柱面(130)或分区大小(+100M),因为要划分出指定大小的分区,所以常用+100M这种方法,如果分区时使用fdisk -cu /dev/sdb,则这里就会使用扇区为单位来进行分区。
Command (m for help): p Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x34d8eef3 Device Boot Start End Blocks Id System
/dev/sdb1 1 14 112423+ 83 Linux Command (m for help): n
Command action
e extended
p primary partition (1-4)
2
Invalid partition number for type `2'
Command action
e extended
p primary partition (1-4)
e
Partition number (1-4): 2
First cylinder (15-130, default 15):
Using default value 15
Last cylinder, +cylinders or +size{K,M,G} (15-130, default 130):
Using default value 130 #<==按回车键,默认设置结束柱而号130。 Command (m for help): p Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x34d8eef3 Device Boot Start End Blocks Id System
/dev/sdb1 1 14 112423+ 83 Linux
/dev/sdb2 15 130 931770 5 Extended Command (m for help): n
Command action
l logical (5 or over) #<=分了扩展分区,这里自动变为逻辑分区。
p primary partition (1-4)
p
Partition number (1-4): 3
No free sectors available #<==不能再创建主分区,没有磁盘空间了。
#<==再新建一个分区。
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (15-130, default 15): #<=按回车键,开始柱面号为15。
Using default value 15
Last cylinder, +cylinders or +size{K,M,G} (15-130, default 130): +400M
#<==设置分区大小为400MB
Command (m for help): p Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x34d8eef3 Device Boot Start End Blocks Id System
/dev/sdb1 1 14 112423+ 83 Linux
/dev/sdb2 15 130 931770 5 Extended
/dev/sdb5 15 66 417658+ 83 Linux Command (m for help): n #<==新建一个分区。
Command action
l logical (5 or over)
p primary partition (1-4)
l #<==再新建一个逻辑分区。
First cylinder (67-130, default 67):
Using default value 67
Last cylinder, +cylinders or +size{K,M,G} (67-130, default 130):
Using default value 130 Command (m for help): p #<==打印分区表。 Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x34d8eef3 Device Boot Start End Blocks Id System
/dev/sdb1 1 14 112423+ 83 Linux
/dev/sdb2 15 130 931770 5 Extended
/dev/sdb5 15 66 417658+ 83 Linux
/dev/sdb6 67 130 514048+ 83 Linux Command (m for help): w #<==将操作写入分区表生效并退出程序。
The partition table has been altered! Calling ioctl() to re-read partition table.
Syncing disks.
[root@cs6 ~]# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb /dev/sdb1 /dev/sdb2 /dev/sdb5 /dev/sdb6
[root@cs6 ~]#
[root@cs6 ~]# yum -y install parted
[root@cs6 ~]# partprobe /dev/sdb #<==执行该命令通知内核分区表已更改,此步是不重启让分区表生效的命令。
步骤4:格式化磁盘。
[root@cs6 ~]# mkfs.ext4 /dev/sdb1    #<==只有格式化后的磁盘才能挂载到系统中使用,后面将会详细讲解mkfs.ext4命令。
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=1024 (log=0)
分块大小=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
28112 inodes, 112420 blocks
5621 blocks (5.00%) reserved for the super user
第一个数据块=1
Maximum filesystem blocks=67371008
14 block groups
8192 blocks per group, 8192 fragments per group
2008 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729 正在写入inode表: 完成
Creating journal (4096 blocks): 完成
Writing superblocks and filesystem accounting information: 完成 This filesystem will be automatically checked every 20 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override. [root@cs6 ~]# tune2fs -c -1 /dev/sdb1 #<=执行这个命令可以避免磁盘挂载自动检查磁盘,后面将会讲解tune2fs命令。
tune2fs 1.41.12 (17-May-2010)
Setting maximal mount count to -1

步骤5:挂载磁盘分区。

[root@cs6 ~]# vi /etc/fstab    #<==最后一行加入,要开机自动挂载磁盘就要加入/etc/fstab或将上面的mount命令放入/etc/rc.local中。

/dev/sdb1              /mnt                     ext4       defaults     0  0

[root@cs6 ~]# vi /etc/rc.local    #<==或者编辑/etc/rc.local,最后一行加入,两种方法二选一。
mount /dev/sdb1 /mnt

步骤6:其他事项。

    用交互指令d删除分区时要小心,看好分区的序号,如果删除了扩展分区,那么扩展分区之下的逻辑分区都会删除,所以操作时一定要小心。如果不小心操作错了,直接使用交互指令q不保存退出,这样先前的操作就会无效。如果输入w(保存指令)则会保存所有修改。
[root@cs6 ~]# fdisk /dev/sdb

Command (m for help): d
Partition number (1-6): 2 Command (m for help): p Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x34d8eef3 Device Boot Start End Blocks Id System
/dev/sdb1 1 14 112423+ 83 Linux

fdsik 非交互式分区(批量分区案例)

 
 
以下是实现非交互式分区的代码。
fdisk /dev/sdb <<EOF    #<==也可以将下面的内容写入文本文件,然后读文本执行。
n
P
1

+100M
n
e
2

n
l
+400
n
l

p
w
EOF
 
 
 
 
-

8.1 fdisk:磁盘分区工具的更多相关文章

  1. 浅谈Linux下傻瓜式磁盘分区工具cfdisk的使用

    对于新手来说,Linux环境下的磁盘分区可能还会存在一些困难.对于熟悉Linux的朋友来说,我们还有fdisk.parted(2TB以上的磁盘分区使用)等磁盘分区工具可以使用.在我们新增磁盘或者在原来 ...

  2. (转)centos7.4 fdisk磁盘分区 格式化 挂载

    centos7.4 fdisk磁盘分区 格式化 挂载 原文:http://blog.csdn.net/capecape/article/details/78499351 1.查看系统中有多少可以识别的 ...

  3. fdisk 磁盘分区命令

    fdisk fdisk磁盘分区命令 -v    打印 fdisk 的版本信息并退出.-l    列出指定设备的分区表信息并退出. 如果没有给出设备,那么使用那些在 /proc/partitions ( ...

  4. linux 大容量磁盘分区工具parted

    1. Msdos和Gpt的区别 fdisk  :只能分msdos分区parted :可以分msdos和gpt分区 2. MSDOS特点最大支持2TB卷大小.每个磁盘最多只能有4个主分区(或3个主分区, ...

  5. Linux下的两种磁盘分区工具的使用

    如何使用fdisk和parted分区工具来进行硬盘分区,下面我来说一下在Linux系统中这两种硬盘分区工具的使用方法:     ----------fdisk分区工具----------       ...

  6. Linux磁盘分区工具的使用

    ----------fdisk分区工具----------   一..下面来介绍fdisk分区工具的命令格式:    fdisk是传统的Linux硬盘分区工具,也是Linux系统中最常用的一种硬盘分区 ...

  7. [转]使用fdisk磁盘分区和 Linux 文件系统

    概述 在本文中,学习磁盘分区和 Linux 文件系统相关内容.学习: 创建分区 使用 mkfs 命令来设置 ext2.ext3.ext4.xfs.Reiser v3 和 vfat 文件系统 创建和管理 ...

  8. Linux学习(十三)du、df、fdisk磁盘分区

    一.du du命令是查看文件或者目录大小的命令. 一般使用du -sh 查看,不用-sh参数意义也不大,应为不用这个参数,它会把目录下的所有文件大小递归的显示出来,就像这样: 如果用-sh参数: [r ...

  9. fdisk磁盘分区与挂载

    参考博客:https://blog.csdn.net/capecape/article/details/78499351?locationNum=6&fps=1 1.查看磁盘分区情况.root ...

随机推荐

  1. Azure Digital Twins(2)- 在本地使用ADT Explorer 管理数字孪生

    本文介绍: 在本地运行ADT Explorer 并连接Azure Digital Twins 实例: 使用 VS CODE DTDL插件开发第一个 模型文件: ADT Explorer的几个基本功能: ...

  2. 由一名保安引发的Java设计模式:外观模式

    目录 应用场景 外观模式 定义 意图 主要解决问题 何时使用 优缺点 结构 保安的故事 应用场景 使用方要完成一个功能,需要调用提供方的多个接口.方法,调用过程复杂时,我们可以再提供一个高层接口(新的 ...

  3. Mybatis3源码笔记(四)Configuration(续)

    1.pluginElement(root.evalNode("plugins")) 解析plugins节点(注册interceptorChain里记录对应的拦截器) private ...

  4. ORM 创新解放劳动力 -SqlSugar 新功能介绍

    介绍 SqlSugar是一款 老牌 .NET 开源ORM框架,由果糖大数据科技团队维护和更新 ,Github star数仅次于EF 和 Dapper 优点: 简单易用.功能齐全.高性能.轻量级.服务齐 ...

  5. 程序员的开源月刊《HelloGitHub》第61期

    兴趣是最好的老师,HelloGitHub 让你对编程感兴趣! 简介 分享 GitHub 上有趣.入门级的开源项目. 内容包括:有趣.入门级的开源项目.开源书籍.实战项目.企业级项目等,让你在短时间内感 ...

  6. 8.switch语句

    switch语句语法 switch(expression){ case value : //语句 break; //可选 case value : //语句 break; //可选 //你可以有任意数 ...

  7. vue.js中使用set方法 this.$set

    vue教程中有这样一个注意事项: 第一种具体情况如下: 运行结果: 当利用索引改变数组某一项时,页面不会刷新.解决方法如下: 运行结果: 三种方式都可以解决,使用Vue.set.vm.$set()或者 ...

  8. 看了这篇还不会Linux性能分析和优化,你来打我

    前言 一般互联网的项目都是部署在linux服务器上的,如果linux服务器出了问题,那么咱们平时学习的高并发,稳定性之类的是没有任何意义的,所以对linux性能的把握就显得非常重要,当然很多同学可能觉 ...

  9. hdu1261 JAVA

    题意: 一个A和两个B一共可以组成三种字符串:"ABB","BAB","BBA".给定若干字母和它们相应的个数,计算一共可以组成多少个不同的 ...

  10. poj2418map或者字典树

    题意:      给你一些串,然后求出每个串出现的概率. 思路:      简单题目,做法也很多,我用字典树做了下,然后又用map做了下,其实这个题目我感觉直接排序一遍之后线性输出应该是最简单最快的( ...