fdisk [-uc] [-b sectorsize] [-C cyls] [-H heads] [-S sects] device
fdisk -l [-u] [device...]
fdisk -s partition...
fdisk -v
fdisk -h
选件
-b sectorsize
|
指定磁盘的扇区大小。有效值是512,1024,2048或4096。最近的内核知道扇区大小。仅在旧内核上使用此功能,或覆盖内核的思想。从util-linux-2.17开始,fdisk区分逻辑扇区大小和物理扇区大小。此选项更改两个扇区大小来sectorsize。
|
-c[=mode]
|
指定兼容模式“ dos ”或“ nondos ”。默认为非DOS模式。为了向后兼容,可以使用不带mode参数的选项。在这种情况下,将使用默认值。请注意,可选模式参数不能与-c选项用空格分隔,正确的格式例如是' -c = dos '。
|
-C cyls
|
指定磁盘的柱面数。这是一件很奇怪的事情,但是如果需要的话,这个选项就可以完成。
|
-H heads
|
指定磁盘的磁头数。不是物理编号,而是用于分区表的编号。合理的值为255和16。
|
-S sects
|
指定磁盘每个磁道的扇区数。不是物理编号,而是用于分区表的编号。合理值为63。
|
-h
|
打印帮助,然后退出。
|
-l
|
列出指定设备的分区表,然后退出。如果未提供任何设备,则使用/ proc / partitions中提到的设备(如果存在)。
|
-u[=unit]
|
列出分区表时,请在“ 扇区 ”或“ 柱面 ”中显示大小。默认设置是显示扇区大小。为了向后兼容,可以使用不带units参数的选项。在这种情况下,将使用默认值。注意,可选的单位参数不能与-u选项用空格分隔;正确的格式例如是' -u = cylinders '。
|
-v
|
打印版本信息,然后退出。
|
设备
设备通常是/ dev / sda,/ dev / sdb等。设备名称指的是整个磁盘。没有libata(Linux内核内部用于支持ATA主机控制器和设备的库)的旧系统会在IDE和SCSI磁盘之间产生差异。在这种情况下,设备名称将为/ dev / hd *(IDE)或/ dev / sd *(SCSI)。
分区是设备名称,后跟分区号。例如,/ dev / sda1是系统中第一个硬盘上的第一个分区。
磁盘标签
一个BSD / SUN类型的磁盘标签可以描述8个分区,其中第三个应该是“整个磁盘”分区。不要在柱面0处启动实际上使用其第一个扇区的分区(例如交换分区),因为这会破坏disklabel。
IRIX / SGI类型的磁盘标签可以描述16个分区,其中的第十一个分区应该是整个“卷”分区,而第九个分区应该标记为“卷标头”。卷标头还将覆盖分区表,即,它从块零开始,默认情况下扩展到五个柱面。卷标头中的剩余空间可由标头目录条目使用。卷头不能有任何分区重叠。另外,请勿更改其类型或在其上创建一些文件系统,因为这样会丢失分区表。仅当在IRIX / SGI计算机上的Linux或Linux下的IRIX / SGI磁盘上使用Linux时,才使用这种类型的标签。
DOS类型的分区表可以描述无限数量的分区。在扇区0中,有描述4个分区(称为“主要”)的空间。其中之一可以是扩展分区。这是一个保存逻辑分区的盒子,在链接的扇区列表中找到描述符,每个描述符位于相应的逻辑分区之前。存在或不存在的四个主分区的编号为1-4。逻辑分区从5开始编号。
在DOS类型的分区表中,起始偏移量和每个分区的大小以两种方式存储:作为扇区的绝对数量(以32位给定),以及作为圆柱/磁头/扇区三重(以10 + 8给定) +6位)。前者还可以;如果使用512字节的扇区,则最多可以工作2 TB。后者有两个问题。首先,仅当已知磁头的数量和每个磁道的扇区数时才能填充这些C / H / S字段。其次,即使我们知道这些数字应该是多少,可用的24位也不足够。DOS仅使用C / H / S,Windows同时使用,Linux从不使用C / H / S。
如果可能,fdisk将自动获取磁盘几何。这不一定是物理磁盘的几何形状(实际上,现代磁盘实际上并没有像物理几何形状那样的东西,当然也不能以简单的Cylinders / Heads / Sectors形式描述),而是MS-DOS的磁盘几何形状用于分区表。
通常,默认情况下一切正常,并且如果Linux是磁盘上的唯一系统,则没有问题。但是,如果必须与其他操作系统共享磁盘,则通常最好让来自另一个操作系统的fdisk至少构成一个分区。当Linux启动时,它会查看分区表,并尝试推断出与其他系统良好协作所需的(伪)几何形状。
每当打印出分区表时,都会对分区表条目执行一致性检查。此检查将验证物理和逻辑起点和终点是否相同,并且每个分区都在圆柱边界上开始和结束(第一个分区除外)。某些版本的MS-DOS创建的第一个分区不是从圆柱边界开始,而是在第一个圆柱的扇区2上开始。从柱面1开始的分区不能从柱面边界开始,但是除非您的计算机上装有OS / 2,否则这不太可能引起困难。
在更新分区表时,在退出之前执行sync()和ioctl(BLKRRPART)(从磁盘重新读取分区表)。很久以前,使用fdisk后必须重新启动。不再需要;实际上,应该注意的是内核和磁盘硬件都可以缓冲数据,因此在使用fdisk分区后立即重新引导可能是不可取的。
DOS 6.x警告
DOS 6.x FORMAT命令在分区的数据区域的第一个扇区中查找某些信息,并将此信息视为比分区表中的信息更可靠。DOS FORMAT期望DOS FDISK会在大小发生变化时清除分区数据区域的前512个字节。即使给出了/ U标志,DOS FORMAT也会查看这些额外信息:这被认为是DOS FORMAT和DOS FDISK中的错误。
底线是,如果您使用cfdisk或fdisk更改DOS分区表条目的大小,则在使用DOS FORMAT格式化分区之前,还必须使用dd将该分区的前512个字节清零。例如,如果使用cfdisk为/ dev / sda1创建DOS分区表条目,则(退出fdisk或cfdisk并重新引导Linux以使分区表信息有效之后),可以使用命令“ dd if = / dev / zero of = / dev / sda1 bs = 512 count = 1 “将分区的前512个字节清零。
警告
如果您使用 dd命令,请格外小心,小的错字可能会使磁盘上的所有数据失效。
为了获得最佳结果,应始终使用特定于操作系统的分区表程序。例如,您应使用DOS FDISK程序创建DOS分区,并使用Linux fdisk或Linux cfdisk程序创建Linux分区。
fdisk [-uc] [-b sectorsize] [-C cyls] [-H heads] [-S sects] device
fdisk -l [-u] [device...]
fdisk -s partition...
fdisk -v
fdisk -h
Options
-b sectorsize
|
Specify the sector size of the disk. Valid values are 512, 1024, 2048 or 4096. Recent kernels know the sector size. Use this only on old kernels or to override the kernel's ideas. Since util-linux-2.17, fdisk differentiates between logical and physical sector size. This option changes both sector sizes to sectorsize.
|
-c[=mode]
|
Specify the compatibility mode, 'dos' or 'nondos'. The default is non-DOS mode. For backward compatibility, it is possible to use the option without the mode argument; in that case, the default is used. Note that the optional mode argument cannot be separated from the -c option by a space, the correct form is, for example, '-c=dos'.
|
-C cyls
|
Specify the number of cylinders of the disk. This would be a very strange thing to want to do, but if so desired, this option will get it done.
|
-H heads
|
Specify the number of heads of the disk. Not the physical number, 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, but the number used for partition tables. A reasonable value is 63.
|
-h
|
Print help and then exit.
|
-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[=unit]
|
When listing partition tables, show sizes in 'sectors' or in 'cylinders'. The default is to show sizes in sectors. For backward compatibility, it is possible to use the option without the units argument; in this case, the default is used. Note that the optional unit argument cannot be separated from the -u option by a space; the correct form is, for example, '-u=cylinders'.
|
-v
|
Print version information, and exit.
|
Devices
The device is usually /dev/sda, /dev/sdb, etc. A device name refers to the entire disk. Old systems without libata (a library used inside the Linux kernel to support ATA host controllers and devices) make a difference between IDE and SCSI disks. In such cases the device name will be /dev/hd* (IDE) or /dev/sd* (SCSI).
The partition is a device name followed by a partition number. For example, /dev/sda1 is the first partition on the first hard disk in the system.
Disk labels
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 or make some filesystem 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 problems. First, these C/H/S fields can be filled only when the number of heads and the number of sectors per track are known. And second, 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 it 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 each 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 an ioctl(BLKRRPART) (reread partition table from disk) are performed before exiting when the partition table is updated. Long ago it used to be necessary to reboot after the use of fdisk. This is no longer required; in fact one should note that both the kernel and the disk hardware may buffer data, so rebooting immediately after partitioning with fdisk may be inadvisable.
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: this is considered to be a bug in DOS FORMAT and DOS FDISK.
The bottom line is that if you use cfdisk or 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 cfdisk to make a DOS partition table entry for /dev/sda1, then (after exiting fdisk or cfdisk and rebooting Linux so that the partition table information is valid) you would use the command "dd if=/dev/zero of=/dev/sda1 bs=512 count=1" to zero the first 512 bytes of the partition.
Warning
BE EXTREMELY CAREFUL if you use the dd command, 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 or Linux cfdisk program.