Translations:Handbook:X86/Blocks/Disks/2/zh-cn

From Gentoo Wiki
Jump to:navigation Jump to:search


分区表

虽然理论上可以用一整块磁盘来安装一个Linux系统(比如当创建一个 btrfs RAID时),但是实践中几乎从不这样做。实际上,一块磁盘可以被分成小一些的、更容易管理的块设备。在 系统里,这被称为分区。有两个标准的分区技术可以被使用:MBR(有时也称为 DOS 磁盘标签)和GPT;这些与两种引导过程类型相关:传统 BIOS 引导和 UEFI。

GUID 分区表 (GPT)

GUID 分区表 (GPT)设置(也称为 GPT 磁盘标签)对分区使用 64 位标识符。它用来存储分区信息的空间也远比 MBR 分区表(DOS 磁盘标签)的512字节要大,GPT磁盘它也不对分区的数量作限制。分区的大小限制可以达到 8 ZiB(zebibytes)。 译者注:

  • 1ZiB = 1,024 EiB
  • 1EiB = 1024 PiB
  • 1PiB = 1024 TiB
  • 1TiB = 1024 GiB
  • 1GiB = 1024 MiB
  • 1MiB = 1024 KiB
  • 1KiB = 1024 B

当操作系统和系统固件之间的软件接口是UEFI (相对于BIOS)时,GPT几乎是必选的,因为这里 DOS 磁盘标签会引起很多兼容性问题。

GPT还利用校验和和冗余。 它携带CRC32校验和以检测报头和分区表中的错误,并在磁盘的末尾有一个备份GPT。 此备份表可用于恢复磁盘开头附近主GPT的损坏。

Important
关于 GPT 有一些注意事项:
  • 在基于 BIOS 的计算机上使用 GPT 是可行的,但不能与 Microsoft Windows 操作系统进行双重引导。原因是如果 Microsoft Windows 检测到 GPT 分区标签,它将以 UEFI 模式启动。
  • 一些配置为以 BIOS/CSM/legacy 模式启动的有问题的(旧)主板固件在从 GPT 标记的磁盘启动时也可能存在问题。

主引导记录 (MBR) 和 DOS 引导扇区

主引导记录引导扇区(也称为 DOS 引导扇区,DOS 磁盘标签,现在区别与 GPT/UEFI 安装,称为 传统 BIOS 引导)于 1983 年首次在 PC DOS 2.x 中引入。 MBR 使用 32 位标识符作为分区的起始扇区和长度,并支持三种分区类型:主分区、扩展分区和逻辑分区。主分区的信息存储在主引导记录本身——磁盘最开始的一个非常小的(通常是 512 字节)位置。由于空间很小,因此仅支持四个主分区(例如,/dev/sda1/dev/sda4)。

为了支持更多的分区,可以将 MBR 中的主分区之一标记为扩展分区。然后,该分区可以包含其它逻辑分区(分区内的分区)。

Important
虽然大多数主板制造商仍然支持,但 MBR 引导扇区及其相关的分区限制被认为是传统的分区方式。除非使用 2010 之前的硬件,否则最好使用 GUID 分区表 对磁盘进行分区。必须继续进行设置类型的读者应了解以下信息:
  • 大多数 2010 年后的主板都有接受用 MBR 引导扇区作为传统(受支持但不理想的)引导模式。
  • 由于使用 32 位标识符,MBR 中的分区表无法处理大于 2 TiB 的存储空间。
  • 除非创建扩展分区,否则 MBR 最多支持四个分区。
  • 此设置不提供备份引导扇区,因此如果某些内容覆盖分区表,所有分区信息将丢失。
也就是说,在 AWS 等虚拟化云环境中仍可能使用 MBR 和 传统 BIOS 启动。

手册作者建议读者安装Gentoo时尽可能使用 GPT

高级储存

安装 CD 提供了对逻辑卷管理器 (LVM) 的支持。 LVM 通过增加分区设置提供的灵活性。它允许将分区和磁盘组合到卷组中,并在快速的固态硬盘上为慢速的机械硬盘定义 RAID 组或缓存。下面的安装说明将侧重于"常规"分区,如果强烈需要 LVM,请访问 LVM 文章了解更多详情。新手请注意:LVM虽然完全支持 ,但不在本指南的范围内。

默认分区方案

在本手册的其余部分,我们将讨论和解释两种情况:

  1. GUID 分区表 (GPT)和 UEFI 引导。
  2. MBR 分区表和传统 BIOS 引导。

