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. 000 - 准备工作ADB wifi连接多台鸿蒙设备进行调试

    首先将两台鸿蒙设备插入电脑的usb上 查看两台鸿蒙设备的deviceid C:\Users\Administrator>adb devices * daemon not running; sta ...

  2. 远程线程注入dll,突破session 0

    前言 之前已经提到过,远线程注入和内存写入隐藏模块,今天介绍突破session 0的dll注入 其实今天写这个的主要原因就是看到倾旋大佬有篇文章提到:有些反病毒引擎限制从lsass中dump出缓存,可 ...

  3. jQuery入门看这一篇就够了

    一.选择器 1.基本 名称 用法 描述 #id $("#myDiv"); 根据给定的ID匹配一个元素 element $("div"); 根据给定的元素标签名匹 ...

  4. 网络编程Netty入门:责任链模式介绍

    目录 责任链模式 责任链模式的简单实现 Netty中的ChannelPipeline责任链 服务端接收客户端连接 pipeline初始化 入站事件和出站事件 Pipeline中的Handler Pip ...

  5. day17.网络编程2+进程

    1 加入链接循环的套接字服务端 1.1 服务端 ''' 2.1 基于文件类型的套接字家族 套接字家族的名字:AF_UNIX unix一切皆文件,基于文件的套接字调用的就是底层的文件系统来取数据,两个套 ...

  6. JavaWeb请求与响应 Cookie&Session

    1.请求与响应 &Cookie&Session 1.1.请求与响应 HTTP协议 概念:英文全称:HyperText Transfer Protocol 中文全称:超文本传输协议   ...

  7. [VSC] HTML打叹号无法自动提示默认框架

    一般的, 在 VSC 中编辑 HTML 文档时, 打一个叹号 '!', 就会提示, 可生成默认代码, 如: 采纳建议后, 是这样: 问题: 如果出现打叹号无法出现提示的情况, 首先, 请检查当前的语言 ...

  8. IPS入侵防御系统

    目录 IPS入侵防御系统 如何才能更好的防御入侵 IPS与IDS的区别 IDS与IPS的部署 IPS独立部署 IPS分布式部署 IPS入侵防御系统 IPS(Intrusion Prevention S ...

  9. Django中图形验证码(django-simple-captcha)

    django-simple-captcha 在网站开发的登录页面中,经常会需要使用到图形验证码来验证.在Django中,django-simple-captcha库包提供了图形验证码的使用. 下面我们 ...

  10. <JVM中篇:字节码与类的加载篇>02-字节码指令集

    笔记来源:尚硅谷JVM全套教程,百万播放,全网巅峰(宋红康详解java虚拟机) 同步更新:https://gitee.com/vectorx/NOTE_JVM https://codechina.cs ...