fdisk 命令

语法  fdisk [-l] [设备名称] 

-l 后边不跟设备名会直接列出系统中所有的磁盘设备以及分区表,加上设备名会列出该设备的分区表。

[[email protected] ~]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 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: 0x000eb8f3

Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          26      204800   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2              26         287     2097152   82  Linux swap / Solaris

Partition 2 does not end on cylinder boundary.

/dev/sda3             287        2611    18668544   83  Linux

Disk /dev/sdb: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 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

对比一下:

[[email protected] ~]# fdisk -l /dev/sda

Disk /dev/sda: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 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: 0x000eb8f3

Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          26      204800   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2              26         287     2097152   82  Linux swap / Solaris

Partition 2 does not end on cylinder boundary.

/dev/sda3             287        2611    18668544   83  Linux

可以看到一块儿未被分区的磁盘 /dev/sdb 的信息。


fdisk 如果不加 -l 则进入另一个模式,在该模式下,可以对磁盘进行分区操作。

[[email protected] ~]# fdisk /dev/sda

WARNING: DOS-compatible mode is deprecated. It‘s strongly recommended to

switch off the mode (command ‘c‘) and change display units to

sectors (command ‘u‘).

Command (m for help): m           //输入 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

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)

p 打印当前磁盘的分区情况:

Command (m for help): p

Disk /dev/sda: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 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: 0x000eb8f3

Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          26      204800   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2              26         287     2097152   82  Linux swap / Solaris

Partition 2 does not end on cylinder boundary.

/dev/sda3             287        2611    18668544   83  Linux

n 建立一个新的分区

w 保存操作

q 退出

d 删除一个分区


下面把刚刚显示的未分区磁盘 /dev/sdb 进行分区

[[email protected] ~]# 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 0x4cb6a167.

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

sectors (command ‘u‘).

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 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: 0x4cb6a167

Device Boot      Start         End      Blocks   Id  System

Command (m for help):

可以看到目前/dev/sdb 没有任何分区,下面建立第一个分区:

Command (m for help): n                     //使用 n 命令新建分区

Command action                                 //它会提示是要 e(扩展分区)还是要 p (主分区)。这里选择 p

e   extended

p   primary partition (1-4)

p

Partition number (1-4): 1                      //提示分区数,这里选择1

First cylinder (1-1305, default 1): 1            //提示第一个柱面从哪里开始,默认是1,直接回车也会按1处理。

Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): +1024M            //提示输入最后一个柱面的数值,使用另一种方法:+容量 单位

Command (m for help): p                            //再次查看会发现多出了一个分区

Disk /dev/sdb: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 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: 0x4cb6a167

Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1         132     1060258+  83  Linux

Command (m for help):

继续上面的操作,一直创建主分区到4,然后再一次创建分区时会提示:

Command (m for help): n

You must delete some partition and add an extended partition first

这是因为在linux系统中最多只能创建4个主分区。如果想要多创建几个分区需要有一个扩展分区,例如把第四个分区创建成扩展分区

Command (m for help): n

Command action

e   extended

p   primary partition (1-4)

e

Selected partition 4

First cylinder (397-1305, default 397):

Using default value 397

Last cylinder, +cylinders or +size{K,M,G} (397-1305, default 1305):                   //第四个扩展分区需要把剩余的磁盘空间全部占用

Using default value 1305

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 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: 0x4cb6a167

Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1         132     1060258+  83  Linux

/dev/sdb2             133         264     1060290   83  Linux

/dev/sdb3             265         396     1060290   83  Linux

/dev/sdb4             397        1305     7301542+   5  Extended           //扩展分区,在最后一列显示为 Extended

继续创建:

Command (m for help): n

First cylinder (397-1305, default 397):          //这时候不再选择主分区还是扩展分区了,而是直接定义大小

Using default value 397

Last cylinder, +cylinders or +size{K,M,G} (397-1305, default 1305): +1024M

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 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: 0x4cb6a167

Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1         132     1060258+  83  Linux

/dev/sdb2             133         264     1060290   83  Linux

/dev/sdb3             265         396     1060290   83  Linux

/dev/sdb4             397        1305     7301542+   5  Extended

/dev/sdb5             397         528     1060258+  83  Linux

当分完三个主分区后,第四个扩展分区要占用全部剩余空间的原因是:分完扩展分区后,再划分新的分区是在已经划分的扩展分区上去划分的。其中/dev/sdb4为扩展分区,它是不可以被格式化的,就相当于一个空壳子,能使用的为/dev/sdb5,这个分区叫做逻辑分区,是/dev/sdb4的子分区。


