Swap space is used by the system to store memory pages or blocks that are used less frequently to free up space in the physical RAM. In this hands-on lab, you will be tasked with creating and enabling a swap partition and a swap file and ensuring that they persist through a reboot.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Create and enable a swap partition using /dev/xvdg1.
- Use the
mkswap
command to create swap space on/dev/xvdg1
:
mkswap /dev/xvdg1
- Use the
swapon
command to enable the swap partition:
swapon /dev/xvdg1
- Use the
- Add an entry to /etc/fstab to ensure that the swap partition persists though a reboot (use the UUID).
Obtain the UUID for the partition using the
blkid
command:- Use the editor of your choosing (i.e.,
vim
,nano
, etc.) to add an entry to/etc/fstab
for the swap partition:
vim /etc/fstab
- At the bottom of the file add the following entry:
UUID=partition_UUID swap swap sw 0 0
- Use the editor of your choosing (i.e.,
- Create and enable a 1 GB swap file in the root directory called “extraswap”.
- Use the
dd
command to create a 1 GB file called extraswap:
dd if=/dev/zero of=/extraswap bs=1M count=1024
- Update the permissions on the swap file to be read right only for the root user:
chmod 600 /extraswap
- Use the
mkswap
command to turn extraswap into a swap file:
mkswap /extraswap
- Use the
swapon
command to enable the swap file:
swapon /extraswap
- Use the
- Add an entry to /etc/fstab to ensure that the swap file persists through a reboot (use the full path to the file name).
- Use the editor of your choosing (i.e., vim, nano, etc) to add an entry to
/etc/fstab
for the swap file:
vim /etc/fstab
- At the bottom of the file add the following entry:
/extraswap swap swap sw 0 0
- Use the editor of your choosing (i.e., vim, nano, etc) to add an entry to