Swap partition or file used by most modern operating systems, including Linux operating systems. This space on a disk in which the system can write portions of memory. Usually, this is a dedicated partition, but it may also be a swapfile.
Tutorial details | |
---|---|
Difficulty | Easy (rss) |
Root privileges | Yes |
Requirements | Linux |
Time | 2m |
Linux Move swap space from one location to another location
There is no command or an easy method exists that allows you to move swap space from one location to another. You can turn off the current swap space with the swapoff command in the original location. For instance:
# swapoff /dev/device
Examples
I am going move /my-swap-file to /foo-swap-space location as follows:
# swapoff /my-swap-file
Verify it with the following command:
# swapon -s
Next create a new swap space with the mkswap command. In this example I am creating a new swap file called /foo-swap-space with 4GiB size:
# dd if=/dev/zero of=/foo-swap-space count=4 bs=1GiB
Set up permission:
$ sudo chmod -v 0600 /foo-swap-space
$ sudo chown -v root:root /foo-swap-space
$ ls -l /foo-swap-space
Run the following mkswap command to set up Linux swap area using a file:
# mkswap /foo-swap-space
Activating a swap space by typing the swapon command:
# swapon /foo-swap-space
For more info see: How to create a Linux swap file.
Conclusion
You learned how to turn off the existing swap space and move it to the new location under Linux.
- Linux Add a Swap File
- FreeBSD Add a Swap File
- Ubuntu Create and add a swap file
- Check Swap Usage Size and Utilization in Linux
- Linux Find Out What Process Are Using Swap Space
- Move swap space from one location to another location
- Solaris add a new swap file for database
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
- RSS feed or Weekly email newsletter
- Share on Twitter • Facebook • 0 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |