fdisk 中文man页面

系统
硬盘可以被分成一个或多个逻辑磁盘,称为 分区。 这些分区信息都存放在硬盘0扇区的 分区表 中。

NAME

fdisk - Linux分区表操作工具软件  

总览

fdisk [-u]设备名

fdisk -l [-u] [设备名 ...]

fdisk -s分区 ...

fdisk -v  

描述

硬盘可以被分成一个或多个逻辑磁盘,称为 分区。 这些分区信息都存放在硬盘0扇区的 分区表 中。

在 BSD 风格中,分区被称为“磁盘片”和“磁盘标签”

Linux 至少需要一个分区,即用做它的 root 文件系统。 Linux 可以使用交换文件和/或交换分区,交换分区更有效。因此,通常用户会创建第二个 Linux 分区供交换分区使用。在 Intel 兼容的硬件上,启动系统的 BIOS 往往只能访问 1024 柱面之前的硬盘。因此,使用大硬盘的用户通常创建第三个只有几兆大小的小分区,通常用来装配在 /boot ,用来存放内核映象和一些其它启动时需要的附属文件,所以应确保此分区必须是在BIOS可访问的部分。出于安全方面的考虑、管理方面的原因、备份的需要或为了某些测试,也可以将一个硬盘分成更多的分区使用。

fdisk (以第一种形式调用)是一个以菜单问答形式出现的用来创建和修改分区的程序。它可以辩认 DOS 类型的分区表和 BSD 或 SUN 类型的磁盘标签。

设备 通常是下列之一:
 

/dev/hda /dev/hdb /dev/sda /dev/sdb

(/dev/hd[a-h] 指 IDE 硬盘,/dev/sd[a-p] 指 SCSI 硬盘, /dev/ed[a-d] 指 ESDI 硬盘,/dev/xd[ab] 指 XT 硬盘)。设备名指整个硬盘设备。

分区 是在 设备名 后跟一个分区号。例如: /dev/hda1 是指系统在第一个 IDE 硬盘上的第一个分区。 IDE 硬盘可以最多创建 63 个分区,SCSI 可以创建 15 个。又见 /usr/src/linux/Documnetation/devices.txt

一个 BSD/SUN 风格的磁盘标签可以描述 8 个分区,其中第三个应该是“整个磁盘”分区。不要在零柱面使用那些的确使用其第一扇区的分区,(比如交换分区)因为这将损坏磁盘标签。

一个 IRIX/SGI 风格的磁盘标签可以描述 16 个分区,其中第十一个应该是完整“卷标”分区,而第九个应该被标成“卷标头”。卷标头将覆盖分区表,即,它从零块开始并缺省时延伸 5 个柱面。卷标头中余下的空间可以用来存放头部目录记录信息。不要有任何分区与此卷标头重叠。同样,也不要改变它的类形和在其中创建任何文件系统,因为这样做将丢失分区表信息。只有当将 Linux 安装在 IRIX/SGI 机器上或在 Linux 中使用 IRIX/SGI 磁盘时才会使用这种类形的标签。

一个 DOS 风格的分区表可以描述无限的分区。零扇区用来存放 4 个分区(称为主分区)的描述信息。其中可以有一个分区是扩展分区;此扩展分区也就是存储各逻辑分区地方,是一个在组成链表的扇区里存放的描述符,每个描述符都是一个对应分区的开头.四个主分区,不管是否存在,都用数字 1-4 编号,而逻辑分区以 5 开始。

在 DOS 风格的分区表中,开始地址偏移量和每个分区的大小是以两种不同的方式来存放的:以扇区数的绝对值来描述(占 32 位)和以柱面、磁头、扇区三个一组的形式(占 10+8+6 个位)来描述。前一种描述很好 - 如果每扇区 512 个字节的情况,这种方式可描述到 2TB 的大小。后一种方式有两个不同的问题。第一个是这种 C/H/S 方式必须是在磁头数和每磁道扇区数都已知的情况下才能使用。第二个是就算我们已经知道了这些数字,而只用 24 位来描述这些信息也是不够的。 DOS 只使用这种 C/H/S 的方式,Windows 则两个都用,Linux 则不使用 C/H/S 的方式。

如果可能, fdisk 会自动获得磁盘的几何结构。这不一定是磁盘的物理结构(当然,现在的磁盘没有真正的物理结构,同样也不能以简单的柱面/磁头/扇区的形式来描述),而是 MS-DOS 用来供分区表使用的几何结构。

通常,缺省时这些都将工作得很好,而且,如果磁盘上只有一个 Linux 操作系统时也不会有任何问题。然而,如果磁盘上还有其它操作系统,那么,用其它操作系统的 fdisk 来生成其自身使用的至少一个分区是比较好的选择。当Linux启动的时侯,它会扫描分区表,并由此推出和其它共存操作系统友好合作所需的(伪)几何结构。

当打印一个分区表时,系统会对分区表进行一次一至性检查。这些检查会验证磁盘几何结构和物理地址的开始、结束、指向和标识,同时在柱面的边界检查分区的开始和结束。(除了第一个分区)

