3
1

More than 3 years have passed since last update.

EC2でaarch64のCentOS8.2を起動したときのディスク拡張

Posted at

先日r6gインスタンスでZabbixサーバーを構築したとき、32GBストレージあるはずなのに8GBしか領域がなく、拡張するときに手間取ったので備忘録兼ねての記事です。

起動時の状態

32GBのSSDで起動したはずなのに/配下が8GBしかありません
ちなみにこの状態でxfs_growfs -d /とか叩いても拡張はできませんでした

[centos@ip-10-0-2-177 ~]$ df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
devtmpfs       devtmpfs  3.7G     0  3.7G   0% /dev
tmpfs          tmpfs     3.7G     0  3.7G   0% /dev/shm
tmpfs          tmpfs     3.7G   22M  3.7G   1% /run
tmpfs          tmpfs     3.7G     0  3.7G   0% /sys/fs/cgroup
/dev/nvme0n1p2 xfs       7.8G  1.4G  6.5G  18% /
/dev/nvme0n1p1 vfat      599M  6.4M  593M   2% /boot/efi
tmpfs          tmpfs     754M     0  754M   0% /run/user/1000

fdisk -lを叩くとなんか問題が見つかるようです

[root@ip-10-0-2-177 ~]# fdisk -l
GPT PMBR size mismatch (20971519 != 67108863) will be corrected by write.
The backup GPT table is not on the end of the device. This problem will be corrected by write.

パーティションの修正

まずはfdiskで問題が出ていたので、parted -lで修正してみます

[root@ip-10-0-2-177 ~]# parted -l
Warning: Not all of the space available to /dev/nvme0n1 appears to be used, you
can fix the GPT to use all of the space (an extra 46137344 blocks) or continue
with the current setting?
Fix/Ignore?

Fix/Ignoreと聞かれるのでFixと入力します

Fix/Ignore? Fix
Model: NVMe Device (nvme)
Disk /dev/nvme0n1: 34.4GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name                  Flags
 1      1049kB  630MB   629MB   fat32        EFI System Partition  boot, esp
 2      630MB   8966MB  8336MB  xfs
 3      8966MB  8967MB  1049kB                                     bios_grub

再度fdiskで確認

[root@ip-10-0-2-177 ~]# fdisk -l
Disk /dev/nvme0n1: 32 GiB, 34359738368 bytes, 67108864 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
Disklabel type: gpt
Disk identifier: E97B9FFA-2C13-474E-A0E4-ABF1572CD20C

Device            Start      End  Sectors  Size Type
/dev/nvme0n1p1     2048  1230847  1228800  600M EFI System
/dev/nvme0n1p2  1230848 17512447 16281600  7.8G Linux filesystem
/dev/nvme0n1p3 17512448 17514495     2048    1M BIOS boot

エラーは消えてパーティション情報だけが表示されるようになりました
/dev/nvme0n1p3が末尾にあるせいで拡張ができなさそうな感じがしています

不要パーティションの削除

続いて本題の/領域を拡張していきます

先ほど書いた通り、/dev/nvme0n1p3が邪魔そうなので削除します
fdiskを実行し、dコマンドで削除していきます

[root@ip-10-0-2-177 ~]# fdisk /dev/nvme0n1

Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help):

ここでdを入力します

Command (m for help): d
Partition number (1-3, default 3):

Partition numberは削除したいパーティションの番号を入力します
今回は3を入力します

Partition number (1-3, default 3): 3

Partition 3 has been deleted.

最後にwコマンドを入力してfdiskを終了します

Command (m for help): w
The partition table has been altered.
Syncing disks.

邪魔なパーティションが消えたので拡張していきます

/領域の拡張

まずはgrowpartコマンドを使用してパーティションを拡張します

[root@ip-10-0-2-177 ~]# growpart /dev/nvme0n1 2

下記のようにCHANGED.....と表示されれば大丈夫です

CHANGED: partition=2 start=1230848 old: size=16281600 end=17512448 new: size=65877983,end=67108831

xfs_growfsコマンドで/領域を拡張します

[root@ip-10-0-2-177 ~]# xfs_growfs -d /
meta-data=/dev/nvme0n1p2         isize=512    agcount=4, agsize=508800 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=2035200, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           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 2035200 to 8234747

dfコマンドで確認し、拡張されていれば完了です

[root@ip-10-0-2-177 ~]# df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
devtmpfs       devtmpfs  3.7G     0  3.7G   0% /dev
tmpfs          tmpfs     3.7G     0  3.7G   0% /dev/shm
tmpfs          tmpfs     3.7G   22M  3.7G   1% /run
tmpfs          tmpfs     3.7G     0  3.7G   0% /sys/fs/cgroup
/dev/nvme0n1p2 xfs        32G  1.5G   30G   5% /
/dev/nvme0n1p1 vfat      599M  6.4M  593M   2% /boot/efi
tmpfs          tmpfs     754M     0  754M   0% /run/user/1000

まとめ

正しいやり方かはわかりませんが、無事ディスク拡張をすることができました。
最初この状態だったときはインスタンス作成でミスったかと思いました...

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1