2018年6月14日木曜日

Amazon Web Service (AWS) EC2 で CentOS 7 から EBS を拡張した時のメモ

自分のチート用

1. instance id を取得
   curl http://169.254.169.254/latest/meta-data/instance-id

2. リージョンを取得
   curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone

3. volume-id を取得
   aws ec2 describe-instances --instance-id i-002e270412ee392b6 --region us-west-2 | jq -r ".Reservations[0].Instances[0].BlockDeviceMappings[0].Ebs.VolumeId"

4. volume を拡張
   aws ec2 modify-volume --region us-west-2 --volume-id vol-0e3eb2f3f6e75583c --size 32

5. 対象のディスクを確認
   $ lsblk
   NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
   xvda    202:0    0  32G  0 disk
   └xvda1 202:1    0   8G  0 part /

6. パーティションを拡張
   $ sudo growpart /dev/xvda 1
   CHANGED: partition=1 start=2048 old: size=16775168 end=16777216 new: size=67106783,end=67108831

7. ファイルシステムタイプを確認
   $ mount | grep xvda1
   /dev/xvda1 on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)

8. ファイルシステムを拡張 (xfsの場合)
   $ sudo xfs_growfs -d /
   meta-data=/dev/xvda1             isize=512    agcount=4, agsize=524224 blks
            =                       sectsz=512   attr=2, projid32bit=1
            =                       crc=1        finobt=0 spinodes=0
   data     =                       bsize=4096   blocks=2096896, 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 2096896 to 8388347


おしまい。