37.3. パーティションの作成と削除

ハードディスクを増設したときなど、新たにパーティションを作成するには fdisk コマンドを使用します。なお、-l オプションを指定すると、以下のように既存のパーティション情報を確認することができます。

# fdisk -l /dev/hda

Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1           8       64228+  83  Linux
/dev/sda2               9          73      522112+  82  Linux swap / Solaris
/dev/sda3              74        1044     7799557+  83  Linux

ここでは、/dev/sdb に接続された SCSI ハードディスクに対して新規パーティションを作成する手順を解説します。

最初に以下のように fdisk コマンドを実行します。

# fdisk /dev/sdb

The number of cylinders for this disk is set to 1116.
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):

fdisk が起動すると、コマンドの入力を待ち受けるプロンプトが表示されます。

m を入力すると、使用可能なコマンドリストが表示されます。

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)

p を指定すると現在のパーティション情報を確認します。新しいハードディスクの場合はパーティション情報は表示されません。

Command (m for help): p

Disk /dev/sdb: 9184 MB, 9184760320 bytes
255 heads, 63 sectors/track, 1116 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

新規パーティションを作成するには n コマンドを指定します。

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p

基本パーティションならば p、拡張パーティションならば e を入力します。すでに拡張パーティションが存在する場合は、論理パーティションを作成する l を入力することができます。ここでは、基本パーティション(/dev/sdb1)を作成しますので p を入力します。

Partition number (1-4): 1

基本パーティションの番号を指定します。ここでは、1 を入力します。

次にパーティションのサイズを指定します。

First cylinder (1-1116, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1116, default 1116):
Using default value 1116

開始シリンダを入力し、次に終了シリンダ、または作成するパーティションのサイズを M で指定します。開始シリンダは、空き領域の先頭のシリンダ番号がデフォルトで指定されますので、通常は、そのまま[Enter]キーを押します。終了シリンダには、作成するパーティションのサイズを指定します。MB 単位での指定が可能なので、例えば、500MB のパーティションを作成するには、終了シリンダに +500M と指定します。上記のように入力せずに、そのまま[Enter]キーを押せば、割り当て可能な最大のシリンダ番号が指定されます。

p コマンドを指定してパーティションが作成できたことを確認します。

Command (m for help): p

Disk /dev/sdb: 9184 MB, 9184760320 bytes
255 heads, 63 sectors/track, 1116 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1116     8964238+  83  Linux

作成したパーティションのシステムタイプはデフォルトで Linux になります。スワップパーティションや LVM など、他のシステムタイプに変更したい場合は t コマンドを使用します。

Command (m for help): t
Selected partition 1

複数のパーティションが存在する場合はパーティション番号を要求されますので、以下のように指定します。

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

ファイルシステムのタイプを変更するには、そのシステムタイプを表す数字を指定します。システムタイプのリストを確認するには l を入力します。

Hex code (type L to list codes): l

 0  Empty           1c  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid
 1  FAT12           1e  Hidden W95 FAT1 75  PC/IX           be  Solaris boot
 2  XENIX root      24  NEC DOS         80  Old Minix       c1  DRDOS/sec (FAT-
 3  XENIX usr       39  Plan 9          81  Minix / old Lin c4  DRDOS/sec (FAT-
 4  FAT16 <32M      3c  PartitionMagic  82  Linux swap      c6  DRDOS/sec (FAT-
 5  Extended        40  Venix 80286     83  Linux           c7  Syrinx
 6  FAT16           41  PPC PReP Boot   84  OS/2 hidden C:  da  Non-FS data
 7  HPFS/NTFS       42  SFS             85  Linux extended  db  CP/M / CTOS / .
 8  AIX             4d  QNX4.x          86  NTFS volume set de  Dell Utility
 9  AIX bootable    4e  QNX4.x 2nd part 87  NTFS volume set df  BootIt
 a  OS/2 Boot Manag 4f  QNX4.x 3rd part 8e  Linux LVM       e1  DOS access
 b  W95 FAT32       50  OnTrack DM      93  Amoeba          e3  DOS R/O
 c  W95 FAT32 (LBA) 51  OnTrack DM6 Aux 94  Amoeba BBT      e4  SpeedStor
 e  W95 FAT16 (LBA) 52  CP/M            9f  BSD/OS          eb  BeOS fs
 f  W95 Ext'd (LBA) 53  OnTrack DM6 Aux a0  IBM Thinkpad hi ee  EFI GPT
10  OPUS            54  OnTrackDM6      a5  FreeBSD         ef  EFI (FAT-12/16/
11  Hidden FAT12    55  EZ-Drive        a6  OpenBSD         f0  Linux/PA-RISC b
12  Compaq diagnost 56  Golden Bow      a7  NeXTSTEP        f1  SpeedStor
14  Hidden FAT16 <3 5c  Priam Edisk     a8  Darwin UFS      f4  SpeedStor
16  Hidden FAT16    61  SpeedStor       a9  NetBSD          f2  DOS secondary
17  Hidden HPFS/NTF 63  GNU HURD or Sys ab  Darwin boot     fd  Linux raid auto
18  AST SmartSleep  64  Novell Netware  b7  BSDI fs         fe  LANstep
1b  Hidden W95 FAT3 65  Novell Netware  b8  BSDI swap       ff  BBT

例えば、LVM に変更するには、8e を指定します。

Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

p コマンドで作成したパーティション情報を確認します。

Command (m for help): p

Disk /dev/sdb: 9184 MB, 9184760320 bytes
255 heads, 63 sectors/track, 1116 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1116     8964238+  8e  Linux LVM

最後に w コマンドでハードディスクにパーティションを作成します。 w コマンドを実行するまでは、fdisk で設定した内容は反映されません。

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

Calling ioctl() to re-read partition table.
Syncing disks.

システムの再起動を要求する以下のメッセージが表示されたときは、再起動が必要です。

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.
Syncing disks.

次に作成したパーティションを削除してみます。

# fdisk /dev/sdb

The number of cylinders for this disk is set to 1116.
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/sdb: 9184 MB, 9184760320 bytes
255 heads, 63 sectors/track, 1116 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1116     8964238+  8e  Linux LVM

パーティションを削除するには d コマンドを使用します。

Command (m for help): d
Selected partition 1

複数のパーティションが存在する場合はパーティション番号を要求されますので、以下のように指定します。

Command (m for help): d
Partition number (1-4): 3

最後に w コマンドでパーティションを削除します。

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

Calling ioctl() to re-read partition table.
Syncing disks.