While it is possible to mix and match boot types with certain motherboard firmware, mixing goes beyond the intention of the handbook. As previously stated, it is strongly recommended for installations on modern hardware to use UEFI boot with a GPT disklabel disk.

以下分区方案是一种简单的布局示例。

Important
The first row of the following table contains exclusive information for either a GPT disklabel or a MBR DOS/legacy BIOS disklabel. When in doubt, proceed with GPT, since machines manufactured after the year 2010 generally support UEFI firmware and GPT boot sector.
分区 文件系统 大小 描述
fat32 EFI 系统分区所需的文件系统,总与 GPT 磁盘标签相关联。 1 GiB EFI 系统分区详情。 适用于支持 UEFI 的系统固件。通常为 2010 年前后至今生产的系统。
MBR 分区表启动分区推荐的文件系统,仅限于 DOS/传统 BIOS 磁盘标签的旧固件一起使用。 MBR DOS/传统 BIOS 引导分区详情。 适用于传统 BIOS 机器固件。通常为 2010 年<u>以前</u>的系统,并且逐步停止维护。
linux-swap RAM 大小 * 2 交换分区详情。
磁盘剩余空间 根分区详情。

如果这些信息已经足够,高级读者可以直接跳转到实际分区操作。

fdiskparted 都是包含在官方 Gentoo live 镜像环境中的分区实用程序。 fdisk 大家都熟知,稳定,在 MBR 和 GPT 磁盘都可以使用。 parted 是最早支持 GPT 分区的 Linux 块设备管理的分区工具之一。如果读者愿意的话,parted 可以作为 fdisk 的替代品,但是因为在大多数 Linux 环境中常见 fdisk,所以本手册只介绍 fdisk

在进行创建分区的指导之前,关于分区方案和常见陷阱我们会先介绍更多的细节。


设计一个分区方案

多少个分区以及多大?

磁盘分区布局的设计高度依赖于系统需求和应用到设备的文件系统。如果有很多用户,建议将 /home 放在单独的分区上,这将提高安全性并使备份和其他类型的维护更容易。 以增强安全性及便于备份。如果安装 Gentoo 来做邮件服务器,那么 /var 应该单独分一个区,因为所有的邮件都储存于 /var/。游戏服务器可能应该有一个独立的 /opt/,因为大多数游戏服务器软件都安装在那里。原因也和 /home/ 目录一样:安全,备份和维护。

在 Gentoo 的大多数情况下,/usr/var 应该保持相对较大的空间。/usr 存放了系统中的大部分应用程序和 Linux 内核源代码(在/usr/src下)。默认情况下,/var 存放着 Gentoo ebuild 仓库(位于 ),根据文件系统的不同,它大约耗费 650MiB 的磁盘空间。这个空间估计"不包括" 目录,当它们被添加到系统中时,将逐渐填写源代码文件和二进制包(可选)。

分区的数量和大小取决于权衡利弊后根据实际情况选择最佳选项。单独的分区或卷具有以下优点:

  • 为每个分区或者卷选择性能最好的文件系统。
  • 当一个失控的工具持续向一个分区或卷写文件时,也不至于让整个系统由于无可用空间而无法运行。
  • 如果有必要,可以简化文件系统检查,多个检查可以并行的完成(尽管使用多个磁盘比使用多个分区更多地实现了这一优势)。
  • 可以通过在挂载一些分区或卷时使用只读、nosuid(忽略setuid属性)、noexec(忽略可执行属性)等来增加安全性。


但是,多个分区也有一些缺点:

  • 如果配置不正确,系统可能在一个分区上有很多可用空间,而在另一个分区上可用空间很少。
  • /usr/ 的单独分区可能需要管理员使用 initramfs 引导,以便在其他引导脚本启动之前挂载该分区。由于 initramfs 的生成和维护超出了本手册的范围,我们建议新手不要为 /usr/ 使用单独的分区
  • SCSI 和 SATA 也有 15 个分区的限制,除非磁盘使用 GPT 标签。
Note
打算使用 systemd 作为服务和 init 系统安装时,/usr/ 目录必须在启动时可用,可以将该目录作为根文件系统的一部分,或通过 initramfs 挂载该目录。

那么交换空间呢?

对于交换空间大小,没有一个完美值。交换空间的目的是当内存(RAM)有压力时为内核提供磁盘存储。一个交换空间允许内核将看过来稍后不会被访问的内存页面移动到磁盘(交换或者 page-out)、为当前任务释放 RAM 中的内存。当然,如果突然要使用到交换到磁盘的页面,需要花费比从 RAM 读取要长得多的时间(相比较内存,硬盘是非常慢的),将这些页面需要放回到内存中(page-in)。

