Translated message

A translation of this page exists in English.

Warning message

This translation is outdated. For the most up-to-date information, please refer to the English version.

RHEL 7 では、ディスクパーティションのオンラインサイズ変更がサポートされますか?

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux 7

Issue

  • Xen および KVM の両方で、仮想マシンの使用する仮想ブロックデバイスのオンラインサイズ変更がサポートされています。
  • しかしながら、起動用仮想ブロックデバイスのパーティションはすでに使用されているので、それらをオンラインで変更することはできず、再起動しない限り、起動用仮想ブロックデバイスに加えた変更は仮想マシンに反映されません。
  • パーティションが設定されたボリュームを動的に増やす機能が望まれますが、RHEL 7 では、ディスクパーティションのサイズをオンラインで変更することはできますか。
  • SAN にアタッチしたボリュームをオフラインにせずに動的に増やすことができません。ディスクパーティションのオンラインサイズ変更をサポートするこの機能は、いつごろ利用可能になりますか?

Resolution

論理ボリュームおよびファイルシステムのサイズを変更する機能は、長い間 Logical Volume Manager (LVM) により提供されてきました。この場合、単にブロックデバイス全体 (例: /dev/sdx) を LVM ボリュームグループの物理ボリュームとして使用しています。 古いスタイルのパーティションでは、パーティションのサイズ変更は必要ありません。 このため、論理ボリュームおよびファイルシステムを簡単に拡張することができました。

より古いスタイルのパーティションに関しては、この機能は RHEL 7 の現在のリリースに機能要求として追加されています (ディスクパーティションのオンラインサイズ変更のサポートを RHEL 7 に追加するために、RHBZ#853105 として REF が起草されています)。この機能により、RHEL 7 でディスクパーティションのサイズをオンラインで変更することができます。


免責事項: Red Hat により提供される以下の情報は、公開されている サービスレベルアグリーメント およびサポートプログラム (製品サポート (Red Hat カスタマーポータル)) の対象ではありません。情報はそのままの状態で提供され、本アーティクルの情報から作成された構成設定またはアプリケーションのインストールにより、オペレーティングシステムが Red Hat Global Support Services のサポートを受けられなくなる場合があります。本アーティクルの目的は、システムのニーズを満たす情報を提供することです。本アーティクルの情報は、ユーザー自身の責任において使用してください。

技術的な観点からは、ファイルシステムおよびそのベースとなるパーティションのサイズ変更 (既存のパーティションテーブルの変更) は、非常に 危険な操作と言えます。また、ディスク上の終了位置からしかパーティションのサイズを変更することはできません。ディスク上でパーティションを移動したり、開始位置からサイズを変更したりすることはできません。このような操作を行うとパーティションテーブルが破損し、ディスクデバイス上の全データがアクセス不能になり、結果としてデータの損失を招きます。パーティションのオンラインサイズ変更を実施することは可能ですが、推奨はされません。これは、データの完全性に対する懸念が唯一の理由であり、技術的に不可能なためではありません。

補足情報については、「How can I extend an existing file-system partition without destroying data?」のアーティクルも参照してください。


  • 使用中のパーティションのサイズをオンラインで変更するには、以下の手順を実施します。
# fdisk -l /dev/vda

Disk /dev/vda: 32.2 GB, 32212254720 bytes, 62914560 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000db7e6

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048     1026047      512000   83  Linux
/dev/vda2         1026048    28289023    13631488   8e  Linux LVM

# cat /proc/partitions 
major minor  #blocks  name

 252        0   31457280 vda
 252        1     512000 vda1
 252        2   13631488 vda2
  11        0    1048575 sr0
 253        0   10240000 dm-0
 253        1    2129920 dm-1

# pvs
  PV         VG          Fmt  Attr PSize  PFree
  /dev/vda2  rhel_vm-205 lvm2 a--  13.00g 1.20g
  • ディスク上のパーティションテーブルを通常の手順で変更します (fdisk コマンドの使用)。

    • パーティションを削除します。

      Command (m for help): d
      Partition number (1,2, default 2): 2
      Partition 2 is deleted
      
    • 新しいサイズでパーティションを作成し直します。

      Command (m for help): n
      Partition type:
         p   primary (1 primary, 0 extended, 3 free)
         e   extended
      Select (default p): p
      Partition number (2-4, default 2): 2
      First sector (1026048-62914559, default 1026048): 
      Using default value 1026048
      Last sector, +sectors or +size{K,M,G} (1026048-62914559, default 62914559): +18G
      Partition 2 of type Linux and of size 18 GiB is set
      
      Command (m for help): t
      Partition number (1,2, default 2): 2
      Hex code (type L to list all codes): 8e
      Changed type of partition 'Linux' to 'Linux LVM'
      
      Command (m for help): p
      
      Disk /dev/vda: 32.2 GB, 32212254720 bytes, 62914560 sectors
      Units = sectors of 1 * 512 = 512 bytes
      Sector size (logical/physical): 512 bytes / 512 bytes
      I/O size (minimum/optimal): 512 bytes / 512 bytes
      Disk label type: dos
      Disk identifier: 0x000db7e6
      
         Device Boot      Start         End      Blocks   Id  System
      /dev/vda1   *        2048     1026047      512000   83  Linux
      /dev/vda2         1026048    38774783    18874368   8e  Linux LVM
      
    • ディスク上のパーティションテーブルに加えた変更をコミットします。

      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.
      
    • ディスク上のパーティションテーブルは更新されても、メモリー上のカーネルパーティションテーブルは更新されていない点に注意してください。

      # partprobe 
      Error: Partition(s) 2 on /dev/vda have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use.  As a result, the old partition(s) will remain in use.  You should reboot now before making further changes.
      
      # cat /proc/partitions | grep vd
       252        0   31457280 vda
       252        1     512000 vda1
       252        2   13631488 vda2
      
  • --update オプションでブロックデバイスを指定して partx (util-linux パッケージにより提供される) を実行し、メモリー内のカーネルパーティションテーブルをディスク上のパーティションテーブルのサイズで更新します。

    # partx -u /dev/vda
    
  • メモリー内のカーネルパーティションテーブルが新しいサイズで更新されていることを確認します。

    # cat /proc/partitions | grep vd
     252        0   31457280 vda
     252        1     512000 vda1
     252        2   18874368 vda2
    
  • 必要に応じてその他の手順を実施します (以下の例では、パーティション上の PV を拡張しています)。

    # pvresize /dev/vda2
      Physical volume "/dev/vda2" changed
      1 physical volume(s) resized / 0 physical volume(s) not resized
    
    # pvs
      PV         VG          Fmt  Attr PSize  PFree
      /dev/vda2  rhel_vm-205 lvm2 a--  18.00g 6.20g
    

Root Cause

  • 使用中のパーティションのオンラインサイズ変更を許可するためには、カーネルおよびユーザーランドの両方に変更を加える必要があります。

    • RHEL 7 カーネルには、BLKPG_RESIZE_PARTITION 操作をサポートするのに必要な BLKPG ioctl に対する変更 (block: add partition resize function to blkpg ioctl) が含まれています。
    • RHEL 7 util-linux パッケージに含まれる partx および resizepart バイナリーは、現在 BLKPG ioctl の BLKPG_RESIZE_PARTITION 操作をサポートする唯一のユーザーランドコマンドです。

Diagnostic Steps

http://lwn.net/Articles/506063/ を参照してください。

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments