{"authors":["utzer"],"canonical_url":"https://newblog.utzer.de/2020/04/20/linux-swap-with-dphys-swapfile/","categories":["Linux"],"content":"This is a solution for a #RaspberryPi, some #VPS without swap of some machine setup without swap where you need swap for something without wanting to fiddle with the drive partitions or so.\n\nThis is a quick and dirty \"short manual\" for #Debian based #Systemd environments (such as #Ubuntu, #Mint or #Raspbian).\n\nFirst run this:\n\n```\ncat \u003e dphys-swap.sh \u003c\u003c EOF\n#!/bin/bash\n#~/up\napt-get install dphys-swapfile\necho \"CONF_SWAPSIZE=2048\"|tee -a /etc/dphys-swapfile\ndphys-swapfile setup\ndphys-swapfile swapon\nsystemctl restart dphys-swapfile.service\nsystemctl status dphys-swapfile.service\nfree -h\nEOF\n```\n\nThis will just create a short #bash #script with the needed commands to run to get #dphys setup and running. Please alter the number 2048 to your need, it is the size of the swap memory that will be setup. The size of the swap should most likely by equal to the real memory installed, sometimes twice the size seems to be a good choice too.\n\nIf you don't know your memory size you can find it out by running the command \"free -h\", which will print the size of the physical memory installed and the below this the swap size(s).\n\nAfter pasting the above code into your shell, which will create a file called \"dphys-swap.sh\" in the current folder (you should be in your home folder!!), you need to make the shell script \"dphys-swap.sh\" executable by running:\n\n```\nchmod +x dphys-swap.sh\n```\n\nThen you need to run the script like this:\n\n```\nsudo ~/dphys-swap.sh\n```\n\nIt will ask for some confirmation(s) to install certain packages.\n\nThe last commands will output the status of the systemd service \"dphys-swapfile.service\" and the last line will show you the memory and swap size again.\n\nRemark:  \nIn the script above I use \"up\", my full update of the system. I just blogged that one too, have a look [here](/2020/04/20/debian-based-full-updates-in-one-command/).\n","content_format":"markdown","date":"2020-04-20T10:29:10Z","description":"This is a solution for a #RaspberryPi, some #VPS without swap of some machine setup without swap where you need swap for something without wanting to fiddle with the drive partitions or so. This is a quick and dirty \"short manual\" for #Debian based #Systemd environments (such as #Ubuntu, #Mint or #R","html_url":"https://newblog.utzer.de/2020/04/20/linux-swap-with-dphys-swapfile/","json_url":"https://newblog.utzer.de/2020/04/20/linux-swap-with-dphys-swapfile/index.json","lastmod":"2020-04-20T10:29:10Z","markdown_url":"https://newblog.utzer.de/2020/04/20/linux-swap-with-dphys-swapfile/index.md","media":[],"schema_version":1,"tags":["bash","debian","dphys","dphys-swap","linux","Mint","RaspberryPi","Raspbian","script","Swap","Systemd","Ubuntu","VPS"],"title":"Linux swap with dphys-swapfile","type":"blog_post"}