Linux mkswap: Creating Swap Partition and File for Virtual Memory
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
That was just one piece. The course teaches the whole path — from your first command to exam day.