Galaxy Kirin server operating system V10SP2 creates or expands Swap partition space

Introduction to Swap partition

It is the swap partition (called virtual memory in Windows system). It is a special hard disk space. When the actual physical memory is not enough, the operating system will take out some temporarily unused data from the physical memory and put it in the swap partition. in to free up enough physical memory space for the currently running program. In short, when the physical memory is not enough, the swap partition is used to temporarily replace it. By using swap partitions, under the scheduling of the operating system, the actual memory space that the application can use will far exceed the physical memory space of the system. What should we do if we forget to allocate the swap partition when installing the operating system or the operating system that is already running needs to expand the swap partition?

Swap partition expansion

Check the current swap partition size

[root@localhost ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:          2.8Gi       604Mi       1.6Gi        11Mi       625Mi       2.0Gi
Swap:            0B          0B          0B

Create a new disk partition as swap space

Note: Since the disk in this experimental environment is a logical volume, the disk creation in the following steps is performed using LVM commands. If the actual environment is a bare hard disk, you can use the fdisk command or the parted command to partition the disk.

  1. Create a new 4GB swap partition;
[root@localhost ~]# lvcreate -L 4GB -n swap klas
  Logical volume "swap" created.
  1. Format as swap partition;
[root@localhost ~]# mkswap /dev/mapper/klas-swap
正在设置交换空间版本 1,大小 = 4 GiB (4294963200  个字节)
无标签,UUID=c219433d-b5ee-454f-af79-0fb373caf5a4
  1. Activate the swap partition and confirm;
[root@localhost ~]# swapon /dev/mapper/klas-swap
[root@localhost ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:          2.8Gi       626Mi       1.6Gi        11Mi       629Mi       1.9Gi
Swap:         4.0Gi          0B       4.0Gi
  1. Configure the swap partition to be automatically mounted at boot and restart the system for verification;
[root@localhost ~]# echo "/dev/mapper/klas-swap swap swap defaults 0 0" >> /etc/fstab
[root@localhost ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Wed Dec  7 11:00:38 2022
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/klas-root   /                       xfs     defaults        0 0
/dev/mapper/klas-backup /backup                 xfs     noauto        0 0
UUID=84f8e782-e1b6-4462-9f86-d08bd019219e /boot                   xfs     defaults        0 0
/dev/mapper/klas-swap swap swap defaults 0 0

Create a new file to expand the swap space

Note: Of course, you can also expand the swap partition according to the above steps of creating a new disk partition or extending a logical volume.

  1. Create a new 2GB file as the swap partition;
[root@localhost ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:          2.8Gi       589Mi       1.6Gi        11Mi       617Mi       2.0Gi
Swap:         4.0Gi          0B       4.0Gi
[root@localhost ~]# dd if=/dev/zero of=/swapfile1 bs=1M count=2048
记录了2048+0 的读入
记录了2048+0 的写出
2147483648字节(2.1 GB,2.0 GiB)已复制,6.23587 s,344 MB/s
  1. Format swap partition file;
[root@localhost ~]# mkswap /swapfile1
mkswap: /swapfile1:不安全的权限 0644,建议使用 0600。
正在设置交换空间版本 1,大小 = 2 GiB (2147479552  个字节)
无标签,UUID=0e48ab71-6391-43a6-8b00-65fdc898834e
[root@localhost ~]# chmod 600 /swapfile1
  1. Activate swap partition file;
[root@localhost ~]# swapon /swapfile1
[root@localhost ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:          2.8Gi       586Mi        69Mi        11Mi       2.2Gi       2.0Gi
Swap:         6.0Gi       0.0Ki       6.0Gi
  1. Configure to automatically activate the swap partition file at boot and restart the system for verification;
[root@localhost ~]# echo "/swapfile1 swap swap defaults 0 0" >> /etc/fstab
[root@localhost ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Wed Dec  7 11:00:38 2022
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/klas-root   /                       xfs     defaults        0 0
/dev/mapper/klas-backup /backup                 xfs     noauto        0 0
UUID=84f8e782-e1b6-4462-9f86-d08bd019219e /boot                   xfs     defaults        0 0
/dev/mapper/klas-swap swap swap defaults 0 0
/swapfile1 swap swap defaults 0 0

Related command analysis

The swapon command is used to activate the swap space in the Linux system. The memory management of the Linux system must use the swap area to create virtual memory.

  1. Syntax
    swapon (options) (parameters)
  2. Option
    -a: Start all devices set as swap in the /etc/fstab file as swap areas;
    -h: Display help;
    -p <priority>: Specify the priority of the swap area;
    -s: Display the swap area Usage status;
    -V: Display version information.
  3. Parameters
    Swap space: Specify the swap space that needs to be activated, which can be a swap file or a swap partition. If it is a swap partition, specify the device file corresponding to the swap partition.
  4. Example
swapon  /dev/sda1          激活swap分区/dev/sda1
swapoff  /dev/sda1         取消激活swap分区/dev/sda1
swapon -a                  激活/etc/fstab文件中所有设置为swap的分区或文件

Guess you like

Origin blog.csdn.net/ShenSeKyun/article/details/128230668
Recommended