Last active
February 22, 2024 09:23
-
-
Save yukithm/d154b289743c35c64874837661de9cab to your computer and use it in GitHub Desktop.
Make swap by cloud-init
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#cloud-config | |
mounts: | |
- [ "/swapfile", "none", "swap", "defaults", "0", "0" ] | |
runcmd: | |
- [ "dd", "if=/dev/zero", "of=/swapfile", "bs=1G", "count=4" ] | |
- [ "chmod", "600", "/swapfile" ] | |
- [ "mkswap", "/swapfile" ] | |
- [ "swapon", "/swapfile" ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It is better to use the standard function described in "cloud-init:Adjust mount points mounted".
Instead of the "runcmd:" section commands, add:
or
This is enough to automatically create the file, format it, add the appropriate entry to
/etc/fstab
and executeswapon /swapfile
.So the line
- ["/swapfile", "none", "swap", "defaults", "0", "0" ]
in themounts:
section is not needed. It will create an unnecessary mount point.