Configuring Swap Size under Linux

When installing oracle, the swap was too small to continue the installation, so I wanted to find a way to change the size of swap without installing os.

So there are the following:

The following operations require root privileges.
#cd /usr/;mkdir swap
#dd if=/dev/zero of=swapfile bs=1G count=2
This command separates a 2×1G space from the hard disk and hangs it on the swapfile.
#mkswap swapfile
Build the swap format on /usr/swap/swapfile
#swapon swapfile
activate the swapfile and add it to the swap partition.
The above operations will lose the swapfile in the swap space after restarting the system. Adding the swapfile to the /etc/fstab entry will enable the system to call swapon -a in the init process to automatically mount the swapfile, so that the swapfile will be valid every time the machine is restarted. swap space.
Add the following line to the /etc/fstab file:
/usr/swap/swapfile swap swap defaults 0 0
This dd command is very useful, it can be used to split large files into small filegroups, and cat can be used to convert those small files Groups are reassembled into the original large file.

__________________________
The following situations encountered by others:
Speaking of swap~ what is it?
In fact, swap is the swap area of ​​the memory; in other words, if the memory is not enough, the system will store some data that is not commonly used in the memory on the hard disk, and then destruct this part of the data in the storage; in this way, the memory will have The remaining space can run stuff. This process is also called swapping. The part of the hard disk that stores data is the swap partition.
When installing the system, the swap size may be set inappropriately, but the swap size is incorrect, which affects the server. Performance This happened to a colleague
last time . 2G of physical memory was only divided into 100M of swap. . . Tragedy happened, we can
only              solve him Swap: 10 0 100 2. Create a swap file in a suitable space [root@jumper usr]# mkdir swap [root@ema usr]# cd swap [root@ema swap]# dd if=/dev/zero of=swapfile bs =402400 count=10000 10000+0 records in










10000+0 records out
[root@ema swap]# ls -al
total 10024
drwxr-xr-x    2 root     root         4096 
drwxr-xr-x   19 root     root         4096 
-rw-r--r--    1 root     root     4013500000
[root@emaswap]# mkswap swapfile

3.激活swap文件
[root@jumper swap]# swapon swapfile
[root@ema usr]# free -m
             total       used       free     shared    buffers     cached
Mem:          2026       1929         97          0          7       1755
-/+ buffers/cache:        166       1860
Swap:         4008          0       4008


另一个例子
  VPS (Virtual Private Server) technology is a high-quality service that divides a server into multiple virtual private servers. Each VPS can be assigned an independent public IP address, independent operating system, independent large space, independent memory, independent execution program and independent system configuration.


Some notes during the configuration process:

1. The VPS has only one root partition and no swap partition. The VPS does not have much memory, so I added a swap file to it.
1. Enter a directory
cd /var/
2. Obtain 256M file blocks:
dd if=/dev/zero of=swapfile bs=1024 count=262144
3. Create swap file
/sbin/mkswap swapfile
4. Activate swap file
/sbin /swapon swapfile
5. Check whether the swap is correct:
/sbin/swapon -s
6. Add to the fstab file to automatically start
vi when the system boots /etc/fstab
Add the following at the end:
refer to
/var/swapfile swap swap defaults 0 0
or above reference: http://www.newsmth.net/pc/pccon.php?id=10002358&nid=320858  

Second, the system defaults to US Eastern Time, modify the Linux time zone to East Eighth
cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326767221&siteId=291194637
Recommended