Linux shell--sfdisk manual

原本 要尝试着自己翻译下的,结果发现有人已经做好了。

转自:http://www.jinbuguo.com/man/sfdisk.html

SFDISK(8)                    System Administration                   SFDISK(8)

名称
       sfdisk - 分区表操作工具

语法
       sfdisk [options] device
       sfdisk -s [partition]

描述
       sfdisk 有4个主要用途:列出分区尺寸,列出分区表,检查分区表,创建分区表[非常危险]。

       sfdisk 不能处理GPT格式的分区表,也不能处理超过2T的大硬盘,这种情况需要使用 GNU parted 工具。

       sfdisk 并不会自动对齐分区,不过 fdisk(8) 可以。


   列出分区尺寸
       sfdisk -s [partition]
       以块[blocks]为单位列出块设备的大小。
       这里的[partition]可以是一个实际的分区(例如:/dev/sdb12),也可以是一个完整的磁盘(例如:/dev/sda)

              % sfdisk -s /dev/hda9
              81599

       如果省略[partition]参数,那么将依次列出每个磁盘(不含分区)的大小以及总计大小。

              % sfdisk -s
              /dev/hda: 208896
              /dev/hdb: 1025136
              /dev/hdc: 1031063
              /dev/sda: 8877895
              /dev/sdb: 1758927
              total: 12901917 blocks


   列出分区表
       sfdisk -l [device]
       列出device设备上的分区表。如果省略[device]参数,那么将列出所有磁盘上的分区表。

              % sfdisk -l /dev/hdc

              Disk /dev/hdc: 16 heads, 63 sectors, 2045 cylinders
              Units = cylinders of 516096 bytes, blocks of 1024 bytes, counting from 0

                 Device Boot Start     End   #cyls   #blocks   Id  System
              /dev/hdc1          0+    406     407-   205096+  83  Linux native
              /dev/hdc2        407     813     407    205128   83  Linux native
              /dev/hdc3        814    2044    1231    620424   83  Linux native
              /dev/hdc4          0       -       0         0    0  Empty

       [说明]数字结尾的"+"或"-"表示其只是一个近似值而非精确值。
       要查看精确值,可以使用 sfdisk -l -u S [device] 语法,按扇区查看。


   检查分区表
       sfdisk -V device
       检查分区表的正确性,并打印出'OK'或者显示不合理之处。
       例如:Warning: partition 1 does not end at a cylinder boundary
       -V 选项可以和 -l 选项一起使用。在shell脚本内,可以使用
       sfdisk -V -q device
       来仅返回一个代表正确/错误的返回值


   创建分区表
       sfdisk device
       根据标准输入(STDIN)给出的指示创建device的分区表。
       这样便可以方便的在shell脚本内进行分区操作。
       当 sfdisk 检测到其自身运行在终端内时,将会以交互方式操作,
       否则(也就是在脚本内),在检测到任何错误的时候,都将导致退出。
       [警告]一个微小的输入错误都将可能导致数据丢失!


