GNU/Linux >> Linux の 問題 >  >> Linux

LinuxでのFdiskコマンド(パーティションの管理)

Fdiskは、Linuxでディスクパーティションを管理するために使用されるテキストベースのユーティリティです。 fdiskを使用すると、すべてのディスクパーティションを表示し、新しいパーティションを作成し、既存のハードディスクパーティションを削除して、パーティションのサイズを表示できます。

fdiskを使用すると、ディスクのサイズに基づいて、最大4つのプライマリパーティションと任意の数の論理パーティションを作成できます。 1つのパーティションには最低40MBのサイズが必要であることに注意してください。

このチュートリアルでは、いくつかの例を使用して、Linuxでfdiskコマンドを使用する方法を学びましょう。

1)既存のすべてのディスクパーティションを表示する

新しいパーティションを作成したり、既存のパーティションを変更したりする前に、システムで使用可能なすべてのパーティションを表示することをお勧めします。

このコマンドは、接続されているすべてのハードディスクのパーティションを一覧表示します。システムに複数のディスクがある場合、パーティションリストはデバイスの/dev名の順に並べられます。たとえば、/ dev / sda、/ dev / sdb、/ dev/sdcなどです。

fdisk -lを使用します 使用可能なすべてのパーティションを次のように表示するには:

# fdisk -l

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xf6edf6ed

Device Boot Start End Blocks Id System
/dev/sda1 1 1959 15735636 c W95 FAT32 (LBA)
/dev/sda2 1960 5283 26700030 f W95 Ext'd (LBA)
/dev/sda3 5284 6528 10000462+ 7 HPFS/NTFS
/dev/sda4 6529 9729 25712032+ c W95 FAT32 (LBA)
/dev/sda5 * 1960 2661 5638752 83 Linux
/dev/sda6 2662 2904 1951866 83 Linux
/dev/sda7 2905 3147 1951866 83 Linux
/dev/sda8 3148 3264 939771 82 Linux swap / Solaris
/dev/sda9 3265 5283 16217586 b W95 FAT32

2)特定のハードディスクのパーティションを表示する

'/ dev / sda'ハードディスクのすべてのパーティションを表示するには、次の手順を実行します。

# fdisk -l /dev/sda

fdiskコマンドm

を使用してすべてのfdiskコマンドを表示する

fdiskコマンドmを使用します 、以下に示すように、使用可能なすべてのfdiskコマンドを表示するには:

# fdisk /dev/sda

The number of cylinders for this disk is set to 9729.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

3)ハードディスクパーティションを削除します

複数のパーティション(たとえば、/ dev / sda6、/ dev / sda7、/ dev / sda8)を1つのディスクパーティションに結合したいとします。これを行うには、以下に示すように、最初にこれらの個々のパーティションをすべて削除する必要があります。

# fdisk /dev/sda

The number of cylinders for this disk is set to 9729.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xf6edf6ed

Device Boot Start End Blocks Id System
/dev/sda1 1 1959 15735636 c W95 FAT32 (LBA)
/dev/sda2 1960 5283 26700030 f W95 Ext'd (LBA)
/dev/sda3 5284 6528 10000462+ 7 HPFS/NTFS
/dev/sda4 6529 9729 25712032+ c W95 FAT32 (LBA)
/dev/sda5 * 1960 2661 5638752 83 Linux
/dev/sda6 2662 2904 1951866 83 Linux
/dev/sda7 2905 3147 1951866 83 Linux
/dev/sda8 3148 3264 939771 82 Linux swap / Solaris
/dev/sda9 3265 5283 16217586 b W95 FAT32

Command (m for help): d
Partition number (1-9): 8

Command (m for help): d
Partition number (1-8): 7

Command (m for help): d
Partition number (1-7): 6

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

4)新しいディスクパーティションを作成します

既存のパーティションをすべて削除したら、次に示すように、使用可能なすべてのスペースを使用して新しいパーティションを作成できます。

# fdisk /dev/sda

The number of cylinders for this disk is set to 9729.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n
First cylinder (2662-5283, default 2662):
Using default value 2662
Last cylinder, +cylinders or +size{K,M,G} (2662-3264, default 3264):
Using default value 3264
In the above example, fdisk n command is used to create new partition with the specific size. While creating a new partition, it expects following two inputs.
Starting cylinder number of the partition to be create (First cylinder).
Size of the partition (or) the last cylinder number (Last cylinder, +cylinders or +size ).
Please keep in mind that you should issue the fdisk write command (w) after any modifications.
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

パーティションが作成されたら、次に示すようにmkfsコマンドを使用してフォーマットします。

# mkfs.ext3 /dev/sda7

5)既存のパーティションのサイズを表示する

以下に示すように、fdisk -s パーティションのサイズをブロック単位で表示します。

次の例では、サイズ'/ dev/sda7'が4900MBと表示されています。

# fdisk -s /dev/sda7
4843566

6)パーティションのブートフラグを切り替えます

