本节将向您展示如何使用 fdisk 实用程序实际对硬盘进行分区。Linux 仅允许 4 个主分区。您可以通过细分其中一个主分区来拥有更多数量的逻辑分区。只有一个主分区可以被细分。
示例
可以通过输入 (以 root 用户身份)fdisk 设备在命令提示符下启动 fdisk。设备可能类似于/dev/hda或/dev/sda(参见 第 2.1.1 节)。您需要的基本 fdisk 命令是
p打印分区表
n创建新分区
d删除分区
q退出但不保存更改
w写入新的分区表并退出
您对分区表所做的更改在您发出写入 (w) 命令之前不会生效。这是一个示例分区表
Disk /dev/hdb: 64 heads, 63 sectors, 621 cylinders Units = cylinders of 4032 * 512 bytes Device Boot Start End Blocks Id System /dev/hdb1 * 1 184 370912+ 83 Linux /dev/hdb2 185 368 370944 83 Linux /dev/hdb3 369 552 370944 83 Linux /dev/hdb4 553 621 139104 82 Linux swap |
概述
确定交换空间的大小(参见 第 4.4 节)以及它应该去哪里(参见 第 4.4.3 节)。将剩余空间划分为其他三个分区。
示例
我从 shell 提示符启动 fdisk
# fdisk /dev/hdb |
Command (m for help): p Disk /dev/hdb: 64 heads, 63 sectors, 621 cylinders Units = cylinders of 4032 * 512 bytes |
Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-621, default 1):<RETURN> Using default value 1 Last cylinder or +size or +sizeM or +sizeK (1-621, default 621): +384M |
Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 2 First cylinder (197-621, default 197):<RETURN> Using default value 197 Last cylinder or +size or +sizeM or +sizeK (197-621, default 621): +128M |
Device Boot Start End Blocks Id System /dev/hdb1 1 196 395104 83 Linux /dev/hdb2 197 262 133056 83 Linux |
Command (m for help): a Partition number (1-4): 1 |
Command (m for help): t Partition number (1-4): 2 Hex code (type L to list codes): 82 Changed system type of partition 2 to 82 (Linux swap) Command (m for help): p |
Disk /dev/hdb: 64 heads, 63 sectors, 621 cylinders Units = cylinders of 4032 * 512 bytes Device Boot Start End Blocks Id System /dev/hdb1 * 1 196 395104+ 83 Linux /dev/hdb2 197 262 133056 82 Linux swap /dev/hdb3 263 458 395136 83 Linux /dev/hdb4 459 621 328608 83 Linux |
附带主题
概述: 创建一个主分区来容纳所有额外的分区。然后在其中创建逻辑分区。在创建逻辑分区之前或之后创建其他主分区。
示例
我从 shell 提示符启动 fdisk
# fdisk /dev/sda |
首先,我确定我想要多少个分区。我知道我的驱动器容量为 183Gb,我想要 26Gb 的分区(因为我碰巧有大约这个大小的备份磁带)。
183Gb / 26Gb = ~7
所以我需要 7 个分区。即使 fdisk 接受以 Mb 和 Kb 表示的分区大小,我还是决定计算每个分区最终将包含的柱面数,因为 fdisk 以柱面报告起始点和停止点。当我输入 fdisk 时,我看到我有 22800 个柱面。
> The number of cylinders for this disk is set to 22800. There is > nothing wrong with that, but this is larger than 1024, and could in > certain setups cause problems with: 1) software that runs at boot > time (e.g., LILO) 2) booting and partitioning software from other > OSs (e.g., DOS FDISK, OS/2 FDISK) |
由于我有 4 个主分区,其中 3 个可以是 3258 个柱面长。扩展分区必须是 (4 * 3258) 或 13032 个柱面长,才能容纳 4 个逻辑分区。
我输入以下命令来设置 3 个主分区中的第一个(我输入的命令以粗体显示)
Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-22800, default 1): <RETURN> Using default value 1 Last cylinder or +size or +sizeM or +sizeK (1-22800, default 22800): 3258 |
Partition number (1-4): 4 First cylinder (9775-22800, default 9775): <RETURN> Using default value 9775 Last cylinder or +size or +sizeM or +sizeK (9775-22800, default 22800): <RETURN> Using default value 22800 |
/dev/sda1 1 3258 26169853+ 83 Linux /dev/sda2 3259 6516 26169885 83 Linux /dev/sda3 6517 9774 26169885 83 Linux /dev/sda4 9775 22800 104631345 5 Extended |
Command (m for help): n First cylinder (9775-22800, default 9775): <RETURN> Using default value 9775 Last cylinder or +size or +sizeM or +sizeK (9775-22800, default 22800): 13032 |
Device Boot Start End Blocks Id System /dev/sda1 1 3258 26169853+ 83 Linux /dev/sda2 3259 6516 26169885 83 Linux /dev/sda3 6517 9774 26169885 83 Linux /dev/sda4 9775 22800 104631345 5 Extended /dev/sda5 9775 13032 26169853+ 83 Linux /dev/sda6 13033 16290 26169853+ 83 Linux /dev/sda7 16291 19584 26459023+ 83 Linux /dev/sda8 19585 22800 25832488+ 83 Linux |
我想提交我的分区布局,因为它在任何 Linux 发行版(甚至是大型基于 RPM 的发行版)中都能很好地工作。我有一个硬盘 ... 正好是 10 GB。Windows 看不到超过 9.3 GB 的空间,但 Linux 可以看到并使用所有空间。它也有超过 1024 个柱面。
表 7. 分区布局示例
分区 | 挂载点 | 大小 |
---|---|---|
/dev/hda1 | /boot | (15 MB) |
/dev/hda2 | Windows 98 分区 | (2 GB) |
/dev/hda3 | 扩展分区 | (N/A) |
/dev/hda5 | 交换空间 | (64 MB) |
/dev/hda6 | /tmp | (50 MB) |
/dev/hda7 | / | (150 MB) |
/dev/hda8 | /usr | (1.5 GB) |
/dev/hda9 | /home | (剩余空间) |
我还注意到您没有任何真正的分区表示例,对于新手,我强烈建议放一些上来。我已经刚从新手阶段出来,分区是最让我困惑的事情。