一些版本的 MS-DOS 在创建第一个分区时并不是从柱面边界的开始处,而是从第一柱面的第 2 扇区处开始。从柱面 1 开始的分区不能直接从柱面边界开始,但这未必会造成困难,除非你在你的机器上安装了 OS/2 操作系统。

当执行了对分区表的更新后退出时,程序会运行一次 sync() 和 BLKRRPART ioct1() (从磁盘上重读分区表信息)。以前,在使用完 fdisk 后需要重启系统。我认为现在不需要这样了 -- 太快的重起可能导致未写入磁盘的数据丢失。注意,内核和磁盘硬件都可能缓存数据。

DOS6.x WARNING

DOS6.x 的 FORMAT 命令会在分区的第一扇区的数据区查找一些信息,并认为这些信息比分区表中的信息更可靠。 DOS 的 FORMAT 命令认为 DOS 的 FDISK 命令会在分区变化时自动清除分区数据区的前 512 字节区域。 DOS 的 FORMAT 将查看这些额外的信息,甚至在给出了 /U 这个参数后也是如此。我们认为这是 DOS FORMAT 和 DOS FDISK 的臭虫。

如果你使用 cfdisk 或 fdisk 更改了 DOS 分区表的条目,你必须同时使用 dd 命令将该分区的前512个字节清零,之后,你才能使用 DOS 的 FORMAT 命令对这个分区进行格式化。例如:如果你使用 cfdisk 去创建一个 DOS 分区表项目,即分区 /dev/hda1,然后(在退出 fdisk 或 cfdisk 后重启 Linux 使分区表合法化)你就有必要使用如下命令 “dd if=/dev/ero of=/dev/hda1 bs=512 count=1” 来将分区的前 512 个字节清零。

当你使用 dd 命令时请 务必万分小心 , 由于任何小的打印错误都将造成磁盘数据的失效。

最好你还是使用由操作系统指定的分区工具软件。例如,当你创建 DOS 分区时应使用 DOS FDISK,而创建 Linux 分区时则使用 Linux 的 fdisk 或 cfdisk。

选项

-v
打印 fdisk 的版本信息并退出.
-l
列出指定设备的分区表信息并退出。如果没有给出设备,那么使用那些在 /proc/partitions (如果存在)提到的.
-u
以扇区数而不是以柱面数的形式显示分区表中各分区的信息. -s 分区 将分区的 大小 (单位为块)信息输出到标准输出

#p#

NAME

fdisk - Partition table manipulator for Linux  

SYNOPSIS

fdisk [-u] [-b sectorsize] [-C cyls] [-H heads] [-S sects] device

fdisk -l [-u] [device ...]

fdisk -s partition ...

fdisk -v  

DESCRIPTION

Hard disks can be divided into one or more logical disks called partitions. This division is described in the partition table found in sector 0 of the disk.

In the BSD world one talks about `disk slices' and a `disklabel'.

Linux needs at least one partition, namely for its root file system. It can use swap files and/or swap partitions, but the latter are more efficient. So, usually one will want a second Linux partition dedicated as swap partition. On Intel compatible hardware, the BIOS that boots the system can often only access the first 1024 cylinders of the disk. For this reason people with large disks often create a third partition, just a few MB large, typically mounted on /boot, to store the kernel image and a few auxiliary files needed at boot time, so as to make sure that this stuff is accessible to the BIOS. There may be reasons of security, ease of administration and backup, or testing, to use more than the minimum number of partitions.

fdisk (in the first form of invocation) is a menu driven program for creation and manipulation of partition tables. It understands DOS type partition tables and BSD or SUN type disklabels.

The device is usually one of the following:
 

/dev/hda /dev/hdb /dev/sda /dev/sdb

(/dev/hd[a-h] for IDE disks, /dev/sd[a-p] for SCSI disks, /dev/ed[a-d] for ESDI disks, /dev/xd[ab] for XT disks). A device name refers to the entire disk.

The partition is a device name followed by a partition number. For example, /dev/hda1 is the first partition on the first IDE hard disk in the system. Disks can have up to 15 partitions. See also /usr/src/linux/Documentation/devices.txt.

A BSD/SUN type disklabel can describe 8 partitions, the third of which should be a `whole disk' partition. Do not start a partition that actually uses its first sector (like a swap partition) at cylinder 0, since that will destroy the disklabel.

An IRIX/SGI type disklabel can describe 16 partitions, the eleventh of which should be an entire `volume' partition, while the ninth should be labeled `volume header'. The volume header will also cover the partition table, i.e., it starts at block zero and extends by default over five cylinders. The remaining space in the volume header may be used by header directory entries. No partitions may overlap with the volume header. Also do not change its type and make some file system on it, since you will lose the partition table. Use this type of label only when working with Linux on IRIX/SGI machines or IRIX/SGI disks under Linux.

