Home >System Tutorial >LINUX >Steps and methods to add swap partition - Linux System Guide

Steps and methods to add swap partition - Linux System Guide

WBOY
WBOYforward
2024-01-03 19:10:40876browse

If you want to add a swap partition in the Linux system, how to add it? Let’s take a look at the detailed tutorial below.

1. First, click "Launcher" on the dock bar, find " Deepin Terminal" and run it.

Steps and methods to add swap partition - Linux System Guide

2. Then set a password for the root user. Because the installation process is for the administrator user, the root password is not set.

sudo passwd root

Steps and methods to add swap partition - Linux System Guide

3. After the setting is completed, execute the su command to switch to the root user

Steps and methods to add swap partition - Linux System Guide

4. Execute the following command to generate a swap file in the root directory. Count sets the number of blocks, bs sets the block size, and generates a 4G swap.

dd if=/dev/zero of=/swapfile count=4096 bs=1024k

Steps and methods to add swap partition - Linux System Guide

5. Next, you need to set it as a swap partition (the path is consistent with the path above).

mkswap /swapfile

Steps and methods to add swap partition - Linux System Guide

6. Mount the swap partition (the path is the same as the path above).

swapon /swapfile

Steps and methods to add swap partition - Linux System Guide

7. At this time, you can see the corresponding swap partition information by executing the top command.

Steps and methods to add swap partition - Linux System Guide

2. Automatically mount swap when booting up

1. Next, to implement automatic mounting at boot, use vim to open the fstab file :

vim /etc/fstab

Steps and methods to add swap partition - Linux System Guide

2. Press the G key, switch to the end of the file, and append the following content

/swapfile     swap     swap  defaults 0 0

Steps and methods to add swap partition - Linux System Guide

3. The wq command saves and exits vim.

Steps and methods to add swap partition - Linux System Guide

4. Restart your computer and you will see the effect.

Steps and methods to add swap partition - Linux System Guide

Precautions:

If you do not allocate swap partition, it is easy to get stuck

related suggestion:

How to add shortcut key startup function to QQ in Linux?

How to resize the dock icon in Linux system?

How to set the font color in text mode in Linux?

The above is the detailed content of Steps and methods to add swap partition - Linux System Guide. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:jb51.net. If there is any infringement, please contact admin@php.cn delete