状況

このブログが動いてるEC2インスタンスのEBSボリュームの容量は、デフォルトの8GB。

8GBで大丈夫しょ、と思ってたけど、気付いたらけっこう大丈夫じゃなくなりつつあった。

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        489M   56K  488M   1% /dev
tmpfs           497M     0  497M   0% /dev/shm
/dev/xvda1      7.8G  2.8G  4.9G  37% /

料金

ap-northeast-1だと、gp2ボリュームは$0.12 / GB / month。

30GBだと400円。

そんな高くないなーということで、30GBに増やす。

手順

基本的に、下記のドキュメントをトレースするだけ。

Linux の EBS ボリュームのサイズ、IOPS、またはタイプの変更

http://docs.aws.amazon.com/ja_jp/AWSEC2/latest/UserGuide/ebs-expand-volume.html

modify-volume

このブログが動いてるインスタンス自身からmodify-volumeを叩いてみた。

sshの接続が切れることも特になく、普通にレスポンスが返る。

$ aws ec2 modify-volume --region ap-northeast-1 --volume-id vol-1234abcd1234acbd1 --size 30 --volume-type gp2
{
    "VolumeModification": {
        "TargetSize": 30,
        "TargetVolumeType": "gp2",
        "ModificationState": "modifying",
        "VolumeId": "vol-1234abcd1234acbd1",
        "TargetIops": 100,
        "StartTime": "2017-09-25T16:02:10.044Z",
        "Progress": 0,
        "OriginalVolumeType": "gp2",
        "OriginalIops": 100,
        "OriginalSize": 8
    }
}

数分も経たず、optimizingになった。

$ aws ec2 describe-volumes-modifications --region ap-northeast-1 --volume-id vol-1234abcd1234acbd1
{
    "VolumesModifications": [
        {
            "TargetSize": 30,
            "TargetVolumeType": "gp2",
            "ModificationState": "optimizing",
            "VolumeId": "vol-1234abcd1234acbd1",
            "TargetIops": 100,
            "StartTime": "2017-09-25T16:02:10.044Z",
            "Progress": 37,
            "OriginalVolumeType": "gp2",
            "OriginalIops": 100,
            "OriginalSize": 8
        }
    ]
}

5, 6分くらいでcompleted。

$ aws ec2 describe-volumes-modifications --region ap-northeast-1 --volume-id vol-1234abcd1234acbd1
{
    "VolumesModifications": [
        {
            "TargetSize": 30,
            "TargetVolumeType": "gp2",
            "ModificationState": "completed",
            "VolumeId": "vol-1234abcd1234acbd1",
            "TargetIops": 100,
            "StartTime": "2017-09-25T16:02:10.044Z",
            "Progress": 100,
            "OriginalVolumeType": "gp2",
            "OriginalIops": 100,
            "EndTime": "2017-09-25T16:07:23.211Z",
            "OriginalSize": 8
        }
    ]
}

この時点では、容量は変化なし。

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        489M   56K  488M   1% /dev
tmpfs           497M     0  497M   0% /dev/shm
/dev/xvda1      7.8G  2.8G  4.9G  37% /

ファイルシステムを拡張

基本的にドキュメントの通りで良いけど、途中ちょっと違う箇所がある(resize2fs)。

$ sudo growpart /dev/xvda 1
CHANGED: disk=/dev/xvda partition=1: start=4096 old: size=16773086,end=16777182 new: size=62910430,end=62914526

$ lsblk
NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda    202:0    0  30G  0 disk
mqxvda1 202:1    0  30G  0 part /

$ sudo resize2fs /dev/xvda1
resize2fs 1.42.12 (29-Aug-2014)
Filesystem at /dev/xvda1 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
The filesystem on /dev/xvda1 is now 7863803 (4k) blocks long.

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        489M   56K  488M   1% /dev
tmpfs           497M     0  497M   0% /dev/shm
/dev/xvda1       30G  2.8G   27G  10% /

学ぶべきこと

ファイルシステムわかってないので勉強する必要がある。

https://www.systutorials.com/docs/linux/man/1-growpart/

https://www.systutorials.com/docs/linux/man/8-lsblk/

https://www.systutorials.com/docs/linux/man/8-resize2fs/

http://www.atmarkit.co.jp/flinux/index/indexfiles/linuxfsindex.html

https://www.amazon.co.jp/dp/B00SF6JN68