cfdisk (显示有关磁盘分区表的信息)

小猪老师 发表于 2020-07-20 11:26
浏览次数:
在手机上阅读

在Linux操作系统上,cfdisk命令操作或显示有关磁盘分区表的信息。 它整合了fdisk的所有功能,但是有一个基于文本的“图形”界面。

查看英文版

目录

1 cfdisk 运行系统环境

2 cfdisk 描述

3 cfdisk 语法

4 cfdisk 指令

5 命令行选项

6 cfdisk 示例

cfdisk 运行系统环境

Unix&Linux

cfdisk 描述

cfdisk是用于对任何硬盘驱动器进行分区的程序。设备参数的典型值为:

  • / dev / hda [default]
  • / dev / hdb
  • / dev / sda
  • / dev / sdb
  • / dev / sdc
  • / dev / sdd

要写入分区表,cfdisk需要磁盘的一种“几何形状”:“磁头”的数量和“每个磁道的扇区”的数量。Linux不使用任何几何体,因此,如果其他操作系统无法访问该磁盘,则可以安全地接受cfdisk为您选择的默认值。cfdisk使用的几何结构如下:首先检查分区表,以查看更改它的上一个程序使用了什么几何结构。如果分区表为空,或包含垃圾,或未指向一致的几何图形,则会要求内核提供建议。如果没有任何效果,则假定255个磁头和63个扇区/磁道。几何图形可以在命令行或使用“ g ”命令。在对空的大型现代磁盘进行分区时,最好选择255个磁头和63个扇区/磁道。由于cfdisk知道磁盘大小,因此无需设置柱面数。

接下来,cfdisk尝试从磁盘驱动器读取当前分区表。如果无法找出分区表,则会显示错误,程序将退出。这也可能是由于几何信息不正确引起的,并且可以在命令行上覆盖。解决此问题的另一种方法是使用-z选项。此选项将忽略磁盘上的分区表。

主显示由上至下四个部分组成:标题,分区,命令行和警告行。标头包含程序名称和版本号,后跟磁盘驱动器及其几何形状。分区部分始终显示当前分区表。命令行是输入命令和文本的地方。可用命令通常显示在括号中。警告行通常为空,除非有重要信息要显示。当前分区以反向视频突出显示(如果提供了-a选项,则以箭头突出显示)。所有特定于分区的命令都适用于当前分区。

分区部分中分区表的格式从左到右为:名称,标志,分区类型,文件系统类型和大小。该名称是分区设备名称。标志可以是Boot,它指定可引导分区,也可以是NC,其代表“与DOS或OS / 2不兼容”。DOS,OS / 2和其他操作系统可能需要磁盘上第一个分区的第一个扇区,而所有逻辑分区都必须从第二个磁头开始。这浪费了第一个磁头的第一个磁道的第二个到最后一个扇区(第一个扇区由分区表本身获取)。cfdisk使您可以使用最大化命令(m)恢复这些“丢失”的扇区。

关于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 / hda1创建DOS分区表条目,则(退出fdisk或cfdisk并重新引导Linux以使分区表信息有效之后),您将使用命令。

dd if = / dev / zero of = / dev / hda1 bs = 512 count = 1 

将分区的前512个字节清零。注意:

警告

使用dd命令时,小的错字可能会使磁盘上的所有数据失效。

为了获得最佳结果,应始终使用特定于操作系统的分区表程序。例如,您应该使用DOS FDISK程序创建DOS分区,并使用Linux fdisk或Linux cfdisk程序创建Linux分区。

cfdisk is a program for partitioning any hard drive. Typical values of the device argument are:

  • /dev/hda [default]
  • /dev/hdb
  • /dev/sda
  • /dev/sdb
  • /dev/sdc
  • /dev/sdd

To write the partition table, cfdisk needs something called the "geometry" of the disk: the number of "heads" and the number of "sectors per track". Linux does not use any geometry, so if the disk will not be accessed by other operating systems, you can safely accept the defaults that cfdisk chooses for you. The geometry used by cfdisk is found as follows: first the partition table is examined, to see what geometry was used by the previous program that changed it. If the partition table is empty, or contains garbage, or does not point at a consistent geometry, the kernel is asked for advice. If nothing works, 255 heads and 63 sectors/track is assumed. The geometry can be overridden on the command line or by use of the "g" command. When partitioning an empty large modern disk, picking 255 heads and 63 sectors/track is always a good idea. There is no need to set the number of cylinders since cfdisk knows the disk size.

