使用 fdisk 创建扩展分区

我们假设我们正在磁盘上创建第一个扩展分区。
要获取当前分区方案的列表,请使用“fdisk -l”。

  1. 使用 fdisk 命令中的选项 n 在磁盘 /dev/sdc 上创建第一个扩展分区。
# fdisk /dev/sdc
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): n
  1. 接下来通过选择“e”来创建扩展分区。
    它将自动选择驱动器上的下一个可用分区。
    在我们的例子中,下一个可用分区是 2.
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): e
Partition number (2-4, default 2): 2
  1. 现在,我们必须为我们的分区选择起始点。
    默认情况下,系统将选择磁盘上的下一个可用柱面。
    我们可以在此处按回车键选择默认值。
First sector (20973568-41943039, default 20973568):     ### press ENTER Here 
Using default value 20973568
  1. 下一步,我们可以选择新分区的大小,例如,要创建一个 1 GB 的分区,我们可以设置命令:+1024M。
Supported: 10^N: KB (KiloByte), MB (MegaByte), GB (GigaByte)
            2^N: K  (KibiByte), M  (MebiByte), G  (GibiByte)
Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): +1024M
Partition 2 of type Extended and of size 1 GiB is set
  1. 这将带我们返回命令行,我们可以其中查看新创建的分区。
    最后一行是新创建的扩展分区,我们可以看到它以块而不是兆字节列出,并且分区 ID 类型自动默认为扩展,这将允许我们在该分区上创建文件系统。
Command (m for help): p
Disk /dev/sdc: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xacbed9c3
   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048    20973567    10485760   83  Linux
/dev/sdc2        20973568    23070719     1048576    5  Extended
  1. 最后用write/quit命令(w)保存并退出fdisk。
    执行此命令后,更改将是永久性的。
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
  1. 运行partprobe命令扫描新修改的分区表:
# partprobe

如果 partprobe 未识别新修改的表,则需要重新启动。
我们还可以运行命令“fdisk -l”来验证新分区。

# fdisk -l /dev/sdc
Disk /dev/sdc: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xacbed9c3
   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048    20973567    10485760   83  Linux
/dev/sdc2        20973568    23070719     1048576    5  Extended
欢迎来到之路教程(on itroad-com)

主分区与扩展分区

PC 硬盘的原始分区方案只允许有四个分区,称为主分区。

要创建四个以上的分区,可以将这四个分区之一划分为许多较小的分区,称为逻辑分区。
当主分区以这种方式细分时,它被称为扩展分区。

什么是磁盘分区

分区将磁盘驱动器划分为一个或者多个逻辑磁盘。
每个分区都被视为具有自己文件系统的单独磁盘。
分区信息存储在分区表中。
可以使用 fdisk 实用程序创建两种类型的分区:

  • 主分区
  • 扩展分区
在Linux/UNIX中 如何使用 fdisk 创建扩展分区
日期:2020-09-17 00:13:27 来源:oir作者:oir