sfdisk (util-linux-ng 2.17.2) 使い方: sfdisk [オプション] デバイス名... デバイス: /dev/hda や /dev/sda の様な何か 有益なオプション: -s [or --show-size]: パーティションサイズのリスト -c [or --id]: パーティション ID の表示または変更 -l [or --list]: デバイス毎のパーティションリスト -d [or --dump]: 前に同じだが、後の入力書式に沿うようにする -i [or --increment]: シリンダ数など。0 ではなく 1 から -uS, -uB, -uC, -uM: セクタ/ブロック/シリンダ/MB のユニットの受理/報告 -T [or --list-types]:既知のパーティションタイプのリスト -D [or --DOS]: DOS 互換モード -- 空間が少し無駄になります -R [or --re-read]: カーネルにパーティションテーブルを再読込みさせる -N# : 指定番号# のパーティションのみ変更する -n : ディスクへの実際の書込みを行わない -O file : 上書きされるセクタをファイルに保存する -I file : セクタをファイルから復元する -v [or --version]: バージョンを表示する -? [or --help]: このメッセージを表示する 危険なオプション: -g [or --show-geometry]: カーネルのジオメトリ情報を表示する -G [or --show-pt-geometry]: 領域テーブルから推測されるジオメトリ情報を表示する -x [or --show-extended]: 拡張領域リストも表示する またはそれらの記述子の入力を得る -L [or --Linux]: Linux にそぐわなくても文句を云わない -q [or --quiet]: 警告メッセージを抑制する ジオメトリ検出を強制指定できます: -C# [or --cylinders #]:使用するシリンダ数を設定する -H# [or --heads #]: 使用するヘッド数を設定する -S# [or --sectors #]: 使用するセクタ数を設定する 矛盾のチェックを行わないようにできます: -f [or --force]: おかしな指定を行っても、そのまま実行します
sfdisk (util-linux-ng 2.17.2) Usage: sfdisk [options] device ... device: something like /dev/hda or /dev/sda useful options: -s [or --show-size]: list size of a partition -c [or --id]: print or change partition Id -l [or --list]: list partitions of each device -d [or --dump]: idem, but in a format suitable for later input -i [or --increment]: number cylinders etc. from 1 instead of from 0 -uS, -uB, -uC, -uM: accept/report in units of sectors/blocks/cylinders/MB -T [or --list-types]:list the known partition types -D [or --DOS]: for DOS-compatibility: waste a little space -R [or --re-read]: make kernel reread partition table -N# : change only the partition with number # -n : do not actually write to disk -O file : save the sectors that will be overwritten to file -I file : restore these sectors again -v [or --version]: print version -? [or --help]: print this message dangerous options: -g [or --show-geometry]: print the kernel's idea of the geometry -G [or --show-pt-geometry]: print geometry guessed from the partition table -x [or --show-extended]: also list extended partitions on output or expect descriptors for them on input -L [or --Linux]: do not complain about things irrelevant for Linux -q [or --quiet]: suppress warning messages You can override the detected geometry using: -C# [or --cylinders #]:set the number of cylinders to use -H# [or --heads #]: set the number of heads to use -S# [or --sectors #]: set the number of sectors to use You can disable all consistency checking with: -f [or --force]: do what I say, even if it is stupid
SFDISK(8) Linux Programmer’s Manual SFDISK(8)
名前
sfdisk - Linux 用のパーティションテーブル操作ツール
書式
sfdisk [options] device
sfdisk -s [partition]
説明
sfdisk には (主に) 4 つの使用法があり、パーティションサイズの一覧・デバ
イス上のパーティションの一覧・デバイス上のパーティションのチェック・ デ
バイスのパーティション再分割 (これは非常に危険) ができる。
サイズの一覧
sfdisk -s partition とすると partition のサイズをブロック単位で表示する
。この使用法は mkswap のようなプログラムと共に使う場合に便利である。 こ
こ で 、 partition は、普通 /dev/hda1 や /dev/sdb12 のようにするが、
/dev/xda のようにディスク全体でもよい。
% sfdisk -s /dev/hda9
81599
%
パーティション引き数が省略された場合、 sfdisk は全てのディスクのサイ ズ
と合計をリストする:
% sfdisk -s
/dev/hda: 208896
/dev/hdb: 1025136
/dev/hdc: 1031063
/dev/sda: 8877895
/dev/sdb: 1758927
合計: 12901917 ブロック
%
パーティションの一覧
第 2 の呼び出し形式: sfdisk -l [options] device はデバイス上のパーティ
ションをリストする。デバイス引き数が省略された場合、全てのハードディ ス
ク上のパーティションがリストされる。
% sfdisk -l /dev/hdc
ディスク /dev/hdc: ヘッド数 16、セクタ数 63、シリンダ数 2045
ユニット = 516096 バイトのシリンダ、1024 バイトのブロック、0 から数えます
デバイス ブート 始点 終点 #シリンダ #ブロック ID システム
/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 空
%
数 字の後ろに付いた - と + 符号は、丸めが行われており、本当の値は多少小
さい (大きい) ことを示す。正確な値を知るためには、セクタを単位として リ
ストすればよい。
パーティションのチェック
第 3 の呼び出し形式: sfdisk -V device は device 上のパーティションテー
ブルに対していろいろな整合性チェックを適用する。 ‘OK’ または問題点が 表
示 される。 -V オプションは -l と一緒に使うことができる。シェルスクリプ
トから使う場合は sfdisk -V -q device とすればステータスのみを返すことも
できる。
パーティションの作成
第 4 の呼び出し形式: sfdisk device を用いると、 sfdisk は device 用のパ
ーティション分割指定を標準入力から読み込み、そのディスクのパーティシ ョ
ン テーブルを変更する。よって、 sfdisk をシェルスクリプトから使うことが
できる。 sfdisk が標準入力を端末と認識した場合は、対話的な動作に入る 。
それ以外の場合は、何らかのエラーでアボート (abort) する。
特に注意 - 1 つ打ち間違えるだけで全てのデータが失われる
予防措置として、 sfdisk で変更されるセクタを保存することができる:
% sfdisk /dev/hdd -O hdd-partition-sectors.save
...
%
こうすれば、(ディスクに何かを書き込む前なら) 何か馬鹿な間違いに気付いた
場合に、以下のようにして以前の状態に戻すことができる。
% sfdisk /dev/hdd -I hdd-partition-sectors.save
%
(これは以前のパーティションテーブルを保存するのとは異なる: 以前のパーテ
ィ ションテーブルは -d オプションを使えば可読な形式で保存できる。しかし
、論理パーティションを作成した場合、それを記述するセクタはディスクの ど
こ かにあり、以前のパーティションテーブルの一部ではないセクタに置かれる
可能性もある。よって、-O オプションで保存される情報は、 -d の出力のバイ
ナリ版ではない。)
多くのオプションがある。
オプション
-v または --version
sfdisk のバージョン番号を表示して、すぐに終了する。
-? または --help
使用法のメッセージを表示して、すぐに終了する。
-T または --list-types
認識されたタイプ (システム ID) を表示する。
-s または --show-size
パーティションのサイズをリストする。
-g または --show-geometry
指定されたディスクに関するカーネルのジオメトリ情報をリストする。
-G または --show-pt-geometry
指定されたディスクに関するカーネルのジオメトリ情報を、パーティシ
ョンテーブルを見て推測し、リストする。
-l または --list
デバイスのパーティションをリストする。
-d sfdisk の入力として使えるフォーマットで、デバイスのパーティショ
ンをダンプする。例えば、
% sfdisk -d /dev/hda > hda.out
% sfdisk /dev/hda < hda.out
は (OS/2 の fdisk が作った) 不正な最後の拡張パーティションを修正
する。
-V または --verify
パーティションが正しいかをテストする (上記を参照)。
-i または --increment
シリンダ数を 0 ではなく 1 から数える。
-N number
指定された 1 つのパーティションだけを変更する。例えば、
% sfdisk /dev/hdb -N5
,,,*
%
は /dev/hdb の第 5 パーティションをブート可能 (‘アクティブ’) に
して、他は変更しない (多分、この第 5 パーティションは /dev/hdb5
と 呼ばれるが、 ‘/my_equipment/disks/2/5’ のような別の名前で呼ぶ
のも自由である)。
-Anumber
指定したパーティション (複数でもよい) をアクティブにして、他のパ
ーティションを非アクティブにする。
-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
OK
最初に /dev/hdb5 が ID 6 であることを表示させ、次に ID を 83 に
変更している。
-uS または -uB または -uC または -uM
セクタ単位 (ブロック単位・シリンダ単位・メガバイト単位) の数値を
受け付け・表示する。少なくともジオメトリが分かる場合、デフォルト
はシリンダ単位である。
-x または --show-extended
基本パーティションでない拡張パーティションも出力にリストする。ま
たそれらに対するパーティション設定を入力で受け付ける。
-C cylinders
シリンダ数を指定する。カーネルが想定している値を上書きできる。
-H heads
ヘッド数を指定する。カーネルが想定している値を上書きできる。
-S sectors
セクタ数を指定する。カーネルが想定している値を上書きできる。
-f または --force
たとえ馬鹿げたことであっても、指示したことを行わせる。
-q または --quiet
警告メッセージを表示しない。
-L または --Linux
Linux に関連しない警告を出さない。
-D または --DOS
DOS との互換性のために、いくらかの領域を無駄にする (より正 確 に
は: あるパーティションがデバイスの MBR だったり、拡張パーティシ
ョン用のパーティションテーブルを含んでいたりしてセクタ 0 を持 つ
ことができない場合、通常 sfdisk は次のセクタからパーティションを
開始する。しかしこのオプションを指定すると、デフォルトで次のトラ
ッ ク にスキップしてからパーティションを開始する。例えば 34 セク
タ/トラックの場合なら、 33 セクタが無駄になる。これは、あるバ ー
ジョンの DOS が行う動作と同じである)。ある種のディスクマネージャ
とブートローダ (OSBS などのことで、LILO や OS/2 ブートマネージャ
は含まれない) はこの空き領域に置かれるので、これらを使う場合には
、このオプションが必要かもしれない。
-E または --DOS-extended
「内側」の拡張パーティションの開始セクタ番号を、 (Linux の よ う
に) 「外側」の拡張パーティションの開始セクタからの相対位置として
取得せず、 (DOS のあるバージョンのように) 開始シリンタ境界からの
相対位置として取得する。 (ここに違いがあるということは、もし DOS
と Linux がパーティションテーブルを同じ方法で解釈していれば、 拡
張パーティションを常にシリンダ境界から始めなければならない、とい
うことを意味する。もちろん、どこにシリンダ境界があるかは 、 DOS
がディスクに対してどのようなジオメトリを使うかを知っていなければ
わからない。)
--IBM または --leave-last
IBM のある診断プログラムは、最後のシリンダをディスクチェックの目
的で使用する。もし、このようなプログラムを実行することがあるなら
、 sfdisk に対して最後のシリンダを割り当てさせないように、このオ
プションを使うこと。最後のシリンダに不正なセクタテーブルが含まれ
ていることが時々ある。
-n 全ての動作を通して実行するが、実際にはディスクに書き込まない。
-R (カーネルにパーティションテーブルを再び読み込ませるために) BLKR-
RPART ioctl のみを実行する。最後の BLKRRPART が成功するかを前も
ってチェックするのに役立つ。また (例えばバックアップから dd を使
って) 「手動で」パーティションテーブルを変更した場合などにも役立
つ。カーネルが (‘device busy for revalidation (usage = 2)’) とい
う警告を出した場合は、デバイスがまだ使われており、ファイルシステ
ムをアンマウントすべきである。あるいはスワップパーティションなら
swapoff を実行すべきである。
--no-reread
ディスクのパーティション再分割を始めると、 sfdisk はディスクがマ
ウントされていないか、またはスワップデバイスとして使われていない
かをチェックする。使われている場合には、続行を拒否する。このオプ
ションを指定すると、このチェックを行わない。 (一方で、-f オプ シ
ョンは sfdisk に対してテストが失敗した場合でも強制的に続行させる
。)
-O file
新しいパーティションを書き込む直前に、上書きされるセクタを file
に出力する (file は、他のディスクやフロッピーにある方が良い)。
-I file
不適切な sfdisk コマンドでファイルシステムを壊してしまった後でも
以前の状態に回復できる。これは -O フラグを使って以前の状態を保存
してある場合にのみ可能である。
理論
ディスクのブロック 0 (マスターブートレコード) には、他に 4 つのパーティ
ションディスクリプタがある。ここで説明するパーティションは 基本パーティ
ションと呼ばれる。
パーティションディスクリプタには 6 つのフィールドがある:
struct partition {
unsigned char bootable; /* 0 または 0x80 */
hsc begin_hsc;
unsigned char id;
hsc end_hsc;
unsigned int starting_sector;
unsigned int nr_of_sectors;
}
2 つの hsc フィールドは、最初と最後のパーティションのヘッド・セクタ・シ
リンダを示す。各 hsc フィールドは 3 バイトしかないので、 24 ビットし か
使用できず、大きなディスク (つまり 8GB より大きいディスク) には十分でな
い。実際には、(通常は 16 であるヘッド数のために 1 バイトを使う) 無駄 の
多 い表現のために、0.5GB から既に問題が起こる。しかし、Linux はこのフィ
ールドを使わず、 Linux が起動する前のブート時にのみ問題が生じる可能性が
ある。詳しくは、 lilo のドキュメントを参照すること。
各 パーティションにはタイプ ‘ID’ がある。 ID が 5 または f (‘拡張パーテ
ィション’) の場合、このパーティションの開始セクタにも 4 つのパーティ シ
ョンディスクリプタがある。 MSDOS は最初の 2 つしか使わない: 最初の 1 つ
は実際のデータパーティションで 2 つめは、次の拡張パーティション (または
空) である。このようにして、拡張パーティションの連鎖をつくる。他の OS
は少し異なる方法を使う。 Linux は 85 を 5 や f と同じものとして受け付け
る - DOS FDISK をハングさせることなく 1024 シリンダを越えたところに
Linux の拡張パーティションを作りたい場合に、これが役立つ。 (正当な理 由
がない場合は、他の OS にも認識される 5 のみを使うべきである。)
基本や拡張でないパーティションは、 論理パーティションと呼ばれる。大抵、
論理パーティションからはブートできない (なぜなら、論理パーティション を
見 付けるプロセスは、ただ MBR を探すのにくらべて更に複雑なためである)。
拡張パーティションでは、ID と開始点しか使われない点に注意すること。他の
フ ィールドに何を書くのかには、いろいろな習慣がある。データの保管やスワ
ップには、拡張パーティションは使うべきではない。
入力フォーマット
sfdisk は、以下の形式の行を読み込む。
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
partitions 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
block devices, 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 par-
titions on all hard block devices 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 val-
ues, ask for a listing with sectors as unit.
Check partitions
The third type of invocation: sfdisk -V device will apply various con-
sistency checks to the partition tables on device. It prints ‘OK’ or
complains. 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 stan-
dard input, and then to change the partition tables on that block
device. 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 block device, 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
version 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 block device 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 block
device(s)
-G or --show-pt-geometry
List the geometry of the indicated block devices 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
kernel 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 ker-
nel 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 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 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 boundaries are when one knows what geometry DOS
will use for this block device.)
--IBM or --leave-last
Certain IBM diagnostic programs assume that they can use the
last cylinder on a block device 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 block
device.
-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 block device, sfdisk checks
that this device 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 block device, 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.
THEORY
Block 0 of a block device (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 block devices
(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. However Linux does not use these fields, and prob-
lems can arise only at boot time, before Linux has been started. For
more details, see the 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 con-
tains 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 vari-
ous 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
Copyright(C) linux-cmd.com All Rights Reserved. Author Takayuki Yukawa