sfdisk [options] device
sfdisk -s [partition]
选件
sfdisk接受以下命令行选项:
-v,-- version
|
打印sfdisk的版本号并立即退出。
|
-h,--help
|
打印使用情况消息并立即退出。
|
-T,-- list-types
|
打印识别的类型(系统ID)。
|
-s,-- show-size
|
列出分区的大小。
|
-g,-- show-geometry
|
列出内核对指定磁盘几何形状的想法。
|
-G,-- show-pt-geometry
|
列出通过查看分区表猜测的指示磁盘的几何形状。
|
-l,--list
|
列出设备的分区。
|
-d,-- dump
|
以可用作/ fBsfdisk / fR输入的格式转储设备分区。例如,以下命令序列:
sfdisk -d / dev / hda> hda.out
sfdisk / dev / hda
将纠正OS / 2 fdisk创建的错误的最后一个扩展分区。
|
-V,--verify
|
测试分区是否正确。请参阅上面的第三种调用类型。
|
-i,--increment
|
数字圆柱等,从1而不是0开始。
|
-N number
|
仅更改指示的单个分区。例如,以下sfdisk命令和列出的输入:
sfdisk / dev / hdb -N5
,,, *
将使/ dev / hdb上的第五个分区可启动(“活动”),并且保持不变。(也许第五个分区称为/ dev / hdb5,但是您可以随意调用其他名称,例如“ / my_equipment / disks / 2/5 ”)。
|
-A,--activate number
|
使指示的分区处于活动状态,而所有其他分区则处于非活动状态。
|
-c,--id number[ Id ]
|
如果未提供Id参数:打印指定分区的分区ID。如果存在Id参数:将指示分区的类型(Id)更改为给定值。此选项有两种较长的形式,-- print-id和--change-id。例如:
sfdisk --print-id / dev / hdb 5
6
sfdisk --change-id / dev / hdb 5 83
好
首先报告/ dev / hdb5具有ID 6,然后将其更改为83。
|
-u,-- unit letter
|
解释输入并以字母指定的单位显示输出。此信可以是一个S,C,B或M,这意味着Sectors,C ylinders,B锁和Megabytes,分别。默认为圆柱体,至少在已知几何体的情况下。
|
-x,-- show-extended
|
另外,在输出上列出非主要扩展分区,并在输入上为其提供描述符。
|
-C,--cylinders cylinders
|
指定柱面数,可能会覆盖内核的想法。
|
-H,-- heads heads
|
指定头数,可能会覆盖内核的想法。
|
-S,-- sectors sectors
|
指定扇区数,可能会覆盖内核的想法。
|
-f,--force
|
按我说的去做,即使那是愚蠢的。
|
-q,--quiet
|
禁止显示警告消息。
|
-L,-- Linux
|
不要抱怨与Linux不相关的事情。
|
-D,-- DOS
|
对于DOS兼容性:浪费一点空间。更精确地讲:如果一个分区不能包含扇区0,例如,因为它是设备的MBR,或者包含扩展分区的分区表,则sfdisk将使其开始下一个扇区。但是,给出此选项后,它会跳到下一个音轨的开头,例如,像某些特定版本的DOS那样,浪费了33个扇区(在34个扇区/音轨的情况下)。某些磁盘管理器和引导加载程序(例如OSBS,但不是LILO或OS / 2引导管理器)也位于此空白空间中,因此,如果您使用一个,则可能需要此选项。
|
-E,-- DOS-extended
|
取“内部”扩展分区的起始扇区号为相对于外部分区的起始柱体边界(如DOS的某些版本),而不是相对于实际的起始扇区(如Linux)。这里存在差异的事实意味着,如果DOS和Linux应该以相同的方式解释分区表,则应始终让扩展分区从圆柱边界开始。当然,只有知道DOS将用于此磁盘的几何图形时,才能知道圆柱边界在哪里。
|
--IBM,--leave-last
|
某些IBM诊断程序假定它们可以使用磁盘上的最后一个柱面进行磁盘测试。如果您认为您可能曾经运行过此类程序,请使用此选项来告诉sfdisk它不应分配最后一个柱面。有时最后一个柱面包含一个坏扇区表。
|
-n
|
经历所有动作,但实际上不写入磁盘。
|
-R,--re-read
|
仅执行BLKRRPART ioctl(以使内核重新读取分区表)。这对于提前检查最终的BLKRRPART是否成功以及在您手动更改分区表(例如,使用备份中的dd)时很有用。如果内核发出错误消息(“设备正忙于重新验证(使用= 2)”),则仍然有设备在使用该设备,并且您仍然必须卸载某些文件系统,或者说要交换到某些交换分区。
|
--no-reread
|
在开始对磁盘进行重新分区时,sfdisk会检查该磁盘是否未安装或正在用作交换设备,如果已安装,则拒绝继续。此选项禁止测试。另一方面,即使该测试失败,-f选项也会强制sfdisk继续运行。
|
--in-order
|
这是一个危险的选择。尚未记录。
|
--not-in-order
|
这是一个危险的选择。尚未记录。
|
--inside-outer
|
这是一个危险的选择。影响链接顺序。
|
--not-inside-outer
|
这是一个危险的选择。影响链接顺序。
|
--nested
|
这是一个危险的选择。每个分区都包含在周围的分区中,并且彼此不相交。
|
-chained
|
这是一个危险的选择。每个数据分区都包含在周围的分区中,并且与所有其他分区不相交,但是扩展分区可能位于外部(在all_logicals_inside_outermost_extended允许的范围内)。
|
--onesector
|
这是一个危险的选择。所有数据分区都是互不相交的;扩展分区每个仅使用一个扇区(也许最外面的一个除外)。
|
-O file
|
在写入新分区之前,将要覆盖的扇区输出到文件(希望文件驻留在另一个磁盘或软盘上)。
|
-I file
|
使用不幸的sfdisk命令销毁文件系统后,如果仅使用-O标志保存了旧情况,便能够恢复原来的情况。
|
技术细节和背景理论
磁盘的块0(主引导记录)除其他外还包含四个分区描述符。此处描述的分区称为主分区。
分区描述符具有6个字段:
struct partition {
unsigned char bootable; /* 0 or 0x80 */
hsc begin_hsc;
unsigned char id;
hsc end_hsc;
unsigned int starting_sector;
unsigned int nr_of_sectors;
}
两个hsc字段指示分区开始和结束的磁头,扇区和柱面。由于每个hsc字段仅占用3个字节,因此仅24位可用,不足以用于大磁盘(例如> 8 GB)。实际上,由于浪费的表示方式(使用一个字节作为磁头数,通常为16),问题已经从0.5 GB开始。但是,Linux不使用这些字段,只有在启动Linux之前的引导时才会出现问题。有关更多详细信息,请参见LILO文档。
每个分区都有一个类型,即其“ Id”,如果此类型为5或f(“扩展分区”),则该分区的起始扇区将再次包含4个分区描述符。MSDOS仅使用其中的前两个:第一个是实际的数据分区,第二个再次是扩展分区(或为空)。这样一来,便得到了一连串的扩展分区。其他操作系统的约定略有不同。Linux还接受与5和f等效的类型85-如果希望在Linux下具有超过1024柱面边界的扩展分区而不使用DOS FDISK,这将很有用。挂。如果没有充分的理由,则应仅使用5,这是其他系统可以理解的。
非主要或扩展的分区称为逻辑分区。通常,不能从逻辑分区启动(因为查找逻辑分区的过程不仅仅是查看MBR,而是涉及更多的过程)。请注意,在扩展分区中,仅使用ID和开始。关于在其他字段中编写什么内容,有各种约定。人们不应该尝试使用扩展分区进行数据存储或交换。
输入格式
sfdisk读取以下形式的行
每行填充一个分区描述符。
字段之间用空格隔开,或者用逗号或分号隔开,可能后跟空格;初始和尾随空白将被忽略。数字可以是八进制,十进制或十六进制;默认为十进制。如果字段不存在或为空,则使用默认值。
所述部分可以(并且可能应该)被省略-sfdisk从计算他们和和作为由内核给定或指定使用的磁盘几何-H,-S,-C标志。
可引导指定为[ * | - ],默认情况下不可引导。对于Linux,此字段的值无关紧要-当Linux运行时,它已经被引导-但对于某些引导加载程序和其他操作系统可能起作用。例如,当有几个主要的DOS分区时,DOS将C:分配给其中的第一个可引导分区。
Id以十六进制给出,不带0x前缀,或者为[ E | S | L | X ],其中L(LINUX_NATIVE(83)是默认值,S是LINUX_SWAP(82),E是EXTENDED_PARTITION(5),X是LINUX_EXTENDED(85)。
start的默认值为第一个未分配的扇区/圆柱体/ ...
size的默认值尽可能大(直到下一个分区或磁盘末尾)。
但是,对于扩展分区内的四个分区,默认值为:Linux分区,扩展分区,空,空。
但是,当给出-N选项(仅更改单个分区)时,每个字段的默认值为其先前的值。
可以指定' + '而不是数字来表示大小,这意味着要尽可能多。这对于-N选项很有用。
sfdisk [options] device
sfdisk -s [partition]
Options
sfdisk accepts the following command-line options:
-v, --version
|
Print version number of sfdisk and exit immediately.
|
-h, --help
|
Print a usage message and exit immediately.
|
-T, --list-types
|
Print the recognized types (system Id's).
|
-s, --show-size
|
List the size of a partition.
|
-g, --show-geometry
|
List the kernel's idea of the geometry of the indicated disk(s).
|
-G, --show-pt-geometry
|
List the geometry of the indicated disks guessed by looking at the partition table.
|
-l, --list
|
List the partitions of a device.
|
-d, --dump
|
Dump the partitions of a device in a format that is usable as input to /fBsfdisk/fR. For example, the following sequence of commands:
sfdisk -d /dev/hda > hda.out
sfdisk /dev/hda < hda.out
will correct the bad last extended partition that the OS/2 fdisk creates.
|
-V, --verify
|
Test whether partitions seem correct. See the third invocation type above.
|
-i, --increment
|
Number cylinders etc. starting from 1 instead of 0.
|
-N number
|
Change only the single partition indicated. For example, the following sfdisk command, and the listed input:
sfdisk /dev/hdb -N5
,,,*
will make the fifth partition on /dev/hdb bootable ("active") and change nothing else. (Probably this fifth partition is called /dev/hdb5, but you are free to call it something else, like "/my_equipment/disks/2/5" or so).
|
-A, --activate number
|
Make the indicated partition(s) active, and all others inactive.
|
-c, --id number [Id]
|
If no Id argument given: print the partition Id of the indicated partition. If an Id argument is present: change the type (Id) of the indicated partition to the given value. This option has two longer forms, --print-id and --change-id. For example:
sfdisk --print-id /dev/hdb 5
6
sfdisk --change-id /dev/hdb 5 83
OK
first reports that /dev/hdb5 has Id 6, and then changes that into 83.
|
-u, --unit letter
|
Interpret the input and show the output in the units specified by letter. This letter can be one of S, C, B or M, meaning Sectors, Cylinders, Blocks and Megabytes, respectively. The default is cylinders, at least when the geometry is known.
|
-x, --show-extended
|
Also, list non-primary extended partitions on output, and expect descriptors for them on input.
|
-C, --cylinders cylinders
|
Specify the number of cylinders, possibly overriding what the kernel thinks.
|
-H, --heads heads
|
Specify the number of heads, possibly overriding what the kernel thinks.
|
-S, --sectors sectors
|
Specify the number of sectors, possibly overriding what the kernel thinks.
|
-f, --force
|
Do what I say, even if it is stupid.
|
-q, --quiet
|
Suppress warning messages.
|
-L, --Linux
|
Do not complain about things irrelevant for Linux.
|
-D, --DOS
|
For DOS-compatibility: waste a little space. More precisely: if a partition cannot contain sector 0, e.g., because that is the MBR of the device, or contains the partition table of an extended partition, then sfdisk would make it start the next sector. However, when this option is given it skips to the start of the next track, wasting for example 33 sectors (in case of 34 sectors/track), just like certain versions of DOS do. Certain Disk Managers and boot loaders (such as OSBS, but not LILO or the OS/2 Boot Manager) also live in this empty space, so maybe you want this option if you use one.
|
-E, --DOS-extended
|
Take the starting sector numbers of "inner" extended partitions to be relative to the starting cylinder boundary of the outer one (like some versions of DOS do), rather than relative to the actual starting sector (like Linux does). The fact that there is a difference here means that one should always let extended partitions start at cylinder boundaries if DOS and Linux should interpret the partition table in the same way. Of course one can only know where cylinder boundaries are when one knows what geometry DOS will use for this disk.
|
--IBM, --leave-last
|
Certain IBM diagnostic programs assume that they can use the last cylinder on a disk for disk-testing purposes. If you think you might ever run such programs, use this option to tell sfdisk that it should not allocate the last cylinder. Sometimes the last cylinder contains a bad sector table.
|
-n
|
Go through all the motions, but do not actually write to disk.
|
-R, --re-read
|
Only execute the BLKRRPART ioctl (to make the kernel re-read the partition table). This can be useful for checking in advance that the final BLKRRPART will be successful, and also when you changed the partition table "by hand" (e.g., using dd from a backup). If the kernel complains ("device busy for revalidation (usage = 2)") then something still uses the device, and you still have to unmount some file system, or say swapoff to some swap partition.
|
--no-reread
|
When starting a repartitioning of a disk, sfdisk checks that this disk is not mounted, or in use as a swap device, and refuses to continue if it is. This option suppresses the test. On the other hand, the -f option would force sfdisk to continue even when this test fails.
|
--in-order
|
THIS IS A DANGEROUS OPTION. Not yet been documented.
|
--not-in-order
|
THIS IS A DANGEROUS OPTION. Not yet been documented.
|
--inside-outer
|
THIS IS A DANGEROUS OPTION. Affects chaining order.
|
--not-inside-outer
|
THIS IS A DANGEROUS OPTION. Affects chaining order.
|
--nested
|
THIS IS A DANGEROUS OPTION. Every partition is contained in the surrounding partitions and is disjoint from all others.
|
--chained
|
THIS IS A DANGEROUS OPTION. Every data partition is contained in the surrounding partitions and disjoint from all others, but extended partitions may lie outside (insofar as allowed by all_logicals_inside_outermost_extended).
|
--onesector
|
THIS IS A DANGEROUS OPTION. All data partitions are mutually disjoint; extended partitions each use one sector only (except perhaps for the outermost one).
|
-O file
|
Just before writing the new partition, output the sectors that are going to be overwritten to file (where hopefully file resides on another disk, or on a floppy).
|
-I file
|
After destroying your filesystems with an unfortunate sfdisk command, you would have been able to restore the old situation if only you had preserved it using the -O flag.
|
Technical Details And Background Theory
Block 0 of a disk (the Master Boot Record) contains among other things four partition descriptors. The partitions described here are called primary partitions.
A partition descriptor has 6 fields:
struct partition {
unsigned char bootable; /* 0 or 0x80 */
hsc begin_hsc;
unsigned char id;
hsc end_hsc;
unsigned int starting_sector;
unsigned int nr_of_sectors;
}
The two hsc fields indicate head, sector and cylinder of the begin and the end of the partition. Since each hsc field only takes 3 bytes, only 24 bits are available, which does not suffice for big disks (say > 8 GB). In fact, due to the wasteful representation (that uses a byte for the number of heads, which is typically 16), problems already start with 0.5 GB. However, Linux does not use these fields, and problems can arise only at boot time, before Linux has been started. For more details, see your LILO documentation.
Each partition has a type, its "Id", and if this type is 5 or f ("extended partition") the starting sector of the partition again contains 4 partition descriptors. MSDOS only uses the first two of these: the first one an actual data partition, and the second one again an extended partition (or empty). In this way one gets a chain of extended partitions. Other operating systems have slightly different conventions. Linux also accepts type 85 as equivalent to 5 and f - this can be useful if one wants to have extended partitions under Linux past the 1024 cylinder boundary, without DOS FDISK hanging. If there is no good reason, you should just use 5, which is understood by other systems.
Partitions that are not primary or extended are called logical. Often, one cannot boot from logical partitions (because the process of finding them is more involved than just looking at the MBR). Note that of an extended partition only the Id and the start are used. There are various conventions about what to write in the other fields. One should not try to use extended partitions for data storage or swap.
Input Format
sfdisk reads lines of the form
where each line fills one partition descriptor.
Fields are separated by whitespace, or comma or semicolon possibly followed by whitespace; initial and trailing whitespace is ignored. Numbers can be octal, decimal or hexadecimal; decimal is default. When a field is absent or empty, a default value is used.
The parts can (and probably should) be omitted - sfdisk computes them from and and the disk geometry as given by the kernel or specified using the -H, -S, -C flags.
Bootable is specified as [*|-], with as default not-bootable. The value of this field is irrelevant for Linux - when Linux runs it has been booted already - but might play a role for certain boot loaders and for other operating systems. For example, when there are several primary DOS partitions, DOS assigns C: to the first among these that is bootable.
Id is given in hex, without the 0x prefix, or is [E|S|L|X], where L (LINUX_NATIVE (83)) is the default, S is LINUX_SWAP (82), E is EXTENDED_PARTITION (5), and X is LINUX_EXTENDED (85).
The default value of start is the first nonassigned sector/cylinder/...
The default value of size is as much as possible (until next partition or end-of-disk).
However, for the four partitions inside an extended partition, the defaults are: Linux partition, Extended partition, Empty, Empty.
But when the -N option (change a single partition only) is given, the default for each field is its previous value.
A '+' can be specified instead of a number for size, which means as much as possible. This is useful with the -N option.