---
title: "How to add a swap drive to your system"
date: "2019-10-02T08:04:57Z"
lastmod: "2019-10-02T08:04:57Z"
authors:
  - "utzer"
tags:
  - "Arch"
  - "linux"
  - "Swap"
  - "system"
categories:
  - "Linux"
  - "qemu"
canonical_url: "https://newblog.utzer.de/2019/10/02/how-to-add-a-swap-drive-to-your-system/"
---

How to add a swap drive to your system, in this case I did this for a virtual machine (qemu) running [Arch Linux](https://wiki.archlinux.org/index.php/Swap).

See at the bottom for information about the virtual drive for qemu.

List current available to system disks:

```
sudo blkid
```

List all disks:

```
sudo lsblk
```

Format as swap:

```
sudo mkswap /dev/vdb
```

gives back the UUID

Now the new swap disk will be shown when executing this again:

```
sudo blkid
```

(also give the UUID)

Take the UUID from above and add an entry in /etc/fstab like this:

```
echo "UUID=56445300-90f5-40b4-860b-99037d0e8aad none swap sw 0 0" |sudo tee -a /etc/fstab
```

Actiate available swap disks, ie. from fstab or on GPT volume.

```
sudo swapon -a
```

Check the swap is available now:

```
sudo swapon --show
```

The qemu image I created as "raw", VirtIO and set the cache mode to "writeback", this should be fine for swap while being fast too. See explanation [here](https://pve.proxmox.com/wiki/Performance_Tweaks) and [here](https://pve.proxmox.com/wiki/Performance_Tweaks#Use_raw_disk_image_and_not_qcow2).

I also looked at [this](https://raymii.org/s/tutorials/KVM_add_disk_image_or_swap_image_to_virtual_machine_with_virsh.html) information about how to add a swap disk.

As always, give me your feedback, I will add information that can help in the future.

