Handbook:AMD64/Blocks/Disks/zh-cn

分区
虽然理论上可以用一整块磁盘来安装一个Linux系统，但是实践中几乎从不这样做. 实际上，一块磁盘可以被分成小一些的、更容易管理的块设备. 在 系统里，这被称为分区. 有两个标准的分区技术可以被使用：MBR和GPT.

MBR
主引导记录MBR (Master Boot Record)对分区的起始扇区和长度使用32比特的标识符，它支持三种分区类型：主分区、扩展分区和逻辑分区. 主分区把它们的信息存储在主引导记录里一个非常小的空间里，通常是512字节，因为这个空间太小了，所以系统只支持四个主分区. （例如从 到）

为了支持更多的分区，其中一个主分区可以被标识成扩展分区，然后这个分区就可以包含逻辑分区了（分区里的分区）.

每个分区的尺寸被限制在2TB，这是由于32比特的标识符造成的. 另外MBR不提供任何的MBR备份，所以一旦被某个应用或者用户误写覆盖了，所有的分区信息将会丢失.

GPT
GTP(GUID Partition table)为分区使用64比特标识符，它用来存储分区信息的空间也远比MBR的512字节要大，它也不对分区的数量作限制. 分区的大小限制可以达到8ZB. 译者注： 1ZiB = 1,024 EiB 1ZiB = 1,048,576 (1024)PiB 1ZiB = 1,073,741,824 (1024)TiB 1ZiB = 1,099,511,627,776 (1024)GiB 1ZiB = 1,125,899,906,842,624 (1024)MiB 1ZiB = 1,152,921,504,606,846,976 (1024)KiB 1ZiB = 1,180,591,620,717,411,303,424 (1024)B

当操作系统和系统固件之间的软件接口是UEFI (相对于BIOS)时，GPT几乎是必选的，因为MBR会引起很多兼容性问题.

GPT还有一个优势在于它在磁盘的盘尾还有一个GPT的备份，它可以用于在硬盘盘首的主GPT损坏时进行数据恢复. GPT仍旧使用CRC32校验和来探查分区表中的错误.

GPT还是MBR
依据上面的描述，人们大概会认为使用GPT应该总是被推荐的方法，但是这里其实还有一些注意事项.

在一台基于BIOS的计算机上使用GPT虽然是能够工作的，但是那样你就不能与微软的Windows操作系统进行双重引导了，原因是微软的Windows如果检测到一个GPT分区标签，它就会以EFI模式进行引导.

一些存在bug的BIOS或者配置成以BIOS/CSM/legacy模式进行引导的EFI也对从GPT标签的磁盘进行引导支持不好. 如果您也碰到了这种情况，有一个可能的凑合办法：在被保护的MBR分区上加上boot/active标志，您可以使用带有 选项的 命令强制它使用MBR格式读取分区表.

在这个例子中，我们用 并敲击 键来切换分区的（是否是活动的）标记. 敲击 键来选择第一个分区，然后敲击键来将所作改动写入磁盘，最后退出 这个程序.

使用UEFI
当在一个使用了UEFI（替代BIOS）进行引导作业的系统上安装Gentoo时，很重要的一点是一个EFI的系统分区需要被创建. The instructions for below contain the necessary pointers for this.

EFI系统分区也需要是一个FAT32分区（在Linux系统里也被称为“vfat”）. 这一章节末尾的指导中以“ext2”分区格式为例作为了 的分区. 请确保使用“vfat”，就像这样：

高级存储
安装CD提供了对LVM2的支持. LVM2增加了分区设置的灵活性，在这份安装指导中，我们将聚集在“常规”分区上，但是得知LVM2也被支持总是好的.

默认分区方案
一直到这份指南的末尾，下面的分区方案将被使用. 如果对此您没有疑问，您可以直接跳到 Default: Using parted to partition the disk 或者 Alternative: Using fdisk to partition the disk. 它们都是分区工具，是众所周知的、稳定且被推荐用于MBR分区的部署，而是新近开发的，同时被推荐用于GPT分区的部署.

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

什么是BIOS引导分区？
BIOS引导分区是一个非常小的分区（1到2MB），引导器软件如GRUB2可以将不适于存放在引导扇区（MBR中只有几百个字节）里并且不能存放在其它位置的额外数据存放于此.

这种分区并不总是需要的，但是考虑到低地址空间消耗以及记录大量不同的分区的难度，我们建议最好还是创建一个.

为了完整，当GPT分区方案与GRUB2一起使用，或者当MBR分区方案与GRUB2一起使用且第一个分区开始于磁盘上1MB位置之前时，BIOS引导分区是需要的.

默认：使用parted对磁盘进行分区
在这一章里，之前提到的分区方案范例将被使用：

您可以根据您的实际需要调整您的分区方案.