如果系统不运行很需要内存的应用程序或有足够多的可用 RAM,则不需要太多的交换空间。但是请注意,在休眠的情况下,交换空间用于存储"内存的全部内容"(可能在台式机和笔记本电脑系统上,而不是在服务器系统上)。如果系统需要支持休眠,那么有必要使用大于或等于内存数量的交换空间。

作为一般规则,建议交换空间大小为内部存储器 (RAM) 的两倍。对于具有多个硬盘的系统,明智的做法是在每个磁盘上创建一个交换分区,以便它们可以用于并行读/写操作。当必须访问交换空间中的数据时,磁盘交换的速度越快,系统运行的速度就越快。在机械和固态磁盘之间进行选择时,最好将交换放在 SSD 上以提高性能。此外,交换文件可以用作交换分区的替代方案;这对于磁盘空间非常有限的系统来说非常有趣。


什么是 EFI 系统分区 (ESP)?

在使用由 UEFI 引导(而不是 BIOS)的操作系统上安装 Gentoo 时,创建 EFI 系统分区 (ESP) 很重要。下面的说明包含正确处理此操作所需的关键点。 在 BIOS/Legacy 模式下启动时不需要 EFI 系统分区。

ESP 必须是 FAT 变体(有时在 Linux 系统上显示为 vfat)。官方 UEFI 规范 表示 UEFI 固件将识别 FAT12、16 或 32 文件系统,但建议使用 FAT32。分区后,相应地格式化 ESP:

root #mkfs.fat -F 32
Warning
如果 ESP 没有使用 FAT 变体进行格式化,那么系统的 UEFI 固件将找不到引导加载程序(或 Linux 内核)并且很可能无法引导系统!

什么是BIOS引导分区?

只有在 BIOS/Legacy 模式下将 GPT 分区布局与 GRUB2 结合时,才需要 BIOS 引导分区。 在 EFI/UEFI 启动模式下引导时不需要它,使用 MBR 表时也不需要它。它是一个非常小的分区(1 到 2 MB),像 GRUB2 这样的可以在其中放置超出容量的引导加载程序。本指南中不会使用它。

使用 GPT for UEFI 对磁盘进行分区

以下部分解释了如何使用 fdisk 为 GPT/UEFI 引导安装创建示例分区布局。范例分区布局我们在前面已经提到过了。

请您根据自己的实际需要来调整您的分区布局。

设备路径 (sysfs) 挂载点 文件系统 DPS UUID (PARTUUID) 描述
EFI 系统分区(EFI system partition ESP) 详情。
N/A. 交换分区并不像设备文件那样挂载到文件系统。 交换分区分区详情。
/ 根分区详情。

查看当前分区布局

fdisk是一个流行的和强大的分区工具。用fdisk向磁盘开火吧!(在我们的例子里,我们使用/dev/sda):

root #fdisk /dev/sda

使用 p 键来显示磁盘当前的分区配置。

Command (m for help):p
Disk /dev/sda: 28.89 GiB, 31001149440 bytes, 60549120 sectors
Disk model: DataTraveler 2.0
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 21AAD8CF-DB67-0F43-9374-416C7A4E31EA
</div>

<div lang="en" dir="ltr" class="mw-content-ltr">
Device        Start        End    Sectors   Size Type
/dev/sda1      2048    2099199    2097152     1G EFI System
/dev/sda2   2099200   10487807    8388608     4G Linux swap
/dev/sda3  10487808 1953523711 1943035904 926.5G Linux root (x86-64)

这块特定的磁盘被配置为容纳 2 个 Linux 文件系统(每个都有一个相应的分区列为“Linux”)以及一个交换分区(列为“Linux swap”)。

创建一个新的磁盘标签/删除所有分区

输入 g 在磁盘上创建一个新的 GPT 磁盘标签;这将删除所有现有分区。

Command (m for help):g
Created a new GPT disklabel (GUID: 87EA4497-2722-DF43-A954-368E46AE5C5F).

对于现有的 GPT 磁盘标签(参见上面 p 的输出),或者考虑从磁盘中一一删除现有分区。输入 d 来删除一个分区。例如,要删除现有的 /dev/sda1

Command (m for help):d
Partition number (1-4): 1

