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

所要時間7分
0

Amazon Elastic Compute Cloud (Amazon EC2) インスタンスが、centos.org によって AWS Marketplace から CentOS 7 を実行しています。Amazon Elastic Block Store (Amazon EBS) ボリュームのデフォルトの MBR パーティションスキームを GPT パーティションスキームに変換して、MBR パーティションの 2 TiB 制限をバイパスする方法を教えてください。

解決方法

警告: インスタンスを停止して起動する前に、必ず以下の点を頭に入れておいてください。

  • インスタンスを停止して起動すると、インスタンスストアデータが失われます。インスタンスがインスタンスストアでバックアップされているか、データを含むインスタンスストアボリュームがある場合、インスタンスが停止するとデータが失われます。詳細については、「インスタンスのルートデバイスタイプの判別」を参照してください。

  • インスタンスが Amazon EC2 Auto Scaling グループの一部である場合、インスタンスを停止するとインスタンスが終了することがあります。Amazon EMR、AWS CloudFormation、または AWS Elastic Beanstalk を使用してインスタンスを起動した場合、インスタンスは AWS Auto Scaling グループの一部である可能性があります。このシナリオでインスタンスが削除されるかどうかは、Auto Scaling グループのインスタンススケールイン保護の設定によって異なります。インスタンスが Auto Scaling グループの一部である場合は、解決手順を開始する前に、一時的に Auto Scaling グループからインスタンスを削除してください。

  • インスタンスを停止および再開すると、インスタンスのパブリック IP アドレスが変更されます。インスタンスに外部トラフィックをルーティングする際は、パブリック IP アドレスではなく Elastic IP アドレスを使用することをお勧めします。Route 53 を使用している場合は、パブリック IP が変更されたときに Route 53 DNS レコードを更新する必要がある場合があります。

注意: 解決手順を開始する前に、EBS ボリュームのバックアップを作成することをお勧めします。

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

2.    CentOS 7 を実行する AWS Marketplace Amazon Machine Image (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-xxxxxxxxxxxxxxxxx' with Marketplace codes as the instance 'i-xxxxxxxxxxxxxxxx' is not in the 'stopped' state.」

5.    停止したインスタンスからルートボリューム (/dev/xvda または /dev/sda1) をデタッチし、ステップ 2 で作成したインスタンスに /dev/sdf としてアタッチします。

注意: t2 などの Xen プラットフォームのインスタンスタイプを使用します。t3 などの Nitro プラットフォームを使用する場合、デバイス名は NVMExn1 に変更されます。

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

7.    lsblk コマンドを使用して、/dev/sdf のルートパーティションを表示します。次の例に示すように、/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.    gdisk ツールを使用して、パーティションテーブルを MBR から GPT に変換します。

注意: gdisk ツールがまだインストールされていない場合は、sudo yum install gdisk-y コマンドを使用してインストールできます。

# 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!

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

11.    プロンプトで次のコマンドを入力して、ルートパーティションを 3 TB に再作成します。最初のセクター最後のセクター、および 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'

12.    プロンプトで次のコマンドを入力して、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.

gdisk コマンドを実行して、新しいパーティション情報を表示します。

$ 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

13.    ファイルシステムチェックおよび修復ツールを使用して、デバイス /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

14.    xfs_growfs コマンドまたは resize2fs コマンドを実行して、ファイルシステムのサイズを変更し、3 TB に拡張します。

注意: ファイルシステムのサイズ変更には数分かかる場合があります。

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.

15.    デバイス /dev/xvdf1 に Grub をインストールし、次のコマンドを使用して設定します。

注意: S 6では、Grubのインストールは必要ありません。CentOS 6 を使用している場合は、ステップ 16 に進みます。

CentOS 7:

sudo mount --bind /proc /mnt/proc
sudo 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

16.    インスタンスを停止します。

17.    停止したインスタンスからボリューム /dev/xvdf をデタッチします。

18.    ボリューム /dev/xvdf を /dev/sda1 として元のインスタンスにアタッチします。

19.    元のインスタンスを起動し、SSH で接続します。

20.    lsblk コマンドを実行して、元のインスタンスのルートボリュームに 3 TiB のスペースがあることを確認します。

$ lsblk
NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda    202:0    0   3T  0 disk 
└─xvda1 202:1    0   3T  0 part /

関連情報

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

AWS公式
AWS公式更新しました 4年前
コメントはありません