FDISK(8) Linux Programmer’s Manual FDISK(8) 名前 fdisk - Linux 用のパーティションテーブル操作ツール 書式 fdisk [-u] [-b sectorsize] [-C cyls] [-H heads] [-S sects] device fdisk -l [-u] [device ...] fdisk -s partition ... fdisk -v 説明 ハ ードディスクは、一つ以上の論理的なディスクに分割することができる。こ れはパーティション (partition) と呼ばれる。この分割に関する情報は、ディ スクのセクタ 0 に置かれるパーティションテーブルに保存される。 BSD の世界では、それぞれ「ディスクスライス (disk slice)」、「ディスクラ ベル (disklabel)」といった用語が用いられる。 Linux は少なくとも一つのパーティションを必要とする。すなわちルートフ ァ イルシステムとするパーティションである。また Linux ではスワップファルや スワップパーティションを利用することができるが、後者の方が効率が良い 。 し たがって、通常は二つめのパーティションをスワップ用に利用したくなる場 合が多いだろう。 Intel 互換のハードウェアでは、システムをブートさ せ る BIOS はディスクの先頭 1024 シリンダにしかアクセスできない場合が多い。し たがって大きなディスクを使っているユーザーは、数メガバイト程度の第三 の パーティションを追加することになる。これは典型的には /boot にマウントさ れ、カーネルイメージと、ブートに必要ないくつかの外部ファイルを保存す る 。 このようにして、ブートに必要なファイルが BIOS によってアクセス可能で あることを保証するのである。またセキュリティ、保守の都合、バックアッ プ 、テストなど、より多くのパーティションを使う理由は他にも存在する。 (最初の形式で起動された場合には) fdisk はメニュー駆動型のプログラムであ り、パーティションテーブルの作成と操作を行う。 DOS 形式のパーティション や、BSD, SUN 形式のディスクラベルを扱うこともできる。 device に指定するのは通常以下のうちのどれかである。 /dev/hda /dev/hdb /dev/sda /dev/sdb (/dev/hd[a-h] は IDE デ ィ ス ク 、/dev/sd[a-p] は SCSI ディスク、 /dev/ed[a-d] は ESDI ディスク、/dev/xd[ab] は XT ディスクである) デバイ ス名はディスク全体を参照する。 partition は device 名にパーティション番号を付加したものである。例えば /dev/hda1 はシステムの第一 IDE ハードディスクの第一パーティションを指す 。 IDE デ ィスクは 63 個までのパーティションを保持することができる。 SCSI デ ィ ス ク は 15 ま で で あ る 。 /usr/src/linux/Documenta- tion/devices.txt も参考にすると良い。 BSD/SUN 形式のディスクラベルは 8 パーティションを扱うことができる。その うち 3 番目は「ディスク全体」を表すパーティションとなる。先頭セクタを実 際に利用するパーティション (スワップなど) をシリンダ 0 から割り当てては ならない。ディスクラベルを破壊してしまう。 IRIX/SGI 形式のディスクラベルは、16 パーティションを記述できる。その う ちの第 11 番目は ‘volume’ 全体に対応するパーティションであり、第 9 番目 は ‘volume header’ とラベル付けされる。 volume header はパーティショ ン テ ーブルの領域もカバーする。つまり volume header はブロック 0 から始ま り、デフォルトではシリンダ 5 までの部分を占める。volume header の残りの 部分はヘッダディレクトリエントリに用いられる。 volume header は他のパー ティションと重なってはならない。またパーティションテーブルが含まれて い る ので、形式を変更したり、ファイルシステムを作ったりもできない。このラ ベル形式は、IRIX/SGI マシンで動作している Linux か、 IRIX/SGI ディス ク を Linux で使う場合に限って用いること。 DOS 形式のパーティションテーブルは、パーティションの数に制限がない。セ クタ 0 には、4 つのパーティション (「基本 (primary) パーティション」 と 呼 ばれる) に関する情報が記述されている。これら基本パーティションは、拡 張 (extended) パーティションにすることもできる。これは論理 (logical) パ ー ティションの入れ物となる。拡張パーティションにはディスクリプターがセ クタのリンクリストの形式で置かれ、それぞれ対応する論理パーティション の 情 報を保持する。四つの基本パーティションには (存在していなくても) 番号 1-4 が割り当てられる。論理パーティションの番号は 5 から始まる。 DOS 形式のパーティションテーブルでは、それぞれのパーティションのスタ ー ト オフセットとサイズは、二種類の方法で保存される。一つはセクタの絶対数 (32 ビット) であり、もう一つは「シリンダ数/ヘッド数/セクタ数 (C/H/S) 」 の三つの組み合わせである (それぞれ 10, 8, 6 ビット)。前者には問題は特に なく、512 バイトのセクタで 2 TB を扱うことができる。後者には二種類の 問 題がある。まず第一に、この C/H/S を与えるためには、ヘッド数とトラックあ たりのセクタ数を知っていなければならない。第二に、これらの数値がわか っ たとしても、24 ビットでは足りないかもしれない。 DOS は C/H/S だけを用い る。Windows は両方を用いる。 Linux では C/H/S は使わない。 fdisk は、可能な場合にはディスクのジオメトリを自動的に取得する。これ は デ ィスクの物理的なジオメトリであるとは限らない (実際、最近のディスクで は、本当に物理的な - 単純な C/H/S 形式で記述できるような - ジオメトリを 持っていないものもある)。しかしいずれにせよ、 MS-DOS はこのジオメトリを パーティションテーブルで利用する。 Linux しか置かないディスクなら、通常はデフォルトで問題なくすべてうま く い く。しかし他の OS とディスクを共有しなければならない場合には、まず他 の OS 上で、その OS 付属の fdisk を先に実行し、少なくとも一つのパーティ ションを作っておくと良い場合が多い。 Linux は、他の OS とうまく付き合う ために、ブート時にパーティションテーブルを参照し、どんなジオメトリが 要 求 されているのかを判断・決定しようとする (要求されているジオメトリは、 物理的なものとは異なっているかもしれないから)。 パーティションテーブルが表示されるときには、パーティションテーブルの エ ン トリに対して整合性チェックが行われる。このチェックは、パーティション の開始と終了に関する、物理的な情報と論理的なそれとが同一であるか、ま た パ ーティションの開始/終了点がシリンダ境界にあるかを調べる (ただし後者 のチェックでは、最初のパーティションは例外である)。 MS-DOS のバージョンによっては、最初のパーティションの開始点をシリンダ境 界 ではなく先頭シリンダの第 2 セクタにするものがある。シリンダ 1 から始 まるパーティションの開始点はシリンダ境界にならないが、これは問題にな る こ とはあまりないだろう。ただし OS/2 を同じマシンで使っていなければ、で あるが。 パーティションテーブルが更新されると、終了する前に sync() と BLKRRPART ioctl() (ディスクからパーティションテーブルを読み込みなおす) が実行され る。とても昔には、fdisk を利用した後にはリブートが必須だったこともあ っ た。多分これは現在では直っていると思う - むしろ、あまりに急いでリブート すると、まだ書き込まれていないデータを失うかもしれない。カーネルとデ ィ スクハードウェアの両方にバッファーデータが存在することに注意すること。 DOS 6.x 向けの警告 DOS 6.x の FORMAT コマンドはパーティションのデータエリアの第一セクタか らある種の情報を検索し、これをパーティションテーブルにある情報より信 頼 できるものとして扱う。 DOS の FORMAT は、容量が変更されたときには最初の 512 バイト分のデータ領域が DOS 版 FDISK によってクリアされていること を 仮定している。 DOS の FORMAT はこの拡張情報を /U フラグを指定した場合で も見ようとする - これは DOS FORMAT と DOS FDISK のバグであると我々は 考 える。 結局のところ、cfdisk や fdisk を用いて DOS パーティションの容量を変更し たときは、DOS FORMAT を使ってパーティションをフォーマットする前に dd を 使 って先頭の 512 バイトを 0 で埋めなければならない、というわけである。 例えば cfdisk を用いて /dev/hda1 の DOS パーティションのテーブルエン ト リ を作成した場合には、(fdisk または cfdisk を終了し、 Linux をリブート してパーティションテーブルの情報を有効にしたあとで) 先頭の 512 バイトを ゼロにするために "dd if=/dev/zero of=/dev/hda1 bs=512 count=1" などと実 行する必要がある。 dd コマンドを使う場合には特に注意すること。ちょっとしたタイプミスで、デ ィスク上のすべてのデータがパーになる可能性もある。 で きるだけ問題を起こしたくなければ、常に OS 固有のパーティションテーブ ル用プログラムを用いることである。例えば DOS パーティションは DOS FDISK プ ロ グ ラ ム で 作り、 Linux のパーティションは Linux の fdisk または cfdisk で作るべきなのである。 オプション -b sectorsize ディスクのセクタサイズを指定する。指定できる値は 512, 1024, 2048 のいずれかである。 (最近のカーネルはセクタサイズをうまく扱える。 このオプションを用いるのは、カーネルが古い場合や、カーネルの考え を上書きする場合だけにすること。) -C cyls ディスクのシリンダ数を指定する。なぜこれを指定したいと思うのかは 分からない。 -H heads ディスクのヘッダ数を指定する (もちろん物理的なヘッダ数ではなく、 パ ーティションテーブルに使われるヘッダ数である)。適切な値は 255 または 16 である。 -S sects ディスクの 1 トラック当りのセクタ数を指定する (もちろん物理的 な セ ク タ数ではなく、パーティションテーブルに使われるセクタ数であ る)。適切な値は 63 である。 -l 指定したデバイスのパーティションテーブルをリストして終了する。デ バイスを何も指定しないと、 /proc/partitions があれば、そこにある デバイスを対象にする。 -u パーティションテーブルをリストするときに、サイズをシリンダ単位で はなくセクタ単位で表示する。 -s partition パーティションのサイズを (ブロック単位で) 標準出力に表示する。 -v fdisk プログラムのバージョン番号を表示して終了する。 バグ こ の種の *fdisk プログラムには、同じ機能を持ったものが複数存在する。そ れぞれ長所短所がある。 cfdisk, fdisk, sfdisk の順に試してみると良いだろ う 。 (実際のところ、 cfdisk は美しいプログラムであり、受付けるパーティ ションテーブルに厳しい条件を課し、品質の高いパーティションテーブルを 生 成する。可能な場合はこれを用いること。 fdisk はバグっぽいプログラムで、 やることもややあやふやである - 通常は真っ当な結果を出力するけれど。一つ 利点があるとすると、 fdisk は BSD のディスクラベルや、その他の非 DOS パ ーティションテーブルを多少サポートしている点である。 sfdisk はハッカ ー 専用である。ユーザーインターフェースはひどいが、 fdisk よりも正しく、ま た fdisk, cfdisk のどちらよりもパワフルだ。それに、インタラクティブでな い使い方もできる) 最 近は parted というツールもある。 cfdisk のインタフェースは優れている が、parted はより優れている。 parted はパーティションのサイズを変更する だけではなく、パーティションにあるファイルシステムのサイズも変更する。 IRIX/SGI 形式のディスクラベルは、現時点ではカーネルでサポートされていな い。また IRIX/SGI ヘッダディレクトリはまだ完全にはサポートできていな い 。 「 パーティションテーブルをファイルにダンプする」オプションは存在しない 。 関連項目 cfdisk(8), mkfs(8), parted(8), sfdisk(8) Linux 2.0 11 June 1998 FDISK(8)
FDISK(8) Linux Programmer’s Manual FDISK(8) NAME fdisk - Partition table manipulator for Linux SYNOPSIS fdisk [-uc] [-b sectorsize] [-C cyls] [-H heads] [-S sects] device fdisk -l [-u] [device...] fdisk -s partition... fdisk -v fdisk -h DESCRIPTION Hard disks can be divided into one or more logical disks called parti- tions. This division is described in the partition table found in sec- tor 0 of the disk. In the BSD world one talks about ‘disk slices’ and a ‘disklabel’. Linux needs at least one partition, namely for its root file system. It can use swap files and/or swap partitions, but the latter are more efficient. So, usually one will want a second Linux partition dedicated as swap partition. On Intel compatible hardware, the BIOS that boots the system can often only access the first 1024 cylinders of the disk. For this reason people with large disks often create a third partition, just a few MB large, typically mounted on /boot, to store the kernel image and a few auxiliary files needed at boot time, so as to make sure that this stuff is accessible to the BIOS. There may be reasons of security, ease of administration and backup, or testing, to use more than the minimum number of partitions. fdisk (in the first form of invocation) is a menu driven program for creation and manipulation of partition tables. It understands DOS type partition tables and BSD or SUN type disklabels. fdisk doesn’t understand GUID Partition Table (GPT) and it is not designed for large partitions. In particular case use more advanced GNU parted(8). The device is usually /dev/sda, /dev/sdb or so. A device name refers to the entire disk. The 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 a case 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. See also Linux kernel documentation (the Documenta- tion/devices.txt file). 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 parti- tion 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 and make some file system 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 parti- tions. 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 different problems. First of all, these C/H/S fields can be filled only when the number of heads and the number of sectors per track are known. Secondly, 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 some- thing that can be described in simplistic Cylinders/Heads/Sectors form), but is the disk geometry that MS-DOS uses for the partition ta- ble. 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) geome- try is required for good cooperation with other systems. Whenever a partition table is printed out, a consistency check is per- formed on the partition table entries. This check verifies that the physical and logical start and end points are identical, and that the 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. Parti- tions 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 a BLKRRPART ioctl() (reread partition table from disk) are performed before exiting when the partition table has been updated. Long ago it used to be necessary to reboot after the use of fdisk. I do not think this is the case anymore - indeed, rebooting too quickly might cause loss of not-yet-written data. Note that both the kernel and the disk hardware may buffer data. DOS 6.x WARNING The DOS 6.x FORMAT command looks for some information in the first sec- tor 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 -- we consider this 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 parti- tion 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. 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 fdisk or Linux cfdisk program. 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-ng 2.17 fdisk differentiates between logical and physical sector size. This option changes both sector sizes to sectorsize. -h Print help and then exit. -c Switch off DOS-compatible mode. (Recommended) -C cyls Specify the number of cylinders of the disk. I have no idea why anybody would want to do so. -H heads Specify the number of heads of the disk. (Not the physical num- ber, of course, but the number used for partition tables.) Rea- sonable values are 255 and 16. -S sects Specify the number of sectors per track of the disk. (Not the physical number, of course, but the number used for partition tables.) A reasonable value is 63. -l List the partition tables for the specified devices and then exit. If no devices are given, those mentioned in /proc/parti- tions (if that exists) are used. -u When listing partition tables, give sizes in sectors instead of cylinders. -s partition The size of the partition (in blocks) is printed on the standard output. -v Print version number of fdisk program and exit. BUGS There are several *fdisk programs around. Each has its problems and strengths. Try them in the order cfdisk, fdisk, sfdisk. (Indeed, cfdisk is a beautiful program that has strict requirements on the par- tition tables it accepts, and produces high quality partition tables. Use it if you can. fdisk is a buggy program that does fuzzy things - usually it happens to produce reasonable results. Its single advantage is that it has some support for BSD disk labels and other non-DOS par- tition tables. Avoid it if you can. sfdisk is for hackers only - the user interface is terrible, but it is more correct than fdisk and more powerful than both fdisk and cfdisk. Moreover, it can be used nonin- teractively.) These days there also is parted. The cfdisk interface is nicer, but parted does much more: it not only resizes partitions, but also the filesystems that live in them. The IRIX/SGI type disklabel is currently not supported by the kernel. Moreover, IRIX/SGI header directories are not fully supported yet. The option ‘dump partition table to file’ is missing. SEE ALSO cfdisk(8), sfdisk(8), mkfs(8), parted(8), partprobe(8), kpartx(8) AVAILABILITY The fdisk command is part of the util-linux-ng package and is available from ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/. Linux 2.0 11 June 1998 FDISK(8)
Copyright(C) linux-cmd.com All Rights Reserved. Author Takayuki Yukawa