删除某分区: d 命令

Command (m for help): d

Partition number (1-5): 1

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 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: 0x4cb6a167

Device Boot      Start         End      Blocks   Id  System

/dev/sdb2             133         264     1060290   83  Linux

/dev/sdb3             265         396     1060290   83  Linux

/dev/sdb4             397        1305     7301542+   5  Extended

/dev/sdb5             397         528     1060258+  83  Linux

Command (m for help): d

Partition number (1-5): 5

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 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: 0x4cb6a167

Device Boot      Start         End      Blocks   Id  System

/dev/sdb2             133         264     1060290   83  Linux

/dev/sdb3             265         396     1060290   83  Linux

/dev/sdb4             397        1305     7301542+   5  Extended

Command (m for help): n

Command action

l   logical (5 or over)

p   primary partition (1-4)

l

First cylinder (397-1305, default 397):

Using default value 397

Last cylinder, +cylinders or +size{K,M,G} (397-1305, default 1305): +1024M

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 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: 0x4cb6a167

Device Boot      Start         End      Blocks   Id  System

/dev/sdb2             133         264     1060290   83  Linux

/dev/sdb3             265         396     1060290   83  Linux

/dev/sdb4             397        1305     7301542+   5  Extended

/dev/sdb5             397         528     1060258+  83  Linux

Command (m for help): d

Partition number (1-5): 4

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 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: 0x4cb6a167

Device Boot      Start         End      Blocks   Id  System

/dev/sdb2             133         264     1060290   83  Linux

/dev/sdb3             265         396     1060290   83  Linux

输入d会提示要删除那个分区,可以选择1-5,其中1-3为主分区。4是扩展分区,5是逻辑分区。如果输入5,则直接把逻辑分区sdb5删除掉,如果输入4,则会把整个扩展分区sdb4干掉,也包含扩展分区里面的逻辑分区。在刚才的界面中直接Ctrl+C退出来,这样刚刚的分区全部都取消了。


重新做分区:

[[email protected] ~]#  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 0xb2b18b55.

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

sectors (command ‘u‘).

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 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: 0xb2b18b55

Device Boot      Start         End      Blocks   Id  System

Command (m for help): n

Command action

e   extended

p   primary partition (1-4)

e

Partition number (1-4): 1

First cylinder (1-1305, default 1):

Using default value 1

Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305):

Using default value 1305

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 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: 0xb2b18b55

Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1        1305    10482381    5  Extended

Command (m for help): n

Command action

l   logical (5 or over)

p   primary partition (1-4)

l

First cylinder (1-1305, default 1):

Using default value 1

Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): +1024M

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 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: 0xb2b18b55

Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1        1305    10482381    5  Extended

/dev/sdb5               1         132     1060227   83  Linux

Command (m for help): n

Command action

l   logical (5 or over)

p   primary partition (1-4)

l

First cylinder (133-1305, default 133):

Using default value 133

Last cylinder, +cylinders or +size{K,M,G} (133-1305, default 1305): +1024M

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 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: 0xb2b18b55

Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1        1305    10482381    5  Extended

/dev/sdb5               1         132     1060227   83  Linux

/dev/sdb6             133         264     1060258+  83  Linux

Command (m for help): w                                        // w 命令保存配置

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

查看分区情况

[[email protected] ~]# fdisk -l /dev/sdb

Disk /dev/sdb: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 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: 0xb2b18b55

Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1        1305    10482381    5  Extended

/dev/sdb5               1         132     1060227   83  Linux

/dev/sdb6             133         264     1060258+  83  Linux

时间: 2024-08-06 20:03:09

fdisk 命令的相关文章

linux下使用fdisk命令进行硬盘分区

添加一块硬盘 # fdisk -l Disk /dev/vdb: 53.7 GB, 53687091200 bytes 16 heads, 63 sectors/track, 104025 cylinders Units = cylinders of 1008 * 512 = 516096 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512

Linux文件系统之新建分区(fdisk命令)

磁盘相关知识: 1.硬盘有数个盘片,每个盘片的两个面各自有一个磁头 2.盘片被划分为多个扇区 3.同一盘片不同半径的同心圆为磁道 4.不同盘片相同半径构成的圆柱面为柱面 fdisk命令: 1.查看已经识别的磁盘设备: [[email protected] ~]# fdisk -l /dev/[hs]d[a-z] Disk /dev/sda: 128.8 GB, 128849018880 bytes     255 heads, 63 sectors/track, 15665 cylinders