选项
       -v, --version
              打印版本信息并立即退出

       -h, --help
              打印帮助信息并立即退出

       -T, --list-types
              列出所有能够识别的分区类型(system ID)

       -s, --show-size
              列出分区的大小

       -g, --show-geometry
              列出内核检测到的设备的几何参数(C-H-S)

       -G, --show-pt-geometry
              列出根据设备上的分区表计算出的几何参数

       -l, --list
              列出设备上的分区表

       -d, --dump
              按照 sfdisk 可以理解的标准格式,打印出设备上目前现有的分区表,例如
                  % sfdisk -d /dev/hda > hda.out
              之后还可以用如下命令重新写入分区表
                  % sfdisk /dev/hda < hda.out

       -V, --verify
              校验分区表的合理性

       -i, --increment
              柱面号(从 1 开始计数,而不是 0 )

       -N number
              仅更改指定序号的分区。例如
                  % sfdisk /dev/hdb -N5
                  ,,,*
              除了将 /dev/sdb 上的第五个分区标记为'bootable'之外,不做其他任何变更。
              虽然这"第五个"分区很有可能叫做 /dev/sdb5 ,但是你也可能称它为别的名称,
              例如'/my_equipment/disks/2/5'之类

       -A, --activate[=device_or_number]
              将指定编号的分区标记为'bootable',并取消所有其他分区的'bootable'标记。

              如果没有参数则表示列出带有'bootable'标记的分区,例如:

                  % sfdisk --activate /dev/sda

              如果给出了设备参数,那么数字对应的分区将被标记为'bootable',而其他分区则取消'bootable'标记。
              例如下面的命令为 1,4 分区添加'bootable',同时取消所有其他分区的'bootable'标记:

                  % sfdisk --activate=/dev/sda 1 4

              如果只想激活一个分区的'bootable'标记,那么就必须将分区号作为参数。
              例如,下面的命令表示开启第一个分区的'bootable'标记,同时取消所有其他分区的'bootable'标记:

                  % sfdisk --activate=1 /dev/sda


       -c, --id num [Id]
              如果没有给出[ID]参数,则打印出第num个分区的类型[ID]
              如果给出[ID]参数,则将第num个分区的类型更改为ID
              这个选项还有两个意思显而易见的别名:--print-id 和 --change-id
              例如,打印 /dev/sdb5 的分区类型
                  % sfdisk --print-id /dev/sdb 5
                  6
              接着再将 /dev/sdb5 的分区类型改为"0x83"
                  % sfdisk --change-id /dev/sdb 5 83
                  OK

       -u, --unit letter
              指定输入/输出的数字的单位。默认值是柱面。
              这里的letter可以是 S[扇区], C[柱面], B[块], M[MB]。

       -x, --show-extended
              也包含扩展分区(无论对于输入还是输出)。

       -C, --cylinders cylinders
              强制指定柱面数,忽略内核自己的检测

       -H, --heads heads
              强制指定磁头数,忽略内核自己的检测

       -S, --sectors sectors
              强制指定扇区数,忽略内核自己的检测

       -f, --force
              强制执行,即使看上去是明显的错误动作

       -q, --quiet
              静默模式,禁止打印提示信息

       -L, --Linux
              不显示与Linux无关的警告

       -n     模拟执行所有动作但并不实际写入磁盘

       -R, --re-read
              让内核重新读取分区表。
              如果内核抱怨说:'device busy for revalidation (usage = 2)'
              那就表明此设备上当前有尚未卸载的文件系统或者swap分区。

       --no-reread
              当执行分区表修改动作时,如果sfdisk检测到此设备已经被挂载或者正被用于swap,
              那么将拒绝执行任何修改动作。使用该选项可以禁止这种检测。
              [注意] --force 比这个选项更强,它表示无视一切禁忌的强制执行


理论
       位于MBR(Master Boot Record)的磁盘分区表拥有如下数据结构:
              struct partition {
                  unsigned char bootable;          /* 0 or 0x80 , 1字节 */
                  hsc begin_head_sector_cylinder;  /* 3字节 */
                  unsigned char id;                /* 1字节 */
                  hsc end_head_sector_cylinder;    /* 3字节 */
                  unsigned int starting_sector;    /* 4字节 */
                  unsigned int num_of_sectors;     /* 4字节 */
              }

       两个 hsc 字段指定了分区的开始和结束 head_sector_cylinder 值。
       由于hsc字段只有24位,所以无法表示超过8G的值。而且当磁头数小于256的时候,所能表示的最大值更加的小。
       事实上,Linux根本不看这两个字段的设置,因此这两个字段仅在磁盘引导的时候可能会有影响。


输入格式
       sfdisk可以识别如下格式的输入行,每一行用于描述一个分区:
       start size id bootable c,h,s c,h,s
       字段之间可以用空格/逗号/分号进行分隔,首尾的空白都将被忽略。
       数字可以是八进制/十进制(默认)/十六进制。
       如果某个字段留空或者缺席,就表示使用其默认值。

       两个 c,h,s 字段应该尽量留空,这样 sfdisk 可以根据几何参数以及 start 和 size 值进行推算。

       bootable 可以指定为[*|-]格式,默认值是"-"也就是没有可引导标记。
       这个标记仅对DOS有意义:DOS会给带有可引导标记的主分区分配 C: 盘符

       id 应该以无"0x"前缀的格式给出其十六进制值,或者[E|S|L]简写字母:
       L(83)是默认值,S(82,LINUX_SWAP),E(5,扩展分区)。

       start 的默认值是首个未分配的扇区/柱面
       size 的默认值是尽可能大(直到下一个分区或磁盘尾),设为'+'明确表示尽可能大。

       当使用 -N 选项指定某个特定的分区时,每个字段的默认值就变成了原有分区表内已经存在的值。
       这时候,可以将 size 设为'+'以明确表示尽可能大(直到下一个分区或磁盘尾)。


