問題
- Raspberry Pi5にUbuntu24.04を入れてkubernetesを動作させるため、swapをoffしようとした
-
/etc/fstab
の/swapfile none swap sw 0 0
やUUID=xxx-xxx-xxx-xxx none swap sw 0 0
といった行をコメントアウトすればよいという情報がいくつかあったが、実際に中身を見て見るとそれに類する記述はなかった$ cat /etc/fstab LABEL=writable / ext4 discard 0 1 LABEL=system-boot /boot/firmware vfat defaults 0 1
- 実際に
sudo swap off -a
後に再起動するとswapが有効になっており、どうすればswapを永続的に無効化できるか調べた
解決策
- swapfile.swapを無効化して、停止
$ sudo systemctl disable swapfile.swap $ sudo systemctl stop swapfile.swap
- swapfileを削除
$ sudo rm /swapfile
- swapを無効化
$ sudo swapoff -a
上記の方法で、再起動してもswapが無効化されていることを確認した。
解決までの経緯
-
Ubuntu 24.04をインストール直後にswapが有効であることを確認
$ free -h total used free shared buff/cache available Mem: 7.8Gi 659Mi 6.5Gi 17Mi 767Mi 7.1Gi Swap: 1.0Gi 0B 1.0Gi
-
swapを動かしてそうなサービスを検索
% sudo ls /etc/systemd/system | grep swap swap.target.wants
-
swap.target.wants
のディレクトリを確認$ sudo ls /etc/systemd/system/swap.target.wants growroot-almost.service mkswap.service swapfile.swap
-
growroot-almost.service
、mkswap.service
、swapfile.swap
の状態を確認$ sudo systemctl status growroot-almost.service Warning: The unit file, source configuration file or drop-ins of growroot-almost.service changed on disk. Run 'systemct> ○ growroot-almost.service - Grow the root file-system, leaving 16MB space for LUKS headers Loaded: loaded (/usr/lib/systemd/system/growroot-almost.service; enabled; preset: enabled) Active: inactive (dead) Condition: start condition unmet at Tue 2024-08-27 23:36:50 JST; 1 month 4 days ago Aug 27 23:36:50 master-desktop systemd[1]: growroot-almost.service - Grow the root file-system, leaving 16MB space for >
$ sudo systemctl status mkswap.service Warning: The unit file, source configuration file or drop-ins of mkswap.service changed on disk. Run 'systemctl daemon-> ○ mkswap.service - Create the default swapfile Loaded: loaded (/usr/lib/systemd/system/mkswap.service; enabled; preset: enabled) Active: inactive (dead) Condition: start condition unmet at Tue 2024-08-27 23:36:50 JST; 1 month 4 days ago Aug 27 23:36:50 master-desktop systemd[1]: mkswap.service - Create the default swapfile was skipped because of an unmet>
$ sudo systemctl status swapfile.swap Warning: The unit file, source configuration file or drop-ins of swapfile.swap changed on disk. Run 'systemctl daemon-r> ● swapfile.swap - The default swapfile Loaded: loaded (/usr/lib/systemd/system/swapfile.swap; enabled; preset: enabled) Active: active since Tue 2024-08-27 23:36:50 JST; 1 month 4 days ago What: /swapfile Tasks: 0 (limit: 9068) Memory: 340.0K (peak: 1.5M) CPU: 11ms CGroup: /system.slice/swapfile.swap Aug 27 23:36:50 master-desktop systemd[1]: Activating swap swapfile.swap - The default swapfile... Aug 27 23:36:50 master-desktop systemd[1]: Activated swap swapfile.swap - The default swapfile.
-
swapfile.swap
が、enabled
かつactive
だったので、無効化して停止$ sudo systemctl disable swapfile.swap Removed "/etc/systemd/system/swap.target.wants/swapfile.swap". $ sudo systemctl stop swapfile.swap
-
swapfile.swap
が無効化されたことを確認$ sudo systemctl status swapfile.swap ○ swapfile.swap - The default swapfile Loaded: loaded (/usr/lib/systemd/system/swapfile.swap; disabled; preset: enabled) Active: inactive (dead) since Tue 2024-10-01 23:38:20 JST; 1s ago Duration: 1month 4d 13h 31min 29.715s What: /swapfile CPU: 15ms Aug 27 23:36:50 master-desktop systemd[1]: Activating swap swapfile.swap - The default swapfile... Aug 27 23:36:50 master-desktop systemd[1]: Activated swap swapfile.swap - The default swapfile. Oct 01 23:38:20 master-desktop systemd[1]: Deactivating swap swapfile.swap - The default swapfile... Oct 01 23:38:20 master-desktop systemd[1]: swapfile.swap: Deactivated successfully. Oct 01 23:38:20 master-desktop systemd[1]: Deactivated swap swapfile.swap - The default swapfile.
-
swapfileを削除
$ sudo rm /swapfile
-
swapを無効化
$ sudo swapoff -a
-
再起動
$ sudo reboot
-
起動後、swapが無効化されていることを確認
$ free -h total used free shared buff/cache available Mem: 7.8Gi 678Mi 6.7Gi 17Mi 640Mi 7.1Gi Swap: 0B 0B 0B