Fdisk (简体中文)

util-linux fdisk 是基于命令行界面的分区表创建和编辑工具。一个硬盘需要分为一个或多个分区,这个信息在分区表里面记录。

翻译状态:本文是 Fdisk翻译。上次翻译日期:2018-08-31。如果英文版本有所更改,则您可以帮助同步翻译。

本文介绍 fdisk(8)sfdisk(8) 工具的使用。

Note: fdisk supports GPT since util-linux 2.23. Alternatively, gptfdisk may be used; see gdisk for more information.

安装

要使用 fdisk 及相关工具,请使用 软件包,这个软件包已经位于 软件包组。

显示分区

要列出设备上的分区表和分区,可以运行以下命令,假设设备的名称为 :

# fdisk -l /dev/sda

备份和恢复分区

在对硬盘做出更改之前,您可能需要备份驱动器的分区表和分区方案。您还可以使用备份将同一分区布局复制到多个驱动器上。

对于GPT和MBR,您可以使用“sfdisk”将设备的分区布局保存到具有-d/--dump 选项的文件中. 对设备 运行以下命令:

# sfdisk -d /dev/sda > sda.dump

对于大小为1 GiB的单个ext4分区,该文件应如下所示:

要稍后恢复此布局,可以运行:

# sfdisk /dev/sda < sda.dump

创建分区表和分区

磁盘 partitioning 的第一步是创建分区表. 然后, 根据所需的 partition scheme 创建实际分区.参见 partition table 一文来帮助你选择使用 MBR 或是 GPT.

在开始之前,您可能希望 backup 您当前的分区表和方案.

fdisk 的最近版本不再使用磁道作为默认显示单位并放弃了对MS-DOS文件系统的兼容性。fdisk在 2048 个 512 字节扇区 (1 MiB) 块大小基础上自动进行分区对齐,这应该与所有使用 Advanced Format 的HDDs 和绝大多数 SSDs 兼容(并不全兼容)。 这意味着默认设置会自动使用正确的对齐方式。

为了使用 fdisk, 带上你想要更改/编辑的 block device 的名字,运行程序。在本例中我们使用 :

# fdisk /dev/sda

这将启动“fdisk”程序,您可以在其中键入命令。

创建新的分区表

输入 来新建一个 MBR 分区表并清除磁盘上的所有数据;输入 来新建一个GUID分区表 (GPT)。 如果已创建所需的分区表,请跳过此步骤。

Create partitions

Create a new partition with the n command. You must enter a MBR partition type, partition number, starting sector, and an ending sector.

Partition type

When using MBR, fdisk will ask for the MBR partition type. Specify it, type to create a primary partition or to create an extended one. There may be up to four primary partitions.

fdisk does not ask for the partition type ID and uses 'Linux filesystem' by default; you can change it later.

Partition number

A partition number is the number assigned to a partition, e.g. a partition with number on a disk would be . Partition numbers may not always match the order of partitions on disk, in which case they can be sorted.

It is advised to choose the default number suggested by fdisk.

First and last sector

The first sector must be specified in absolute terms using sector numbers. The last sector can be specified using the absolute position in sectors or using the symbol to specify a position relative to the start sector measured in sectors, kibibytes (), mebibytes (M), gibibytes (), tebibytes (), or pebibytes (); for instance, setting as the last sector will specify a point 2GiB after the start sector. Pressing the key with no input specifies the default value, which is the start of the largest available block for the start sector and the end of the same block for the end sector.

Select the partition's type id. The default, , should be fine for most use. Press to show the codes list. You can make the partition bootable by typing .

重复此过程,直到获得所需的分区。

将改动写入磁盘

使用 w 退出程序并将分区写入磁盘中.

提示和技巧

分区排序

这适用于在两个分区之间的空间中创建新分区或删除分区的情况。本例中使用了 .

# sfdisk -r /dev/sda

After sorting the partitions if you are not using Persistent block device naming, it might be required to adjust the and/or the configuration files.

另见

This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.