Okay. Let's talk about swap partitions. Swap is RAM that is emulated on disk. I already
explained that that is beneficial for Linux because Linux can move inactive application
memory to swap. If it's not used, why should it be in RAM? So all Linux systems should
have at least some swap, unless there is a very specific statement that an application
doesn't support swap. Some applications don't. So if there is a memory shortage, unused application
memory can be moved to swap. And that frees up memory that you can use for other purposes.
The amount of swap depends on the use of the server. I can't say anything specific about
it. Well, the only thing that I can say is that nowadays, now servers have a large amount
of memory. It's pretty common to have 25% of the amount of RAM available as swap. Swap
can be created on any block device, and you could even use swap files. In order to configure
a partition as swap, you set the partition type to Linux swap. And after creating the
swap partition, you use mkswap to create swap file system. And next, you activate it using
swap on. Let me show you. So I'm going to start back at good old FDisk, using FDisk
on NVMe 0 and 1. Is that so? Well, with these always changing device names, let me use LSBLK.
Better be safe than sorry. So yeah, I'm going to use device number 1. So FDisk on dev NVMe
0 and 1. It really doesn't matter what I'm using, because both of these disks have available
disk space. I'm ignoring the message in red, because I know what I'm doing. I'm using N
to create partition number 5. First sector, just pressing Enter. Last sector, let's use
plus 1G for one gigabyte of swap. Now, as I'm going to use this as swap, I need to set
the partition type. If we use P, we can see that the partition type right now is set as
Linux file system. I don't like that, so I'm using T to change the partition type for
partition number 5. And the partition type, I'm going to set it to swap. Feel free to
use L to get a list of all the partition types. Too much information. This alias makes it
easy to set it to swap. P again is showing that it is Linux swap, so I'm happy, and I'm
using W to write. Next, it's really like creating a real partition. After creating the
partition, you need MKFS. And this time, instead of MKFS, we need MKSwap. So I'm using
MKSwap on dev NVMe 0 and 1 P5, and that would do it. And there we can see the UUID again.
Well, if you are going to make it final in ETCFS step, please use the UUID. But before
doing so, I want to verify 3-M. Currently, you have 2 gigs of swap. And now if I use swap
on minus A and 3-M again, I still have 2 gigs of swap. Oh, no. Why is that? Well, swap on
minus A requires an entry in ETCFS step. And you know what? Let's immediately do that
because without the entry in ETCFS step, it won't be activated automatically. So this
time, I'm using my mouse to copy the UUID. Oh, no. Didn't I copy it? Well, then BLKID
print $2 greater than greater than ETCFS step. Might as well use that. This is so
convenient that you better practice it a couple of times so that you are used to it when you
do the exam. So here we can see the UUID equals. And how are we going to mount it?
Well, the good thing is for mounting swap, there's an example. Look, two lines above.
So you are mounting this device on none. That sounds weird, but that is because it's not
really a file system or whatever. So you mount it on none. You specify the file system type
swap. Then the file system mount options defaults and 0 and 0. And that should be doing it.
And next, swap on minus A. And next, 3 minus M is showing that right now we have 3 gigs of swap.
And that's how you add a BLK device as swap space.