Next, cfdisk tries to read the current partition table from the disk drive. If it is unable to figure out the partition table, an error is displayed and the program will exit. This might also be caused by incorrect geometry information, and can be overridden on the command line. Another way around this problem is with the -z option. This option ignores the partition table on the disk.

The main display is composed of four sections, from top to bottom: the header, the partitions, the command line and a warning line. The header contains the program name and version number followed by the disk drive and its geometry. The partitions section always displays the current partition table. The command line is the place where commands and text are entered. The available commands are usually displayed in brackets. The warning line is usually empty except when there is important information to be displayed. The current partition is highlighted with reverse video (or an arrow if the -a option is given). All partition specific commands apply to the current partition.

The format of the partition table in the partitions section is, from left to right: Name, Flags, Partition Type, Filesystem Type and Size. The name is the partition device name. The flags can be Boot, which designates a bootable partition, or NC, which stands for "Not Compatible with DOS or OS/2". DOS, OS/2, and possibly other operating systems require the first sector of the first partition on the disk and all logical partitions to begin on the second head. This wastes the second through the last sector of the first track of the first head (the first sector is taken by the partition table itself). cfdisk allows you to recover these "lost" sectors with the maximize command (m).

A warning about DOS 6.x

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 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/hda1, 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/hda1 bs=512 count=1

to zero the first 512 bytes of the partition. Note:

When using the dd command, a small typo can make all 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.

fdisk和DOS的某些早期版本创建的所有分区的扇区数已经最大化。有关更多信息,请参见下面的最大化命令。分区类型可以是Primary或Logical之一。对于驱动器上未分配的空间,分区类型也可以是Pri / Log或空(如果空间不可用)。文件系统类型部分显示分区上使用的文件系统的名称(如果已知)。如果未知,则未知和十六进制显示文件系统类型的值。当磁盘驱动器的某些部分无法使用时(因为使用了所有主分区),就会发生特殊情况。检测到此错误后,文件系统类型将显示为Unusable。size字段显示分区的大小(以兆字节为单位)(默认情况下)。它还可以显示扇区和圆柱的大小(请参见下面的更改单位命令)。如果大小后出现星号(*),则表示该分区未在圆柱边界上对齐。

fdisk and some early versions of DOS create all partitions with the number of sectors already maximized. For more information, see the maximize command below. The partition type can be one of Primary or Logical. For unallocated space on the drive, the partition type can also be Pri/Log, or empty (if the space is unusable). The filesystem type section displays the name of the filesystem used on the partition, if known. If it is unknown, then Unknown and the hex value of the filesystem type are displayed. A special case occurs when there are sections of the disk drive that cannot be used (because all the primary partitions are used). When this is detected, the filesystem type is displayed as Unusable. The size field displays the size of the partition in megabytes (by default). It can also display the size in sectors and cylinders (see the change units command below). If an asterisk (*) appears after the size, this means that the partition is not aligned on cylinder boundaries.

查看英文版

查看中文版

cfdisk 语法

cfdisk [-agvz] [-c cylinders] [-h heads] [-s sectors-per-track]
       [-P opt] [device]
cfdisk [-agvz] [-c cylinders] [-h heads] [-s sectors-per-track]
       [-P opt] [device]

查看英文版

查看中文版

cfdisk 指令

可以通过按所需的键输入cfdisk命令(不需要该命令后按Enter)。以下是可用命令的列表:

b

切换当前分区的可启动标志。这使您可以选择驱动器上可引导的主分区。

d

删除当前分区。此命令会将当前分区转换为可用空间,并将其与当前分区周围所有可用空间合并。已经标记为可用空间或标记为不可用的分区无法删除。

g

更改磁盘的几何形状(圆柱,磁头或每磁道扇区)。

警告:此选项仅应由知道自己在做什么的人使用。也可以使用命令行选项来更改磁盘的几何形状。在更改磁盘几何图形命令行上时,您可以选择更改圆柱( c),磁头( h)和每磁道的扇区( s)。默认值将在提示下打印,您可以通过按Enter键来接受该默认值,或者可以通过按 Esc键退出而不进行任何更改。如果要更改默认值,请输入所需的值,然后按Enter。更改的磁盘参数值直到返回主菜单(通过按 Enter或 Esc键)才会生效。在更改磁盘几何图形命令行上)。如果更改几何形状以使磁盘看起来更大,则会在磁盘末尾添加额外的扇区作为可用空间。如果磁盘看起来较小,则会删除新的最后一个扇区以外的分区,并使驱动器上的最后一个分区(或驱动器末端的可用空间)在新的最后一个扇区处结束。

