在 Oracle Linux 下有多种创建或者管理分区的选项 fdisk 就是其中之一。
这篇文章描述了它的用法和创建新分区表时的用例。
fdisk 是一个菜单驱动的程序,用于创建和操作分区表。
它了解 GPT(目前处于实验阶段)、MBR、Sun、SGI 和 BSD 分区表。
硬盘可以划分为一个或者多个称为分区的逻辑磁盘。
此分区记录在分区表中,该分区表位于磁盘的扇区 0 中。
(在 BSD 世界中,人们谈论“磁盘切片”和“磁盘标签”。
)
Linux 至少需要一个分区,即它的根文件系统。
它可以使用交换文件和/或者交换分区,但后者效率更高。
因此,通常人们会想要一个专用于交换分区的第二个 Linux 分区。
在 Intel 兼容硬件上,引导系统的 BIOS 通常只能访问磁盘的前 1024 个柱面。
出于这个原因,大磁盘的人通常会创建第三个分区,只有几 MB 大,通常挂载在 /boot 上,用于存储内核镜像和启动时所需的一些辅助文件,以确保这些东西是BIOS 可访问。
可能出于安全、易于管理和备份或者测试的原因,使用超过最小分区数。
所需的基本 fdisk 命令是:
- p 打印分区表
- n 创建一个新分区
- d 删除一个分区
- q 退出而不保存更改
- w 写入新的分区表并退出
在我们发出 write (w ) 命令之前,我们对分区表所做的更改不会生效。
更多信息可以在手册页中找到:
# man fdisk
更多: zhilu jiaocheng
使用 fdisk 对磁盘进行分区
- 对所需设备“/dev/device_name”运行 fdisk。
# 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. Device does not contain a recognized partition table Command (m for help):
- 选择选项“p”打印磁盘的分区表:
Command (m for help): p Disk /dev/sdc: 4294 MB, 4294967296 bytes, 8388608 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
- 选择选项“n”来创建一个新分区:
Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): First sector (2048-8388607, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-8388607, default 8388607): 4056 Partition 1 of type Linux and of size 1004.5 KiB is set
注意:要创建另一个分区,请再次选择选项“n”。
这是在同一磁盘上创建另一个分区的示例:
Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): p Partition number (2-4, default 2): First sector (4057-8388607, default 4096): Using default value 4096 Last sector, +sectors or +size{K,M,G} (4096-8388607, default 8388607): Using default value 8388607 Partition 2 of type Linux and of size 4 GiB is set
- 使用选项“p”检查分区表:
Command (m for help): p Disk /dev/sdc: 4294 MB, 4294967296 bytes, 8388608 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 Device Boot Start End Blocks Id System /dev/sdc1 2048 4056 1004+ 83 Linux /dev/sdc2 4096 8388607 4192256 83 Linux
- 选择选项“w”写入新的一个或者多个分区。
Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
- 运行命令 partprobe 通知操作系统分区表的变化:
# partprobe
日期:2020-09-17 00:14:02 来源:oir作者:oir