Manage Swap

TIPS & TRICKS

To search the contents of the man pages

# man -k searchterm 
# man -K searchterm

Swap partition tasks examples

Don’t forget

# mkswap /dev/sdb1
# swapom /dev/sdb1

And in fstab:

UUID=29ee03a0-196a-42cd-986f-4560097c9764 swap swap defaults 0 0
UUID=fe0b8dff-238d-4748-8e16-c576c4c0b8be swap swap pri=42 0 0

Create a swap partition 1

Create a swap partition of 512MB at /dev/sdb, with a persistent prioity of 20.

# free -m
# fdisk /dev/sdb/       // g, n, +512M, t, swap, w
# partprobe
# lsblk
# mkswap /dev/sdb1 // DONT FORGET !!!
# blkid

Add the priority in fstab instead of default parameter:

# vim /etc/fstab 
UUID=......... swap swap pri=20 0 0

Note:
Priority can be added when swappon command is invoqued, but not persistent:

# swapon -p 20 /dev/sdb1
# swapon -s
# mount -a
# swapon -s
# swapon -a
# free -m
# lsblk

Create a swap partition 2

| Add aditional swap partition of 2GB using /dev/sddX and mount it permanently.

# lsblk [-fp]
# fdisk /dev/sdd

Command (m for help): g

Created a new GPT disklabel (GUID: 2A33A3BA-E580-1B44-A4CD-9EDC587E3FC0).

Command (m for help): n
Partition number (1-128, default 1): 1
First sector (2048-12582878, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-12582878, default 12582878): +2G

Created a new partition 1 of type 'Linux filesystem' and of size 2 GiB.

Command (m for help): t
Selected partition 1
Partition type or alias (type L to list all): swap
Changed type of partition 'Linux filesystem' to 'Linux swap'.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

# partprobe
# mkswap /dev/sdd1 // DONT FORGET !!!
# swapon /dev/sdd1
# swapon -s // check swap summary

To mount swap permanently make entry in fstab:

# vim /etc/fstab
UUID=29ee03a0-196a-42cd-986f-4560097c9764 swap swap defaults 0 0

Documentations

Internet
Git
ChatGPT

> Partager <