这个分区已经计划被删除了,当您用p键打印分区清单时它将不会被显示了,但此时它还未被实际删除,直到改变被真正保存。这将允许用户在操作错误后中止——此时,输入q并按Enter可以立即防止分区被删除。

重复敲击 p来打印分区清单,然后敲击 d键和分区号码来删除它。最终,分区表将变得空空如也。

Command (m for help):p
Disk /dev/sda: 28.89 GiB, 31001149440 bytes, 60549120 sectors
Disk model: DataTraveler 2.0
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 87EA4497-2722-DF43-A954-368E46AE5C5F

现在在内存中的分区表已经空了,我们是时候来创建分区了。

创建 EFI 系统分区 (ESP)

Note
虽然可以使用较小的 ESP,但是不推荐这么做,尤其是考虑到可能与其他操作系统共享 ESP。

首先创建一个小的 EFI 系统分区,该分区也将挂载为 /boot。输入 n 创建一个新分区,然后输入 1 选择第一个分区。当提示输入第一个扇区时,确保它从 2048(引导加载程序可能需要)开始并输入 Enter。当提示输入最后一个扇区时,输入 +1G 创建一个大小为 1G 字节的分区:

Command (m for help):n
Partition number (1-128, default 1): 1
First sector (2048-60549086, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-60549086, default 60549086): +1G
 
Created a new partition 1 of type 'Linux filesystem' and of size 1 GiB.

Do you want to remove the signature? [Y]es/[N]o: Y The signature will be removed by a write command.

}}

将分区标记为 EFI 系统分区:

Command (m for help):t
Selected partition 1
Partition type (type L to list all types): 1
Changed type of partition 'Linux filesystem' to 'EFI System'.

Optionally, to have the ESP conform to the Discoverable System Partition (DSP) specification, switch to expert mode and perform the following extra step to set the partition's UUID:

Command (m for help):x
Expert command (m for help):u
Selected partition 1
</div>

<div lang="en" dir="ltr" class="mw-content-ltr">
New UUID (in 8-4-4-4-12 format): c12a7328-f81f-11d2-ba4b-00a0c93ec93b
Partition UUID changed from 10293DC1-DF6C-4443-8ACF-C756B81B4767 to C12A7328-F81F-11D2-BA4B-00A0C93EC93B.

Press the r key to return to the main menu:

Expert command (m for help):r
</div>

<div lang="en" dir="ltr" class="mw-content-ltr">
Command (m for help):

创建交换分区

接下来,要创建交换分区,请输入 n 创建一个新分区,然后输入 2 创建第二个分区 /dev/sda2。当提示输入第一个扇区时,输入 Enter。当提示输入最后一个扇区时,输入 +4G(或交换空间所需的任何其他大小)以创建大小为 4GB 的分区。

Command (m for help):n
Partition number (2-128, default 2): 
First sector (526336-60549086, default 526336): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (526336-60549086, default 60549086): +4G
 
Created a new partition 2 of type 'Linux filesystem' and of size 4 GiB.

完成后,输入t设置分区类型,2选择刚刚创建的分区,然后输入 19 设置分区类型为 "Linux Swap"。

Command (m for help):t
Partition number (1,2, default 2): 2
Partition type (type L to list all types): 19
 
Changed type of partition 'Linux filesystem' to 'Linux swap'.

Optionally, to have the swap partition conform to the Discoverable System Partition (DSP) specification, switch to expert mode and perform the following extra step to set the partition's UUID:

Command (m for help):x
Expert command (m for help):u
Partition number (1,2, default 2): 2
Selected partition 2
</div>

<div lang="en" dir="ltr" class="mw-content-ltr">
New UUID (in 8-4-4-4-12 format): 0657fd6d-a4ab-43c4-84e5-0933c84b4f4f
Partition UUID changed from 7529CDF6-9482-4497-B021-576745648B2A to 0657FD6D-A4AB-43C4-84E5-0933C84B4F4F..

Press the r key to return to the main menu:

Expert command (m for help):r
</div>

<div lang="en" dir="ltr" class="mw-content-ltr">
Command (m for help):

创建根分区

最后,要创建根分区,请输入 n 以创建新分区。然后输入 3 创建第三个分区,/dev/sda3。当提示输入第一个扇区时,按 Enter。当提示输入最后一个扇区时,按 Enter 以创建一个分区,该分区占用磁盘上的其余剩余空间。完成这些步骤后,输入 p 应该会显示一个类似于以下内容的分区表:

Command (m for help):n
Partition number (3-128, default 3): 3
First sector (10487808-1953525134, default 10487808):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (10487808-1953525134, default 1953523711):
</div>