h

打印帮助屏幕。

m

最大化当前分区的磁盘使用率。此命令将恢复分区表和分区开头之间的未使用空间,但是以使分区与DOS,OS / 2和其他操作系统不兼容为代价。此选项将在最大磁盘使用率和DOS,OS / 2等兼容磁盘使用率之间切换。创建分区时的默认设置是创建DOS,OS / 2等兼容分区。

n

从可用空间创建新分区。如果分区类型是PrimaryLogical,则会创建该类型的分区,但是如果分区类型是Pri / Log,则会提示您输入要创建的类型。意识到:

  1. 主分区只有四个插槽
  2. 由于只能有一个扩展分区,其中包含所有逻辑驱动器,因此所有逻辑驱动器必须是连续的(中间没有主分区)。

cfdisk next提示您输入要创建的分区的大小。默认大小(等于当前分区的整个可用空间)以兆字节显示。您可以按Enter键接受默认大小,也可以在提示时输入其他大小。cfdisk接受大小输入,以兆字节(M)[这是默认设置],千字节(K),柱面(C)和扇区(S)为单位,方法是输入数字,紧随其后的是(M,K,C或S)。如果该分区填满了可用的可用空间,则会创建该分区,并返回到主命令行。否则,可以在可用空间的开头或结尾创建分区,并且cfdisk会要求您选择将分区放置在何处。创建分区后,如果使用了所有主分区,cfdisk会自动调整其他分区的分区类型。

p

将分区表打印到屏幕或文件中。您可以选择不同的分区格式:

r

原始数据格式(正是要写入磁盘的格式)。

s

分区顺序格式的分区表。

t

原始格式的分区表。

如果选择了写入命令,则原始数据格式将打印将要写入磁盘的扇区。首先,打印主分区表,然后打印与每个逻辑分区关联的分区表。数据以十六进制字节逐字节打印,每行16字节。

扇区顺序格式的分区表将打印按扇区号排序的分区表。字段从左到右分别是分区号,分区类型,第一个扇区,最后一个扇区,从分区的第一个扇区到数据开头的偏移量,分区的长度,文件系统类型(括号中为十六进制值)和标志(括号中为十六进制值)。除了主分区和逻辑分区之外,还会打印第一个逻辑分区之前的空闲和不可用空间,并打印扩展分区。

如果分区没有在圆柱边界上开始或结束,或者如果分区长度不能被圆柱尺寸整除,则在未对齐的扇区号/计数之后将打印星号(*)。这通常表明分区是由操作系统创建的,该操作系统要么未将分区与柱面边界对齐,要么使用了不同的磁盘几何信息。如果您知道其他操作系统的磁盘几何,则可以使用change geometry命令(g)输入几何信息。

