• Contact
  • Contact Us
  • Disclamer
  • Home 1
  • Home 2
  • Home 3
  • Privacy Policy
Friday, May 9, 2025
How VPS - How to use/setup VPS
  • Login
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
How VPS - How to use/setup VPS
No Result
View All Result
Home Operating System BSD

Create Swap File on FreeBSD 10

How VPS by How VPS
September 1, 2019
in BSD
0
0
SHARES
49
VIEWS
Share on FacebookShare on Twitter

Contents

  1. Confirm swap status
  2. How much swap is needed?
  3. Creating and using a swap file
  4. Explanation for the curious
  5. Want to contribute?


Out of the box, Vultr FreeBSD servers are not configured to include swap space. If your intention is for a disposable cloud instance, you probably don’t need to worry about this. If you’ve created a “real” server that’s going to stick around a while, read on.

Even the most ridiculously decked-out server requires swap space. That’s just how the OS operates. During those times when your app goes a little nuts and eats more RAM than it should, having swap space will give you a fighting chance to regain control of the machine. Even under normal operation, FreeBSD is proactive about memory management. For example, long-running programs that are sitting idle in memory will be swapped to disk to make room for useful things, like filesystem caches. Running with zero swap is a recipe for unpredictable behavior, and no one running a server wants that!

Confirm swap status

Before we do anything, let’s make sure that we really don’t have any swap.

swapinfo should return nothing. Like so:

vultr [~]# swapinfo
Device          1K-blocks     Used    Avail Capacity
vultr [~]#

If indeed it’s blank, let’s continue and make ourselves a swap file. But first…

How much swap is needed?

The old rules of thumb (1x RAM, 2x RAM, .5x RAM, etc) don’t really apply these days. If your server has 16GB of memory, you most certainly do not need to waste 32GB of your precious disk space on a swap file. That said, if you have crash dumps enabled, depending on how it’s configured, having swap equal to your memory may be required for it to work.

So, how big to make the swap file is really up to you. The good news is, you can always change it later, and with SSD-backed storage, you don’t have to worry too much about where it ends up on your disk. Anyway, let’s move on to…

Creating and using a swap file

We will create a 512 meg swap file located at /usr/swap0. Feel free to change any of that if it doesn’t work for you. For example, if you want 1 gig of swap, change the 512 to 1024, and so on up. If you decide to change the filename, make sure you change both references to it.

Carefully copy the following, execute as root, and you’ll be all set:

dd if=/dev/zero of=/usr/swap0 bs=1m count=512
chmod 0600 /usr/swap0
echo "md99 none swap sw,file=/usr/swap0,late 0 0" >> /etc/fstab
swapon -aL

Confirm that it has worked:

vultr [~]# swapinfo
Device          1K-blocks     Used    Avail Capacity
/dev/md99          524288        0   524288     0%

At this point, you’re all set. Swap is active, and it will continue to work after a reboot.

Explanation for the curious

The dd command creates the actual file. After that, we set appropriate permissions, add a line to /etc/fstab for swap, and then turn it on. The command swapon -aL tells the OS to activate all swap partitions/files in fstab, including those marked as late. Due to the way FreeBSD 10.2 boots, the swap file must be mounted late. When the OS boots normally, your swap will get turned on during the “mounting late filesystems” stage.

Want to contribute?

You could earn up to $300 by adding new articles

Submit your article
Suggest an update
Request an article
Previous Post

How to Install Attendize on FreeBSD 12

Next Post

Nginx Reverse Proxy and Golang Setup on FreeBSD

Next Post

Nginx Reverse Proxy and Golang Setup on FreeBSD

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

No Result
View All Result

Recent Post

Install Imagemagick on CentOS
CentOS

Install Imagemagick on CentOS

by How VPS
June 28, 2023
0

This is how I installed Imagemagick on a vanilla CentOS server Start off by installing the prerequisites yum install php-pear...

Read more
how to Check phpinfo

How to Check phpinfo of Hosting or VPS?

June 28, 2023
Failed to download metadata for repo 'appstream' on Centos 8

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

February 25, 2022
How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”?

November 17, 2020
How to optimize Mysql or MariaDB

How to optimize Mysql or MariaDB

November 3, 2020

Recent News

  • Install Imagemagick on CentOS
  • How to Check phpinfo of Hosting or VPS?
  • How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

Category

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel
  • About
  • Advertise
  • Careers
  • Contact

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Thabet