<div lang="en" dir="ltr" class="mw-content-ltr">
Created a new partition 3 of type 'Linux filesystem' and of size 926.5 GiB..
Note
Setting the root partition's type to "Linux root (x86-64)" is not required and the system will function normally if it is set to the "Linux filesystem" type. This filesystem type is only necessary for cases where a bootloader that supports it (i.e. systemd-boot) is used and a fstab file is not wanted.

After creating the root partition, press t to set the partition type, 3 to select the partition just created, and then type in 23 to set the partition type to "Linux Root (x86-64)".

Command(m for help):t
Partition number (1-3, default 3): 3
Partition type or alias (type L to list all): 23
</div>

<div lang="en" dir="ltr" class="mw-content-ltr">
Changed type of partition 'Linux filesystem' to 'Linux root (x86-64)'

Optionally, to have the root partition conform to the Discoverable System Partition (DSP) specification, switch to expert mode and perform the following extra step to set the partition's UUID:

Command (m for help):x
Expert command (m for help):u
Partition number (1-3, default 3): 3
</div>

<div lang="en" dir="ltr" class="mw-content-ltr">
New UUID (in 8-4-4-4-12 format): 4f68bce3-e8cd-4db1-96e7-fbcaf984b709
</div>

<div lang="en" dir="ltr" class="mw-content-ltr">
Partition UUID changed from 40465382-FA2A-4846-9827-640821CC001F to 4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709.

Press the r key to return to the main menu:

Expert command (m for help):r
</div>

<div lang="en" dir="ltr" class="mw-content-ltr">
Command (m for help):

After completing these steps, pressing p should display a partition table that looks similar to the following:

Command (m for help):p
Disk /dev/sda: 28.89 GiB, 31001149440 bytes, 60549120 sectors
Disk model: DataTraveler 2.0
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 87EA4497-2722-DF43-A954-368E46AE5C5F
 
Device       Start      End  Sectors  Size Type
/dev/sda1     2048   526335   524288    1G EFI System
/dev/sda2   526336  8914943  8388608    4G Linux swap
/dev/sda3  8914944 60549086 51634143 24.6G Linux filesystem

Device Start End Sectors Size Type /dev/sda1 2048 2099199 2097152 1G Linux filesystem /dev/sda2 2099200 10487807 8388608 4G Linux swap /dev/sda3 10487808 1953523711 1943035904 926.5G Linux root (x86-64)

Filesystem/RAID signature on partition 1 will be wiped.

}}

保存分区布局

要保存分区布局并退出 fdisk,请敲击 w

Command (m for help):w

当分区创建完成后,就该在其上部署文件系统了。

使用 MBR 对磁盘进行分区以用于 BIOS/legacy 启动

下面解释了如何为 MBR/BIOS 传统引导安装创建示例分区布局。前面提到的示例分区布局现在是:

设备路径 (sysfs) 挂载点 文件系统 DPS UUID (PARTUUID) 描述
N/A MBR DOS / 传统 BIOS 引导分区详情。
N/A. 交换分区并不像设备文件那样挂载到文件系统。 交换分区详情。
/ 根分区详情。

根据个人喜好更改分区布局。

查看当前分区布局

针对磁盘启动 fdisk(在我们的示例中,我们使用 /dev/sda):

root #fdisk /dev/sda

输入p显示磁盘的当前分区配置:

Command (m for help):p
Disk /dev/sda: 28.89 GiB, 31001149440 bytes, 60549120 sectors
Disk model: DataTraveler 2.0
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 21AAD8CF-DB67-0F43-9374-416C7A4E31EA
 
Device        Start      End  Sectors  Size Type
/dev/sda1      2048   526335   524288    1G EFI System
/dev/sda2    526336  2623487  2097152    1G Linux swap
/dev/sda3   2623488 19400703 16777216    8G Linux filesystem
/dev/sda4  19400704 60549086 41148383 19.6G Linux filesystem

Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 2099199 2097152 1G 83 Linux /dev/sda2 2099200 10487807 8388608 4G 82 Linux swap / Solaris /dev/sda3 10487808 1953525167 1943037360 926.5G 83 Linux

}}

直到现在,这个特定的磁盘被配置为使用 GPT 表容纳两个 Linux 文件系统(每个都有一个相应的分区列为 "Linux")以及一个交换分区(列为 "Linux swap")。

创建一个新的磁盘标签/删除所有分区