对于磁盘上的第一个分区以及所有逻辑分区,如果从分区开始的偏移量不等于每个磁道的扇区数(即,数据不在第一个磁头上开始),则用数字符号(#)在偏移量之后打印。对于其余分区,如果偏移量不为零,则将在偏移量后打印一个数字符号。这对应于主显示屏分区部分中的NC标志。

原始格式的分区表将打印按分区号排序的分区表。它将遗漏所有可用且不可用的空间。字段从左到右分别是分区号,标志(十六进制),起始磁头,扇区和柱面,文件系统ID(十六进制),结束磁头,扇区和柱面,起始分区中的扇区和分区中的扇区数。该表中的信息可以直接转换为原始数据格式。

分区表条目只有10位可用于表示起始和结束柱面。因此,当绝对起始(结束)扇区号大于1023时,将打印起始(结束)磁头,扇区和柱面的最大值。这是OS / 2使用的方法,因此可以解决与OS / 2的fdisk不在此格式时重写分区表有关的问题。由于Linux和OS / 2使用绝对扇区数,因此不使用起始和结束磁头,扇区和柱面中的值。

q

退出程序。该命令将退出程序,而不会将任何数据写入磁盘。

t

更改文件系统类型。默认情况下,新分区被创建为Linux分区,但是由于cfdisk可以为其他操作系统创建分区,因此更改分区类型允许您输入所需文件系统的十六进制值。显示已知文件系统类型的列表。您可以在提示符下输入文件系统类型,或接受默认的文件系统类型[ Linux ]。

u

更改分区大小显示的单位。它将旋转兆字节,扇区和柱面。

W

将分区表写入磁盘(必须输入大写的W)。由于这可能会破坏磁盘上的数据,因此您必须输入“ yes ”或“ no ” 来确认或拒绝写入。如果输入“ yes ”,则cfdisk会将分区表写入磁盘,并告诉内核从磁盘重新读取分区表。分区表的重新读取在某些情况下不起作用,例如对于设备映射器设备。在特定情况下,您需要通过partprobe,kpartx或重新引导系统来通知内核有关新分区的信息。

UpArrow, DownArrow

将光标移动到上一个或下一个分区。如果分区数量超出屏幕上显示的数量,则可以通过在屏幕上显示的最后一个(第一个)分区上向下(向上)移动来显示下一个(上一个)分区集。

Ctrl-L

重新绘制屏幕。万一出了什么问题而又看不懂任何内容,则可以从主命令行刷新屏幕。

打印帮助屏幕。

所有命令都可以使用大写或小写字母输入(W rites 除外)。在子菜单中或提示输入文件名时,您可以按Esc键返回主命令行。

cfdisk commands can be entered by pressing the desired key (pressing Enter after the command is not necessary). Here is a list of the available commands:

b

Toggle bootable flag of the current partition. This allows you to select which primary partition is bootable on the drive.

d

Delete the current partition. This command will convert the current partition into free space and merge it with any free space immediately surrounding the current partition. A partition already marked as free space or marked as unusable cannot be deleted.

g

Change the disk geometry (cylinders, heads, or sectors-per-track).

WARNING: This option should only be used by people who know what they are doing. A command line option is also available to change the disk geometry. While at the change disk geometry command line, you can choose to change cylinders (c), heads (h), and sectors per track (s). The default value will be printed at the prompt which you can accept by pressing the Enter key, or you can exit without changes by pressing the Esc key. If you want to change the default value, enter the desired value and press Enter. The altered disk parameter values do not take effect until you return to the main menu (by pressing Enter or Esc at the change disk geometry command line). If you change the geometry such that the disk appears larger, the extra sectors are added at the end of the disk as free space. If the disk appears smaller, the partitions that are beyond the new last sector are deleted and the last partition on the drive (or the free space at the end of the drive) is made to end at the new last sector.

h

Print the help screen.

m

Maximize disk usage of the current partition. This command will recover the unused space between the partition table and the beginning of the partition, but at the cost of making the partition incompatible with DOS, OS/2, and possibly other operating systems. This option will toggle between maximal disk usage and DOS, OS/2, etc. compatible disk usage. The default when creating a partition is to create DOS, OS/2, etc. compatible partitions.

n

Create new partition from free space. If the partition type is Primary or Logical, a partition of that type will be created, but if the partition type is Pri/Log, you will be prompted for the type you want to create. Be aware that:

  1. there are only four slots available for primary partitions
  2. since there can be only one extended partition, which contains all the logical drives, all the logical drives must be contiguous (with no intervening primary partition).

cfdisk next prompts you for the size of the partition you want to create. The default size, equal to the entire free space of the current partition, is displayed in megabytes. You can either press the Enter key to accept the default size or enter a different size at the prompt. cfdisk accepts size entries in megabytes (M) [this is the default], kilobytes (K), cylinders (C) and sectors (S) by entering the number immediately followed by one of (M, K, C or S). If the partition fills the free space available, the partition is created and you are returned to the main command line. Otherwise, the partition can be created at the beginning or the end of the free space, and cfdisk will ask you to choose where to place the partition. After the partition is created, cfdisk automatically adjusts the other partitions' partition types if all the primary partitions are used.

p

Print the partition table to the screen or to a file. There are different formats for the partition that you can choose from:

r

Raw data format (exactly what would be written to disk).

s

Partition table in sector order format.

t

Partition table in raw format.

The raw data format will print the sectors that would be written to disk if a write command is selected. First, the primary partition table is printed, followed by the partition tables associated with each logical partition. The data is printed in hex byte by byte with 16 bytes per line.

The partition table in sector order format will print the partition table ordered by sector number. The fields, from left to right, are the number of the partition, the partition type, the first sector, the last sector, the offset from the first sector of the partition to the start of the data, the length of the partition, the filesystem type (with the hex value in parenthesis), and the flags (with the hex value in parenthesis). In addition to the primary and logical partitions, free and unusable space is printed and the extended partition is printed before the first logical partition.

If a partition does not start or end on a cylinder boundary or if the partition length is not divisible by the cylinder size, an asterisk (*) is printed after the non-aligned sector number/count. This usually indicates that a partition was created by an operating system that either does not align partitions to cylinder boundaries or that used different disk geometry information. If you know the disk geometry of the other operating system, you could enter the geometry information with the change geometry command (g).

For the first partition on the disk and for all logical partitions, if the offset from the beginning of the partition is not equal to the number of sectors per track (i.e., the data does not start on the first head), a number sign (#) is printed after the offset. For the remaining partitions, if the offset is not zero, a number sign will be printed after the offset. This corresponds to the NC flag in the partitions section of the main display.

The partition table in raw format will print the partition table ordered by partition number. It will leave out all free and unusable space. The fields, from left to right, are the number of the partition, the flags (in hex), the starting head, sector, and cylinder, the filesystem ID (in hex), the ending head, sector, and cylinder, the starting sector in the partition and the number of sectors in the partition. The information in this table can be directly translated to the raw data format.

The partition table entries only have 10 bits available to represent the starting and ending cylinders. Thus, when the absolute starting (ending) sector number is on a cylinder greater than 1023, the maximal values for starting (ending) head, sector, and cylinder are printed. This is the method used by OS/2, and thus fixes the problems associated with OS/2's fdisk rewriting the partition table when it is not in this format. Since Linux and OS/2 use absolute sector counts, the values in the starting and ending head, sector, and cylinder are not used.

q

Quit program. This command will exit the program without writing any data to disk.

t

Change the filesystem type. By default, new partitions are created as Linux partitions, but since cfdisk can create partitions for other operating systems, change partition type allows you to enter the hex value of the filesystem you desire. A list of the know filesystem types is displayed. You can type in the filesystem type at the prompt or accept the default filesystem type [Linux].

u

Change units of the partition size display. It will rotate through megabytes, sectors, and cylinders.

W

Write partition table to disk (must enter an uppercase W). Since this might destroy data on the disk, you must either confirm or deny the write by entering "yes" or "no". If you enter "yes," cfdisk will write the partition table to disk and the tell the kernel to re-read the partition table from the disk. The re-reading of the partition table does not work in some cases, for example for device-mapper devices. In particular case you need to inform kernel about new partitions by partprobe, kpartx or reboot the system.

UpArrow, DownArrow

Move cursor to the previous or next partition. If there are more partitions than can be displayed on a screen, you can display the next (previous) set of partitions by moving down (up) at the last (first) partition displayed on the screen.

Ctrl-L

Redraws the screen. In case something goes wrong and you cannot read anything, you can refresh the screen from the main command line.

?

Print the help screen.

All the commands can be entered with either upper or lowercase letters (except for Writes). When in a sub-menu or at a prompt to enter a file name, you can hit the Esc key to return to the main command line.

查看英文版

查看中文版

命令行选项

-a

使用箭头光标而不是反向视频突出显示当前分区。

-g

不要使用磁盘驱动程序给定的几何图形,而是尝试从分区表中猜测几何图形。

-v

打印版本号和版权。

-z

从零位分区表开始。要重新分区整个磁盘时,此选项很有用。注意:此选项不会将磁盘上的分区表归零;而是,它在不读取现有分区表的情况下启动程序。

-c cylinders,
-h heads,
-s sectors-per-track

覆盖从BIOS读取的每个磁道的柱面数,磁头数和扇区数。如果您的BIOS或适配器不提供此信息,或者提供的信息不正确,请使用以下选项设置磁盘的几何值。

-a

Use an arrow cursor instead of reverse video for highlighting the current partition.

-g

Do not use the geometry given by the disk driver, but try to guess a geometry from the partition table.

-v

Print the version number and Copyright.

-z

Start with zeroed partition table. This option is useful when you want to repartition your entire disk. Note: this option does not zero the partition table on the disk; rather, it starts the program without reading the existing partition table.

-c cylinders,
-h heads,
-s sectors-per-track

Override the number of cylinders, heads, and sectors per track read from the BIOS. If your BIOS or adapter does not supply this information or if it supplies incorrect information, use these options to set the disk geometry values.

查看英文版

查看中文版

cfdisk 示例

sudo cfdisk

使用命令运行cfdisk,以root特权执行该命令

sudo cfdisk

Run cfdisk, using the sudo command to execute the command with root privileges.

查看英文版

查看中文版

其他命令行

cut | cu | csplit | crontab | cpio | continue | compress | col | cmp | cksum | chsh | chroot | chkey | cd | chmod | cp | comm | chown | cal | calendar | clear | chfn | cancel | cat | cc | checkeq | checknr | chgrp |

如此好文,分享给朋友
发表评论
验证码:
评论列表
共0条