参见
       cfdisk(8), fdisk(8), mkfs(8), parted(8), partprobe(8), kpartx(8)


util-linux                        August 2011                        SFDISK(8)

下面是从系统里man的资料,英文原文:

SFDISK(8)                  Linux Programmer's Manual                 SFDISK(8)


NAME
       sfdisk - Partition table manipulator for Linux

SYNOPSIS
       sfdisk [options] device
       sfdisk -s [partition]

DESCRIPTION
       sfdisk has four (main) uses: list the size of a partition, list the parti-
       tions on a device, check the partitions on a device, and - very  dangerous
       - repartition a device.

       sfdisk  doesn't  understand  GUID  Partition  Table  (GPT)  and  it is not
       designed for large partitions. In particular case use  more  advanced  GNU
       parted(8).

       Note  that  sfdisk  does  not align partitions to block device I/O limits.
       This functionality is provided by fdisk(8).

   List Sizes
       sfdisk -s partition gives the size of partition in  blocks.  This  may  be
       useful in connection with programs like mkswap(8) or so. Here partition is
       usually something like /dev/hda1 or /dev/sdb12, but may also be an  entire
       disk, like /dev/xda.
              % sfdisk -s /dev/hda9
              81599
              %
       If  the  partition  argument is omitted, sfdisk will list the sizes of all
       disks, and the total:
              % sfdisk -s
              /dev/hda: 208896
              /dev/hdb: 1025136
              /dev/hdc: 1031063
              /dev/sda: 8877895
              /dev/sdb: 1758927
              total: 12901917 blocks
              %

   List Partitions
       The second type of invocation: sfdisk -l [options] device  will  list  the
       partitions  on this device.  If the device argument is omitted, the parti-
     tions on all hard disks are listed.
       % sfdisk -l /dev/hdc

       Disk /dev/hdc: 16 heads, 63 sectors, 2045 cylinders
       Units = cylinders of 516096 bytes, blocks of 1024 bytes, counting from 0

          Device Boot Start     End   #cyls   #blocks   Id  System
       /dev/hdc1          0+    406     407-   205096+  83  Linux native
       /dev/hdc2        407     813     407    205128   83  Linux native
       /dev/hdc3        814    2044    1231    620424   83  Linux native
       /dev/hdc4          0       -       0         0    0  Empty
       %
       The trailing - and + signs indicate that rounding  has  taken  place,  and
       that  the  actual value is slightly less (more).  To see the exact values,
       ask for a listing with sectors as unit.

   Check partitions
       The third type of invocation: sfdisk -V device will apply various  consis-
       tency  checks  to  the partition tables on device.  It prints 'OK' or com-
       plains. The -V option can be used together with -l. In a shell script  one
       might use sfdisk -V -q device which only returns a status.

   Create partitions
       The fourth type of invocation: sfdisk device will cause sfdisk to read the
       specification for the desired partitioning of  device  from  its  standard
       input,  and  then to change the partition tables on that disk. Thus, it is
       possible to use sfdisk from a shell script. When  sfdisk  determines  that
       its  standard input is a terminal, it will be conversational; otherwise it
       will abort on any error.

       BE EXTREMELY CAREFUL - ONE TYPING MISTAKE AND ALL YOUR DATA IS LOST

       As a precaution, one can save the sectors changed by sfdisk:
              % sfdisk /dev/hdd -O hdd-partition-sectors.save
              ...
              %

       Then, if you discover that you did something stupid before  anything  else
       has  been written to disk, it may be possible to recover the old situation

       with

 % sfdisk /dev/hdd -I hdd-partition-sectors.save
              %

       (This is not the same as saving the old partition table: a  readable  ver-
       sion of the old partition table can be saved using the -d option. However,
       if you create logical partitions, the sectors describing them are  located
       somewhere on disk, possibly on sectors that were not part of the partition
       table before. Thus, the information the -O option saves is  not  a  binary
       version of the output of -d.)

       There are many options.