Linux fdisk 命令

Linux fdisk 命令 fdisk                         fdisk功能说明:磁盘分区.语 法:fdisk [-b <分区大小>][-uv][外围设备代号] 或 fdisk [-l][-b <分区大小>][-uv][外围设备代号...] 或 fdisk [-s <分区编号>]补充说明:fdisk是用来磁盘分区的程序,它采用传统的问答式界面,而非类似DOS fdisk的cfdisk互动式操作界面,因此在使用上较为不便,但功能却丝毫不打折扣.

Linux下使用fdisk命令和partprobe命令,在不重启系统的情况下新建分区并格式化

由于工作的需要,最近一段时间一直在学习Linux.学习一门新的知识,我是喜欢根据谋一本书或者某一个学习视频系统的学习,这样可以对学习的新知识有一个系统全面的认识和了解.所以学习之前,没了一本鸟哥的私房菜做为参考书,开始系统的学习Linux. 根据鸟哥的建议,安装虚拟机时,预留了一块空的容量用来练习分区使用.所以在虚拟机上安装Linux系统分区时,只划分了一块4G的容量挂载到根目录“/”下,还有就是只划分了一个2G的swap分区.还有14G的容量没有分配. 在学习磁盘管理时,使用fdisk将剩余的

Linux fdisk命令参数及用法详解---Linux磁盘分区管理命令fdisk

fdisk 命令 linux磁盘分区管理 用途:观察硬盘之实体使用情形与分割硬盘用. 使用方法: 一.在 console 上输入 fdisk -l /dev/sda ,观察硬盘之实体使用情形. 二.在 console 上输入 fdisk /dev/sda,可进入分割硬盘模式. 1. 输入 m 显示所有命令列示. 2. 输入 p 显示硬盘分割情形. 3. 输入 a 设定硬盘启动区. 4. 输入 n 设定新的硬盘分割区. 4.1. 输入 e 硬盘为[延伸]分割区(extend). 4.2. 输入 p

fdisk命令 实战案例

主要内容: ========================================== 一.fdisk命令中参数介绍 二.将/dev/sdd整个磁盘划成一个文件分区 三.删除整个分区 四.创建两个分区,分区一200M,分区二800M 五.创建主分区.扩展分区.逻辑分区 六.使用单个分区的方式进行格式化分区 七.挂载分区 八.配置开启自动挂载分区 九.挂载光驱 ========================================== 一.fdisk命令中参数介绍: Comma

Linux系统 fdisk命令 创建新分区

Linux系统 fdisk命令 创建新分区 --fdisk命令fdisk -l /dev/sda           # 查看分区 fdisk    /dev/sda           # 创建分区  n                         # 新建分区    (e                      # 创建扩展分区)    (p                      # 创建主分区)    (t                      # 改变分区类型)  p   

运行fdisk命令时,弹出 bash:fdisk:command not found

原因:命令fdisk 不在你的命令搜索路径中 第一种解决办法,将fdisk添加到你的命令搜索路径中 首先查看你当前的命令搜索路径: [[email protected] sbin]# echo $PATH/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/vurtne/bin 再查一下fdisk命令在哪个路径下 [[email protected] home]# wherei

如何避免使用fdisk命令硬盘分区后fstab挂载故障问题

问题: 一般情况我们在使用fdisk命令分区后,挂载时通常使用mount命令进行挂载,但在有些时候添加其他硬盘时,可能导致分区表变化系统无法启动的问题出现. 解决方法: blkid # 获取新分区的uuid:/dev/sdb5: UUID="8f21d155-3cbd-46d3-93df-903937e7b750" TYPE="ext4" vim /etc/fstab #系统开机自动挂载配置文件,添加下条命令参数UUID=8f21d155-3cbd-46d3-93d

linux下使用fdisk命令进行磁盘分区

linux下使用fdisk命令进行磁盘分区 目录 分区类型 分区方法表示 文件系统 fdisk命令分区过程 分区类型 主分区:总共最多只能分四个 扩展分区:只能有一个,也算作主分区的一种,也就是说主分区加扩展分区最多有四个.但是扩展分区不能存储数据和格式化,必须再划分成逻辑分区才能使用. 逻辑分区:逻辑分区是在扩展分区中划分的,如果是IDE硬盘,Linux最多支持59个逻辑分区,如果是IDE硬盘,Linux最多支持59个逻辑分区,如果是SCSI硬盘Linux最多支持11个逻辑分区 分区方法表示