Fdiskコマンドは、各パーティションのブートフラグを表示します。対応するパーティションのブートフラグを無効または有効にする場合は、次の手順を実行します。

# fdisk /dev/sda

The number of cylinders for this disk is set to 9729.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xf6edf6ed

Device Boot Start End Blocks Id System
/dev/sda1 1 1959 15735636 c W95 FAT32 (LBA)
/dev/sda2 1960 5283 26700030 f W95 Ext'd (LBA)
/dev/sda3 5284 6528 10000462+ 7 HPFS/NTFS
/dev/sda4 6529 9729 25712032+ c W95 FAT32 (LBA)
/dev/sda5 * 1960 2661 5638752 83 Linux
/dev/sda6 3265 5283 16217586 b W95 FAT32
/dev/sda7 2662 3264 4843566 83 Linux

Partition table entries are not in disk order

Command (m for help): a
Partition number (1-7): 5

Command (m for help): p

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xf6edf6ed

Device Boot Start End Blocks Id System
/dev/sda1 1 1959 15735636 c W95 FAT32 (LBA)
/dev/sda2 1960 5283 26700030 f W95 Ext'd (LBA)
/dev/sda3 5284 6528 10000462+ 7 HPFS/NTFS
/dev/sda4 6529 9729 25712032+ c W95 FAT32 (LBA)
/dev/sda5 1960 2661 5638752 83 Linux
/dev/sda6 3265 5283 16217586 b W95 FAT32
/dev/sda7 2662 3264 4843566 83 Linux

Partition table entries are not in disk order

Command (m for help):

上記のように、パーティション'/ dev/sda5'ではブートフラグが無効になっています。

7)パーティションテーブルの順序を修正

論理パーティションを削除して再作成すると、「パーティションの順序が正しくない」という問題が発生する場合があります。つまり、「パーティションテーブルのエントリがディスク順にありません」というエラーメッセージが表示されます。

たとえば、3つの論理パーティション(sda6、sda7、およびsda8)を削除し、新しいパーティションを作成する場合、新しいパーティション名はsda6であると予想される場合があります。ただし、システムがsda7として新しいパーティションを作成した可能性があります。これは、パーティションが削除された後、「sda9」パーティションがsda6として移動され、空き領域が最後に移動されたためです。

このパーティションの順序の問題を修正し、新しく作成されたパーティションにsda6を割り当てるには、エキスパートコマンドfを実行します。 以下に示すように。

$ fdisk /dev/sda

The number of cylinders for this disk is set to 9729.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xf6edf6ed

Device Boot Start End Blocks Id System
/dev/sda1 1 1959 15735636 c W95 FAT32 (LBA)
/dev/sda2 1960 5283 26700030 f W95 Ext'd (LBA)
/dev/sda3 5284 6528 10000462+ 7 HPFS/NTFS
/dev/sda4 6529 9729 25712032+ c W95 FAT32 (LBA)
/dev/sda5 * 1960 2661 5638752 83 Linux
/dev/sda6 3265 5283 16217586 b W95 FAT32
/dev/sda7 2662 3264 4843566 83 Linux

Partition table entries are not in disk order

Command (m for help): x

Expert command (m for help): f
Done.

Expert command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

パーティションテーブルの順序が修正されると、「パーティションテーブルのエントリはディスクの順序ではありません」というエラーメッセージは表示されなくなります。

# fdisk -l

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xf6edf6ed

Device Boot Start End Blocks Id System
/dev/sda1 1 1959 15735636 c W95 FAT32 (LBA)
/dev/sda2 1960 5283 26700030 f W95 Ext'd (LBA)
/dev/sda3 5284 6528 10000462+ 7 HPFS/NTFS
/dev/sda4 6529 9729 25712032+ c W95 FAT32 (LBA)
/dev/sda5 * 1960 2661 5638752 83 Linux
/dev/sda6 2662 3264 4843566 83 Linux
/dev/sda7 3265 5283 16217586 b W95 FAT32

結論

このチュートリアルでは、Linuxでfdiskコマンドを使用してパーティションを管理する方法を学びました。読んで楽しんでいただければ幸いです。下のコメントボックスに提案を残してください。注:何をしているかわからない場合は、パーティションを削除、変更、または追加しないでください。データが失われる可能性があります。注意してください。


Linux
  1. Linuxでディスクをパーティション分割する方法

  2. 「cat」コマンドを使用してLinuxパーティションをバックアップまたはクローンする方法

  3. Linux で fdisk を使用してディスクをパーティション分割する方法

  1. Linuxでパーティションを削除する方法

  2. Linuxでパーティションを作成する方法

  3. Linuxでpartedコマンドを使用してディスクパーティションを作成する方法

  1. Linuxディスクの使用状況とパーティションを監視するための上位5つのツール

  2. LinuxでのFdiskコマンド(ディスクパーティションの作成)

  3. Linuxddコマンドを使用してディスクをクローン化する方法