使用parted查看当前分区布局
这个应用为磁盘分区提供了一个简单的接口，而且它支持很大的分区空间（超过2TB）. 用 来搞磁盘吧（在我们的例子中，它是）. 我们建议您让 来优化分区对齐：

Alignment means that partitions are started on well-known boundaries within the disk, ensuring that operations on the disk from the operating system level (retrieve pages from the disk) use the least amount of internal disk operations. Misaligned partitions might require the disk to fetch two pages instead of one even if the operating system asked for a single page.

To find out about all options supported by parted, type and press return.

设置GPT标签
Most disks on the or  architectures are prepared using an msdos label. Using, the command to put a GPT label on the disk is :

To have the disk with MBR layout, use.

使用parted移除全部分区
If this isn't done yet (for instance through the operation earlier, or because the disk is a freshly formatted one), first remove all existing partitions from the disk. Type to view the current partitions, and  where NUMBER is the partition to remove.

Do the same for all other partitions that aren't needed. However, make sure to not make any mistakes here - parted executes the changes immediately (unlike which stages them, allowing a user to "undo" his changes before saving or exiting fdisk).

创建分区
Now create the partitions. Creating partitions with isn't very difficult - all we need to do is inform parted about the following settings:


 * The partition type to use. This usually is primary. If the msdos partition label is used, keep in mind that there can be no more than 4 primary partitions. If more than 4 partitions are needed, make one of the first four partitions extended and create logical partitions inside it.
 * The start location of a partition (which can be expressed in MB, GB, ...)
 * The end location of the partition (which can be expressed in MB, GB, ...)

First, tell parted that the size unit we work with is megabytes (actually mebibytes, abbreviated as MiB which is the "standard" notation, but we will use MB in the text throughout as it is much more common):

Now create a 2 MB partition that will be used by the GRUB2 boot loader later. Use the command for this, and inform  to start from 1 MB and end at 3 MB (creating a partition of 2 MB in size).

Do the same for the boot partition (128 MB), swap partition (in the example, 512 MB) and the root partition that spans the remaining disk (for which the end location is marked as -1, meaning the end of the disk minus one MB, which is the farthest a partition can go).

When using the UEFI interface to boot the system (instead of BIOS), mark the boot partition as the EFI System Partition. Parted does this automatically when the boot option is set on the partition:

The end result looks like so:

Use the command to exit parted.

备选：使用fdisk对磁盘进行分区
The following parts explain how to create the example partition layout using. The example partition layout was mentioned earlier:

Change the partition layout according to personal preference.

查看当前分区布局
is a popular and powerful tool to split a disk into partitions. Fire up against the disk (in our example, we use ):

Use the key to display the disk's current partition configuration:

This particular disk is configured to house seven Linux filesystems (each with a corresponding partition listed as "Linux") as well as a swap partition (listed as "Linux swap").

使用fdisk移除全部分区
First remove all existing partitions from the disk. Type to delete a partition. For instance, to delete an existing :

The partition has now been scheduled for deletion. It will no longer show up when printing the list of partitions (, but it will not be erased until the changes have been saved. This allows users to abort the operation if a mistake was made - in that case, type immediately and hit enter and the partition will not be deleted.

Repeatedly type to print out a partition listing and then type  and the number of the partition to delete it. Eventually, the partition table will be empty:

Now that the in-memory partition table is empty, we're ready to create the partitions.

创建BIOS引导分区
First create a very small BIOS boot partition. Type to create a new partition, then  to select a primary partition, followed by  to select the first primary partition. When prompted for the first sector, make sure it starts from 2048 (which is needed for the boot loader) and hit enter. When prompted for the last sector, type +2M to create a partition 2 Mbyte in size:

Mark the partition for EFI purposes:

创建引导分区
Now create a small boot partition. Type to create a new partition, then  to select a primary partition, followed by  to select the second primary partition. When prompted for the first sector, accept the default by hitting. When prompted for the last sector, type +128M to create a partition 128 Mbyte in size:

Now, when pressing, the following partition printout is displayed:

Type to toggle the bootable flag on a partition and select. After pressing again, notice that an * is placed in the "Boot" column.

创建swap分区
To create the swap partition, type to create a new partition, then  to tell fdisk to create a primary partition. Then type to create the third primary partition,. When prompted for the first sector, hit. When prompted for the last sector, type +512M (or any other size needed for the swap space) to create a partition 512MB in size.

After all this is done, type to set the partition type,  to select the partition just created and then type in 82 to set the partition type to "Linux Swap".

创建根分区
Finally, to create the root partition, type to create a new partition, then  to tell  to create a primary partition. Then type to create the fourth primary partition,. When prompted for the first sector, hit. When prompted for the last sector, hit to create a partition that takes up the rest of the remaining space on the disk. After completing these steps, typing should display a partition table that looks similar to this:

保存分区布局
To save the partition layout and exit, type.

With the partitions created, it is now time to put filesystems on them.