CentOS EC2 インスタンスのデフォルトの MBR パーティションスキームを GPT に変換して、EBS ボリュームの MBR パーティションに対する 2 TiB の制限を回避する方法を教えてください。

所要時間7分
0

Amazon Elastic Compute Cloud (Amazon EC2) インスタンスで、centos.org の AWS Marketplace にある CentOS 7 を実行しています。MBR パーティションには 2 TiB の制限があります。この制限を回避するために、Amazon Elastic Block Store (Amazon EBS) ボリュームのパーティションスキームを GPT パーティションスキームに変換したいと考えています。

解決策

重要: インスタンスを停止して起動する前に、次の点を確認してください。

  • インスタンスを停止して起動すると、インスタンスストアのデータは失われます。インスタンスがインスタンスストアベースの場合や、データを含むインスタンスストアボリュームがある場合、インスタンスを停止するとデータは失われます。詳細については、「Amazon EC2 インスタンスのルートボリューム」を参照してください。
  • インスタンスが Amazon EC2 Auto Scaling グループの一部である場合、インスタンスを停止するとインスタンスが終了する可能性があります。Amazon EMR、AWS CloudFormation、または AWS Elastic Beanstalk を使用してインスタンスを起動した際に、そのインスタンスは AWS Auto Scaling グループの一部である可能性があります。このシナリオにおいては、インスタンスが終了するかどうかは、Auto Scaling グループのインスタンススケールイン保護設定によって異なります。インスタンスが Auto Scaling グループの一部である場合は、Auto Scaling グループから一時的にインスタンスを削除します。
  • インスタンスを停止および再開すると、インスタンスのパブリック IP アドレスが変更されます。パブリック IP アドレスではなく Elastic IP アドレスを使用するのがベストプラクティスです。Amazon Route 53 を使用している場合は、パブリック IP アドレスが変更されたときに Route 53 の DNS レコードを更新しなければならない場合があります。

注: 解決手順を開始する前に、EBS ボリュームのバックアップを作成するのがベストプラクティスです。

