【Google Compute Engine】dnf使うと殺される件(Killed)

OS=Rocky8 Optimized for GCP

# dnf update
...
Killed

# dmesg
...
[  137.810169] Out of memory: Killed process 1638 (dnf)

e2-microだときびしい

対策1)メモリ増やす

Always Free なのでスペック変更できない。Oracle CloudはRAM1GBでも動いたのに。

対策2)SWAPエリアを作る。

# fallocate -l 1G /swapfile
# mkswap /swapfile
# chmod 0600 /swapfile
# swapon /swapfile

動いた。

# dnf update
...
Total download size: 245 M
Is this ok [y/N]:

リブート後もswapが有効になるには以下を設定

# vi /etc/fstab
/swapfile none                    swap    defaults        0 0

SWAPがあるか確認

# free
              total        used        free      shared  buff/cache   available
Mem:         773308      200076      202456        2764      370776      344372
Swap:       1048572      100360      948212