A DOS type partition table can describe an unlimited number of partitions. In sector 0 there is room for the description of 4 partitions (called `primary'). One of these may be an extended partition; this is a box holding logical partitions, with descriptors found in a linked list of sectors, each preceding the corresponding logical partitions. The four primary partitions, present or not, get numbers 1-4. Logical partitions start numbering from 5.

In a DOS type partition table the starting offset and the size of each partition is stored in two ways: as an absolute number of sectors (given in 32 bits) and as a Cylinders/Heads/Sectors triple (given in 10+8+6 bits). The former is OK - with 512-byte sectors this will work up to 2 TB. The latter has two different problems. First of all, these C/H/S fields can be filled only when the number of heads and the number of sectors per track are known. Secondly, even if we know what these numbers should be, the 24 bits that are available do not suffice. DOS uses C/H/S only, Windows uses both, Linux never uses C/H/S.

If possible, fdisk will obtain the disk geometry automatically. This is not necessarily the physical disk geometry (indeed, modern disks do not really have anything like a physical geometry, certainly not something that can be described in simplistic Cylinders/Heads/Sectors form), but is the disk geometry that MS-DOS uses for the partition table.

Usually all goes well by default, and there are no problems if Linux is the only system on the disk. However, if the disk has to be shared with other operating systems, it is often a good idea to let an fdisk from another operating system make at least one partition. When Linux boots it looks at the partition table, and tries to deduce what (fake) geometry is required for good cooperation with other systems.

Whenever a partition table is printed out, a consistency check is performed on the partition table entries. This check verifies that the physical and logical start and end points are identical, and that the partition starts and ends on a cylinder boundary (except for the first partition).

Some versions of MS-DOS create a first partition which does not begin on a cylinder boundary, but on sector 2 of the first cylinder. Partitions beginning in cylinder 1 cannot begin on a cylinder boundary, but this is unlikely to cause difficulty unless you have OS/2 on your machine.

A sync() and a BLKRRPART ioctl() (reread partition table from disk) are performed before exiting when the partition table has been updated. Long ago it used to be necessary to reboot after the use of fdisk. I do not think this is the case anymore - indeed, rebooting too quickly might cause loss of not-yet-written data. Note that both the kernel and the disk hardware may buffer data.

DOS 6.x WARNING

The DOS 6.x FORMAT command looks for some information in the first sector of the data area of the partition, and treats this information as more reliable than the information in the partition table. DOS FORMAT expects DOS FDISK to clear the first 512 bytes of the data area of a partition whenever a size change occurs. DOS FORMAT will look at this extra information even if the /U flag is given -- we consider this a bug in DOS FORMAT and DOS FDISK.

The bottom line is that if you use fdisk to change the size of a DOS partition table entry, then you must also use dd to zero the first 512 bytes of that partition before using DOS FORMAT to format the partition. For example, if you were using disk to make a DOS partition table entry for /dev/hda1, then (after exiting fdisk and rebooting Linux so that the partition table information is valid) you would use the command "dd if=/dev/zero of=/dev/hda1 bs=512 count=1" to zero the first 512 bytes of the partition.

BE EXTREMELY CAREFUL if you use the dd command, since a small typo can make all of the data on your disk useless.

For best results, you should always use an OS-specific partition table program. For example, you should make DOS partitions with the DOS FDISK program and Linux partitions with the Linux fdisk program.

OPTIONS

-b sectorsize
Specify the sector size of the disk. Valid values are 512, 1024, or 2048. (Recent kernels know the sector size. Use this only on old kernels or to override the kernel's ideas.)
-C cyls
Specify the number of cylinders of the disk. I have no idea why anybody would want to do so.
-H heads
Specify the number of heads of the disk. (Not the physical number, of course, but the number used for partition tables.) Reasonable values are 255 and 16.
-S sects
Specify the number of sectors per track of the disk. (Not the physical number, of course, but the number used for partition tables.) A reasonable value is 63.
-l
List the partition tables for the specified devices and then exit. If no devices are given, those mentioned in /proc/partitions (if that exists) are used.
-u
When listing partition tables, give sizes in sectors instead of cylinders.
-s partition
The size of the partition (in blocks) is printed on the standard output.
-v
Print version number of fdisk program and exit.
责任编辑:韩亚珊 来源: CMPP.net
相关推荐

2011-08-24 16:48:36

man中文man

2011-08-15 10:21:09

man中文man

2011-08-11 16:11:49

at中文man

2011-08-25 10:21:56

man.conf中文man

2011-08-11 15:03:21

ACCESS中文man

2011-08-16 10:59:16

pwconv中文man

2011-08-18 19:02:43

environ中文man

2011-08-25 17:43:07

snprintf中文man

2011-08-19 18:30:52

ipc中文man

2011-08-24 15:35:52

hier中文man

2011-08-25 17:18:07

putc中文man

2011-08-15 13:53:19

stat中文man

2011-08-16 10:10:58

setup中文man

2011-08-25 15:24:31

execlp中文man

2011-08-15 18:06:07

restore中文man

2011-08-24 17:26:35

reindex中文man

2011-08-25 16:55:26

gets中文man

2011-08-15 15:45:04

xpdf中文man

2011-08-24 17:06:42

NOTIFY中文man

2011-08-25 15:47:06

fopen中文man
点赞
收藏

51CTO技术栈公众号