CentOS EC2 インスタンスのデフォルトの MBR パーティションスキームを GPT に変換するには、次の手順を実行します。

  1. Amazon EC2 コンソールを開きます。

  2. CentOS 7 を実行する AWS Marketplace Amazon マシンイメージ (AMI) からインスタンスを起動します。

  3. 最初のインスタンスと同じアベイラビリティーゾーンで、ルートボリュームが 3 TiB の同じ CentOS AMI から 2 番目のインスタンスを起動します。
    注: すでに CentOS 7 インスタンスがある場合は、新しい CentOS 7 インスタンスを起動する必要はありません。CentOS 7 では、ルートボリュームを変更し、サイズを 2 TiB よりも大きいものに拡張します。

  4. ルートボリュームが 3 TiB のインスタンスを停止してから、ステップ 2 で作成したインスタンスを停止します。
    注: CentOS 7 は AWS Marketplace AMI からのものであるため、AWS Marketplace コードを含むボリュームをアタッチする前にインスタンスを停止する必要があります。インスタンスを停止しないと、次のエラーが発生します。 "Error attaching volume: Cannot attach volume 'vol-#################' with Marketplace codes as the instance 'i-################' is not in the 'stopped' state."

  5. 停止したインスタンスからルートボリューム (/dev/xvda または /dev/sda1) をデタッチします。次に、そのボリュームを、ステップ 2 で作成したインスタンスに /dev/sdf としてアタッチします。
    注: Xen インスタンスタイプを使用する場合、デバイス名は /dev/sdf または /dev/sda と表示されます。Nitro インスタンスタイプを使用する場合、デバイス名は /dev/nvme0n1 または /dev/nvme1n1 と表示されます。

  6. ステップ 2 で起動したインスタンスを起動し、SSH で接続します。

  7. /dev/sdf のルートパーティションを確認するには、lsblk コマンドを使用します。/dev/sdf のルートパーティションのサイズは、次の例に示すように、2 TiB のみです。

    # lsblk
    NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    (snip)
    xvdf    202:80    0   3T  0 disk
    └─xvdf1 202:81    0   2T  0 part
    (snip)

    注: 次の例に示すように、ルートファイルシステム "/" に /dev/xvdf1 がマウントされる場合があります。その場合は、/dev/xvda1 がルートファイルシステムとしてマウントされるまで、インスタンスの停止と起動を数回繰り返してください。

    # lsblk
    NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    xvda    202:0    0   8G  0 disk
    └─xvda1 202:1    0   8G  0 part /
    xvdf    202:80   0   3T  0 disk
    └─xvdf1 202:81   0   2T  0 part
  8. パーティションテーブルを MBR から GPT に変換するには、gdisk ツールを使用します。

    # sudo gdisk /dev/xvdf
    GPT fdisk (gdisk) version 1.0.1
    Partition table scan:
      MBR: MBR only
      BSD: not present
      APM: not present
      GPT: not present
    
    Found invalid GPT and valid MBR; converting MBR to GPT format
    in memory. THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by
    typing 'q' if you don't want to convert your MBR partitions
    to GPT format!

    注: gdisk ツールをインストールするには、次のコマンドを実行します。

    sudo yum install gdisk -y
  9. GPT パーティションを作成するには、プロンプトで次のコマンドを実行します。[最後のセクター] プロンプトで enter を入力し、デフォルトのセクター番号である 2047 を使用します。

    Command (? for help): n
    
    Partition number (2-128, default 2): 128
    First sector (34-6291455966, default = 4294967296) or {+-}size{KMGTP}: 34
    Last sector (34-2047, default = 2047) or {+-}size{KMGTP}:
    Current type is 'Linux filesystem'
    Hex code or GUID (L to show codes, Enter = 8300): ef02
    Changed type of partition to 'BIOS boot partition'

    注: この例では、ef02 が BIOS ブートパーティション番号です。

  10. ルートパーティションを削除するには、プロンプトで次のコマンドを実行します。

Command (? for help): d
Partition number (1-128): 1
  1. ルートパーティションを 3-TiB にして再作成するには、プロンプトで次のコマンドを実行します。[最初のセクター][最後のセクター]、および [16 進コード] または [GUID] プロンプトで、enter を入力し、デフォルト設定を使用します。
Command (? for help): n
Partition number (1-128, default 1): 1
First sector (2048-6291455966, default = 2048) or {+-}size{KMGTP}:
Last sector (2048-6291455966, default = 6291455966) or {+-}size{KMGTP}:
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300):
Changed type of partition to 'Linux filesystem'
  1. GPT パーティションテーブルを保存するには、プロンプトで次のコマンドを実行します。
Command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/xvdf.
The operation has completed successfully.

新しいパーティション情報を確認するには、次のコマンドを実行します。

sudo gdisk -l /dev/xvdf
GPT fdisk (gdisk) version 0.8.10
Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.
Disk /dev/xvda: 6291456000 sectors, 2.9 TiB
Logical sector size: 512 bytes
Disk identifier (GUID): 35D6B819-1C79-4EC0-920F-4D1191609505
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 6291455966
Partitions will be aligned on 8-sector boundaries
Total free space is 0 sectors (0 bytes)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048      6291455966   2.9 TiB     8300  Linux filesystem
 128              34            2047   1007.0 KiB  EF02  BIOS boot partition
  1. デバイス /dev/xvdf1 のファイルシステムが正しいことを確認するには、ファイルシステムチェックおよび修復ツールを実行します。
    CentOS 7:
# sudo xfs_repair /dev/xvdf1
Phase 1 - find and verify superblock...
        - reporting progress in intervals of 15 minutes
