# How to Create Swap File Using Virtualmin Interface

**URL:** <https://forum.virtualmin.com/t/how-to-create-swap-file-using-virtualmin-interface/106073>\
**Category:** Virtualmin\
**Created:** [June 10, 2020, 3:28am UTC](https://forum.virtualmin.com/t/how-to-create-swap-file-using-virtualmin-interface/106073 "2020-06-10T03:28:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![adamjedgar](https://cdn.forum.virtualmin.com/letter_avatar_proxy/v4/letter/a/57b2e6/32.png) [@adamjedgar](https://forum.virtualmin.com/u/adamjedgar)\
**Post date:** [June 10, 2020, 3:28am UTC](https://forum.virtualmin.com/t/how-to-create-swap-file-using-virtualmin-interface/106073/1 "2020-06-10T03:28:00Z")

</div>

Hi guys,  
using the Virtualmin interface, how can we create a swapfile and size it to say 2GB?

i can create the file in Virtualmin File Manager, however, i dont know how we size it?

Also, are the any other things that have to be done to a swap file?

---

<div class="post-metadata">

**Author:** ![Joe](https://cdn.forum.virtualmin.com/user_avatar/forum.virtualmin.com/joe/32/9_2.png) [@Joe](https://forum.virtualmin.com/u/Joe)\
**Post date:** [June 10, 2020, 3:51am UTC](https://forum.virtualmin.com/t/how-to-create-swap-file-using-virtualmin-interface/106073/2 "2020-06-10T03:51:26Z")

</div>

I don’t know how you’d do it in the GUI.

Here’s the basic steps (note below I’m using `/swapfile` as the swap name…which is the same name the Virtualmin install.sh uses if you created swap at install time; you probably want to delete it and create bigger one instead of adding another…see below for how):

Make an empty file of e.g. 2GB (must be root or use sudo):

```bash
# dd if=/dev/zero of=/swapfile bs=1024 count=2097152

```

Set it to only be readable by root (because memory can contain anything, including sensitive data):

```bash
# chmod 600 /swapfile

```

Format it for swap usage:

```bash
# mkswap /swapfile

```

Enable it in `/etc/fstab` (skip this if you already had swap on /swapfile):

```bash
# echo '/swapfile none swap sw 0 0' >> /etc/fstab

```

Turn it on:

```bash
# swapon -a

```

If you already have swap on `/swapfile`, do the following first:

```bash
# swapoff -a
# rm /swapfile

```

And, then do the above steps.

---

<div class="post-metadata">

**Author:** ![adamjedgar](https://cdn.forum.virtualmin.com/letter_avatar_proxy/v4/letter/a/57b2e6/32.png) [@adamjedgar](https://forum.virtualmin.com/u/adamjedgar)\
**Post date:** [June 10, 2020, 3:58am UTC](https://forum.virtualmin.com/t/how-to-create-swap-file-using-virtualmin-interface/106073/3 "2020-06-10T03:58:08Z")

</div>

ok. i missed that part in the other thread about this. i have actually just turned off the swapfile and increased its size, then chmod 600 and then turned it back on again.

---

<div class="post-metadata">

**Author:** ![system](https://cdn.forum.virtualmin.com/uploads/default/original/2X/c/cd96d761e326db4b2bef94886a639109bd7a8e76.svg) [@system](https://forum.virtualmin.com/u/system)\
**Post date:** [July 10, 2020, 3:58am UTC](https://forum.virtualmin.com/t/how-to-create-swap-file-using-virtualmin-interface/106073/4 "2020-07-10T03:58:08Z")

</div>

Closed on July 10, 2020, 3:58am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