OPTIONS
       -v or --version
              Print version number of sfdisk and exit immediately.

       -? or --help
              Print a usage message and exit immediately.

       -T or --list-types
              Print the recognized types (system Id's).

       -s or --show-size
              List the size of a partition.

       -g or --show-geometry
              List the kernel's idea of the geometry of the indicated disk(s).

       -G or --show-pt-geometry
              List  the geometry of the indicated disks guessed by looking at the
              partition table.

       -l or --list
              List the partitions of a device.

       -d     Dump the partitions of a device in a  format  useful  as  input  to
              sfdisk. For example,
                  % 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 or --verify
              Test whether partitions seem correct. (See above.)

       -i or --increment
              Number cylinders etc. starting from 1 instead of 0.

       -N number
              Change only the single partition indicated. For example:
                  % 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 number
              Make the indicated partition(s) active, and all others inactive.

       -c or --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 the
              two very long 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.

       -uS or -uB or -uC or -uM
              Accept or report in units of sectors (blocks, cylinders, megabytes,
              respectively). The default is cylinders, at least when the geometry
              is known.

       -x or --show-extended
              Also  list  non-primary  extended  partitions on output, and expect
              descriptors for them on input.

       -C cylinders

 Specify the number of cylinders, possibly overriding what the  ker-
              nel thinks.

       -H heads
              Specify  the  number  of heads, possibly overriding what the kernel
              thinks.

       -S sectors
              Specify the number of sectors, possibly overriding what the  kernel
              thinks.

       -f or --force
              Do what I say, even if it is stupid.

       -q or --quiet
              Suppress warning messages.

       -L or --Linux
              Do not complain about things irrelevant for Linux.

       -D or --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 parti-
              tion, 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 or --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 to the  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  bound-
              aries are when one knows what geometry DOS will use for this disk.)

       --IBM or --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     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.)

       -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  com-
              mand, you would have been able to restore the old situation if only
              you had preserved it using the -O flag.

THEORY
       Block 0 of a disk (the Master Boot Record)  contains  among  other  things
       four  partition descriptors. The partitions described here are called pri-
       mary 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 >  8GB).  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.5GB.  How-
       ever  Linux does not use these fields, and problems can arise only at boot
       time, before Linux has been started. For more details, see the lilo  docu-
       mentation.

       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  parti-
       tion 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 oper-
       ating 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 fol-

 lowed 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 parti-
       tions, 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.

EXAMPLE
       The command
              sfdisk /dev/hdc << EOF
              0,407
              ,407
              ;
              ;
              EOF
       will partition /dev/hdc just as indicated above.

       The command
              sfdisk /dev/hdb << EOF

    ,3,L
              ,60,L
              ,19,S
              ,,E
              ,130,L
              ,130,L
              ,130,L
              ,,L
              EOF
       will partition /dev/hdb into two Linux partitions of 3 and 60 cylinders, a
       swap space of 19 cylinders, and an extended partition covering  the  rest.
       Inside  the  extended  partition  there are four Linux logical partitions,
       three of 130 cylinders and one covering the rest.

       With the -x option, the number of input lines must be a multiple of 4: you
       have  to list the two empty partitions that you never want using two blank
       lines. Without the -x option, you give one line for the partitions  inside
       a  extended  partition,  instead  of  four, and terminate with end-of-file
       (^D).  (And sfdisk will assume that your input line represents  the  first
       of  four, that the second one is extended, and the 3rd and 4th are empty.)

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  infor-
       mation  even if the /U flag is given -- we consider this a bug in DOS FOR-
       MAT and DOS FDISK.

       The bottom line is that if you use sfdisk to change the size of a DOS par-
       tition  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 sfdisk to make a DOS partition table entry for
       /dev/hda1, then (after exiting sfdisk and rebooting Linux so that the par-
       tition  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 sfdisk program.




你可能感兴趣的:(Linux shell--sfdisk manual)