Phase 2 - using internal log
        - zero log...
        - scan filesystem freespace and inode maps...
        - 05:27:07: scanning filesystem freespace - 1025 of 1025 allocation groups done
        - found root inode chunk
Phase 3 - for each AG...
        - scan and clear agi unlinked lists...
        - 05:27:07: scanning agi unlinked lists - 1025 of 1025 allocation groups done
        - process known inodes and perform inode discovery...
        - agno = 960
        - agno = 0
        - agno = 240
        - agno = 480

(snip)
        - agno = 238
        - agno = 239
        - 05:27:08: process known inodes and inode discovery - 25856 of 25856 inodes done
        - process newly discovered inodes...
        - 05:27:08: process newly discovered inodes - 1025 of 1025 allocation groups done
Phase 4 - check for duplicate blocks...
        - setting up duplicate extent list...
        - 05:27:08: setting up duplicate extent list - 1025 of 1025 allocation groups done
        - check for inodes claiming duplicate blocks...
        - agno = 0
        - agno = 1
        - agno = 2
        - agno = 3
        - agno = 4

(snip)
        - agno = 1021
        - agno = 1022
        - agno = 1023
        - agno = 1024
        - 05:27:08: check for inodes claiming duplicate blocks - 25856 of 25856 inodes done
Phase 5 - rebuild AG headers and trees...
        - 05:27:08: rebuild AG headers and trees - 1025 of 1025 allocation groups done
        - reset superblock...
Phase 6 - check inode connectivity...
        - resetting contents of realtime bitmap and summary inodes
        - traversing filesystem ...
        - traversal finished ...
        - moving disconnected inodes to lost+found ...
Phase 7 - verify and correct link counts...
        - 05:27:08: verify and correct link counts - 1025 of 1025 allocation groups done
done

CentOS 6:

# sudo e2fsck -f /dev/xvdf1
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/xvdf1: 18734/524288 files (0.2% non-contiguous), 284948/2096896 blocks
  1. ファイルシステムのサイズを変更して 3 TiB に拡張するには、xfs_growfs または resize2fs コマンドを実行します。
    CentOS 7:
# sudo mount -o nouuid /dev/xvdf1 /mnt
# sudo xfs_growfs /dev/xvdf1
meta-data=/dev/xvdf1             isize=512    agcount=1025, agsize=524224 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=536870656, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 536870656 to 786431739

CentOS 6:

# sudo resize2fs /dev/xvdf1
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/xvdf1 to 786431739 (4k) blocks.

The filesystem on /dev/xvdf1 is now 786431739 blocks long.
  1. Grub をデバイス /dev/xvdf1 にインストールし、次のコマンドを使用して設定します。
    注: CentOS 6 では、Grub のインストールは不要です。CentOS 6 を使用している場合は、ステップ 15 に進んでください。
    CentOS 7:
sudo mount --bind /proc /mnt/procsudo mount --bind /sys /mnt/sys
sudo mount --bind /dev /mnt/dev
sudo chroot /mnt /bin/bash
grub2-install /dev/xvdf
exit
sudo umount -l /mnt/dev
sudo umount -l /mnt/sys
sudo umount -l /mnt/proc
sudo umount -l /mnt
  1. インスタンスを停止します。
  2. ボリューム /dev/xvdf を実行中のインスタンスからデタッチします。
  3. ボリューム /dev/xvdf/dev/sda1 として元の値に戻します。
  4. 元のインスタンスを起動し、SSH で接続します。
  5. 元のインスタンスのルートボリュームに 3 TiB の容量があることを確認するには、lsblk コマンドを実行します。
lsblk
NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda    202:0    0   3T  0 disk
└─xvda1 202:1    0   3T  0 part /

関連情報

EC2 Ubuntu インスタンスのデフォルトの MBR パーティションスキームを GPT に変換して、EBS ボリュームの MBR パーティションに対する 2 TiB の制限を回避する方法を教えてください

AWS公式
AWS公式更新しました 6ヶ月前
コメントはありません