fbpx Linux mkswap: Create and Activate Swap Memory | Certificação Linux

Linux mkswap: Creating Swap Partition and File for Virtual Memory

📅 12/09/2021 ⏱ 1 min ✍️ Uira Ribeiro
Linuxcommands
Linux mkswap: Creating Swap Partition and File for Virtual Memory
Exam Pass App — mais de 7.000 questões LPI, offline, em 5 idiomas, disponível no Android e na App Store
Available on
Google Play
Available on
App Store

The mkswap command on Linux prepares the device to be used as swap space.

The device argument will generally be a disk partition (something like /dev/sdb7), but it can also be a file.

It's not strictly necessary for the partition to be of type Swap - Type 82 in fdisk - but it's good practice for the partition to be type 82.

After creating the swap space with the mkswap command, you need to enable it with the "swapon" command and add it to /etc/fstab so the partition is used as swap after system reboot.

Usage example:

# mkswap /dev/sdb1mkswap: /dev/sdb1: warning: wiping old swap signature.Setting up swapspace version 1, size = 2097148 KiBno label, UUID=a873901e-5b33-4c78-84f5-e9eeadd9fba3

After it's created, the swap partition can be enabled:

# swaponNAME      TYPE      SIZE USED PRIO/dev/dm-1 partition   2G 256K   -1

Learn much more about Linux in our online course. You can enroll here. If you already have an account, or want to create one, just log in or create your user here.

Did you like it? Share

Uira Ribeiro

Prof. Uirá Ribeiro

Chair do Board do Linux Professional Institute

After years of watching professionals waste hours on simple tasks because they didn't know the right Linux tools, I decided to teach.
Today I'm the author of most of LPI's official Learning Materials and mentor to over 14,000 certified students.

See my full story →

That was just one piece. The course teaches the whole path — from your first command to exam day.

Certificação Linux — a plataforma líder em certificações Linux no Brasil
WhatsApp