ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Create a Linux Swap File in SaltStack

    IT Discussion
    salt devops sds sdi swap linux centos fedora rhel ubuntu debian suse opensuse iaas cloud computing saltstack
    1
    1
    2.0k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • scottalanmillerS
      scottalanmiller
      last edited by scottalanmiller

      Using Salt Stack, it is quite easy to create a swap file on our Linux systems. We can add this to our SLS files.

      /swapfile:
        cmd.run:
          - name: |
              [ -f /swapfile ] || dd if=/dev/zero of=/swapfile bs=1M count={{ grains["mem_total"] * 2 }}
              chmod 0600 /swapfile
              mkswap /swapfile
              swapon -a
          - unless:
            - file /swapfile 2>&1 | grep -q "Linux/i386 swap"
        mount.swap:
          - persist: true
      

      This is Linux specific and will not work on other operating systems. It's common with modern cloud VMs that no swap space is provided and creating a swap file on top of the normal file system is warranted. This command doesn't just make a swap file but looks up the system of the memory on the system and doubles it before making the swap file. So if you have a 2GB RAM VM, this will create a 4GB swap file. Easy to modify if you want half the swap space as memory, one to one or whatever. And it adds the swapspace to the /etc/fstab file for persistence.

      1 Reply Last reply Reply Quote 1
      • 1 / 1
      • First post
        Last post