Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the step of adding swap partition to Linux system

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article shows you the steps of adding swap partition to the Linux system. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

We can configure the swap partition when we install the Linux system, but after the system installation, we need to add the swap partition because the swap partition is too small. The problem is how to add the swap partition?

First, create a new disk partition as swap partition 1. Enter the console (login system) as root and enter # swapoff-a # to stop all swap partitions

\ 2. Partition the disk with the fdisk command (for example: # fdisk / dev/sdb), add the swap partition, create a new partition, change the newly added partition id to 82 (Linux swap type) with the "t" command in fdisk, and finally write the operation to the hard disk with w (the operation before w is invalid).

\ 3. # mkswap / dev/sdb2 # formats the swap partition. The sdb2 here depends on the actual partition device name displayed by the p command after you add it.

\ 4. # swapon / dev/sdb2 # start a new swap partition

\ 5. To enable this swap partition automatically when the system boots, edit / etc/fstab and add the following line / dev/sdb2 swap swap defaults 0 0

2. Use files as Swap partitions

1. Create a file to be a swap partition: increase the 1GB size of the swap partition, and the command is written as follows, where the count is equal to the number of blocks you want (bs*count= file size). # dd if=/dev/zero of=/root/swapfile bs=1M count=1024

two。 Formatted to swap partition file: # mkswap / root/swapfile # build the file system of swap

3. Enable swap partition files: # swapon / root/swapfile # enable swap files

4. To enable the system to boot itself, add a line to the file / etc/fstab: / root/swapfile swap swap defaults 0 0

3. Expand the LV corresponding to swap to modify the size of swap switching partition

[root@xzzfgsptap01] # df-Th Filesystem Type Size Used Avail Use% Mounted on / dev/mapper/vg_oraclelinx6-LogVol01 ext4 38G 4.0G 32G 12% / tmpfs tmpfs 7.6G 07.6G 0% / dev/shm / dev/sda1 ext4 488M 83M 370M 19% / boot / dev/mapper/vg_oraclelinx6-weblogic_lv Ext4 50G 3.3G 44G 7% / weblogicswap space

[root@xzzfgsptap01 ~] # vi / etc/fstab # # / etc/fstab # Created by anaconda on Thu Oct 25 12:58:25 2018 # # 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 # / dev/mapper/vg_oraclelinx6-LogVol01 / ext4 defaults 1 1 UUID=37c8b0b0-f0d9-4ef8-8fa7-3596783ab7f8 / boot ext4 defaults 1 2 / dev/mapper/vg_oraclelinx6-LogVol00 swap swap defaults 00 tmpfs / dev/shm Tmpfs defaults 0 0 devpts / dev/pts devpts gid=5 Mode=620 0 0 sysfs / sys sysfs defaults 0 0 proc/ proc proc defaults 0 0 / dev/mapper/vg_oraclelinx6-weblogic_lv / weblogic ext4 defaults 0 0cat / proc/swaps

Filename Type Size Used Priority

/ dev/mapper/VolGroup00-LogVol01 partition 1048568 0-1

Lvextend-L + 16G / dev/mapper/vg_oraclelinx6-LogVol00 swapoff / dev/mapper/vg_oraclelinx6-LogVol00 [root@xzzfgsptap01 ~] # resize2fs / dev/mapper/vg_oraclelinx6-LogVol00 resize2fs 1.43-WIP (20-Jun-2013) resize2fs: Bad magic number in super-block while trying to open / dev/mapper/vg_oraclelinx6-LogVol00 Couldn't find valid filesystem superblock. The result of the above execution reported an error because the swap partition does not contain a valid file system, cannot be synchronized, and needs to be rebuilt. [root@xzzfgsptap01] # mkswap-f / dev/mapper/vg_oraclelinx6-LogVol00 Setting up swapspace version 1, size = 17825788 KiB no label, UUID=2ccb4646-20f2-45c1-ac1a-3f00779c6e54 or

/ dev/mapper/vg_oraclelinx6-LogVol00: Device or resource busy needs

Swapoff-f / dev/mapper/vg_oraclelinx6-LogVol00 and then

Mkswap-f / dev/mapper/vg_oraclelinx6-LogVol00swapon-f / dev/mapper/vg_oraclelinx6-LogVol00 [root@centos01 ~] # swapon-a

Finally, you can see that the swap space is 16G.

[root@xzzfgsptap01] # free-g total used free shared buffers cached Mem: 15 014 000-/ + buffers/cache: 0 15 Swap: 16 0 16-

Promotion can also increase and decrease the corresponding LV.

Lvreduce / dev/VolGroup00/LogVol01-L-512m

Lvextend / dev/VolGroup00/LogVol00-L + 512m

What are the steps to add swap partitions to the Linux system? have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report