输入 o 在磁盘上创建一个新的 MBR 磁盘标签(这里也称为 DOS 磁盘标签);这将删除所有现有分区。

Command (m for help):o
Created a new DOS disklabel with disk identifier 0xe04e67c4.
The device contains 'gpt' signature and it will be removed by a write command. See fdisk(8) man page and --wipe option for more details.

对于现有的 DOS 磁盘标签(参见上面 p 的输出),或者考虑从磁盘中一一删除现有分区。输入 d 删除分区。例如,要删除现有的 /dev/sda1


Command (m for help):d
Partition number (1-4): 1

该分区现已计划删除。打印分区列表时将不再显示 (p,但在保存更改之前它不会被删除。如果发生错误,用户可以中止操作 —— 在这种情况下, 立即输入 q 并按 Enter 不会删除分区。

重复输入 p 打印出一个分区列表,然后输入 d 和分区号来删除它。最终,分区表将为空:

Command (m for help):p
Disk /dev/sda: 28.89 GiB, 31001149440 bytes, 60549120 sectors
Disk model: DataTraveler 2.0
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xe04e67c4

现在我们已准备好创建分区。

创建引导分区

首先,创建一个将挂载到 /boot 的小分区。输入 n 创建一个新分区,然后输入 p 作为主分区,输入 1 选择第一个主分区。当提示输入第一个扇区时,确保它从 2048(引导加载程序可能需要)开始并按 Enter。当提示输入最后一个扇区时,输入 +1G 创建一个大小为 1 GB 的分区:

Command (m for help):n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-60549119, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-60549119, default 60549119): +1G
 
Created a new partition 1 of type 'Linux' and of size 1 GiB.

Created a new partition 1 of type 'Linux' and of size 1 GiB.

}}

Mark the partition as bootable by pressing the a key and pressing Enter:

Command (m for help):a
Selected partition 1
The bootable flag on partition 1 is enabled now.

Note: if more than one partition is available on the disk, then the partition to be flagged as bootable will have to be selected.

创建 swap 分区

接下来,要创建交换分区,输入 n 创建一个新分区,然后输入 p,然后输入 2 创建第二个主分区,/dev/sda2。当提示输入第一个扇区时,按 Enter。当提示输入最后一个扇区时,输入 +4G(或交换空间所需的任何其他大小)以创建大小为 4GB 的分区。

Command (m for help):n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 2
First sector (526336-60549119, default 526336): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (526336-60549119, default 60549119): +4G
 
Created a new partition 2 of type 'Linux' and of size 4 GiB.

完成后,输入t设置分区类型,输入2选择刚刚创建的分区,然后输入 82 设置分区类型为 "Linux Swap"。

Command (m for help):t
Partition number (1,2, default 2): 2
Hex code (type L to list all codes): 82

Changed type of partition 'Linux' to 'Linux swap / Solaris'.

创建根分区

最后,要创建根分区,请输入 n 以创建新分区。然后输入 p3 以创建第三个主分区 /dev/sda3。当提示输入第一个扇区时,按 Enter。当提示输入最后一个扇区时,按 Enter 以创建一个分区,该分区占用磁盘上的剩余空间。完成这些步骤后,输入 p 应该会显示一个类似于以下内容的分区表:

Command (m for help):n
Partition type
   p   primary (2 primary, 0 extended, 2 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (3,4, default 3): 3
First sector (10487808-1953525167, default 10487808):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (10487808-1953525167, default 1953525167):
</div>

<div lang="en" dir="ltr" class="mw-content-ltr">
Created a new partition 3 of type 'Linux' and of size 926.5 GiB.

After completing these steps, pressing p should display a partition table that looks similar to this:

Command (m for help):p
Disk /dev/sda: 28.89 GiB, 31001149440 bytes, 60549120 sectors
Disk model: DataTraveler 2.0
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xe04e67c4
 
Device     Boot   Start      End  Sectors  Size Id Type
/dev/sda1          2048   526335   524288    1G 83 Linux
/dev/sda2        526336  8914943  8388608    4G 82 Linux swap / Solaris
/dev/sda3       8914944 60549119 51634176 24.6G 83 Linux

Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 2099199 2097152 1G 83 Linux /dev/sda2 2099200 10487807 8388608 4G 82 Linux swap / Solaris /dev/sda3 10487808 1953525167 1943037360 926.5G 83 Linux

}}

保存分区布局

要保存分区布局并退出 fdisk,输入 w

Command (m for help):w

现在是时候将文件系统应用在分区上了。