Linux swap area (swap) is established

  

1. dd instruction


Use dd this command to add a 128MB file under /tmp:

[root@www ~]# dd if=/dev/zero of=/tmp/swap bs=1M count=128

128+0 records in

128+0 records out

134217728 bytes (134 MB) copied, 1.7066 seconds, 78.6 MB/s

View

[root@www ~]# ls -l /tmp/swap

-rw-r--r-- 1 root root 128M Oct 28 15:33 /tmp/swap


This 128MB file is built.


2. mkswap directive


Use mkswap to format the /tmp/swap file into a swap file format:

[root@www ~]# mkswap /tmp/swap

Setting up swapspace version 1, size = 134213 kB

# Please be careful when this command is issued, because the wrong character Control, it will probably hang your file system!


3. swapon instructions


Use swapon to start /tmp/swap.

View existing swap size

[root@www ~]# free

total used free shared buffers cached

Mem: 742664 450860 291804 0 45584 261284

-/+ buffers/cache: 143992 598672

Swap: 1277088 96 1276992


[root@www ~]# swapon /tmp/Swap

View the current swap size

[root@www ~]# free

total used free shared buffers cached

Mem: 742664 450860 291804 0 45604 261284

-/+ buffers/cache: 143972 598692

Swap: 1408152 96 1408056


[root@www ~]# swapon -s< Br>

Filename Type Size Used Priority

/dev/hdc5 partition 1020088 96 -1

/tmp/swap file 131064 0 -3


< H2>4. swapoff instruction

Use swapoff to turn off swap file


[root@www ~]# swapoff /tmp/swap

[root @www ~]# free

total used free shared buffers cached

Mem: 742664 450860 291804 0 45660 261284

-/+ buffers/cache: 143916 598748

Swap: 1020088 96 1019992 <==Revert to the original look!



We need to mount swap in /etc/fstab.

Use the command: sudo gedit /etc/fatab to open the fatab file and add it:

# <file system> <mount point> <type> <options> < ;dump> <pass>


proc /proc proc defaults 0 0


/tmp/swap none swap defaults 0 0

source /etc/fstab will take effect immediately, and it will be guaranteed to take effect the next time you reboot. It's that simple.

Copyright © Windows knowledge All Rights Reserved