|
We have previously been described in detail in the Swap Linux swap partition, in fact, the server runs out of memory affect server responsiveness even lead to application errors for Ubuntu 14.04 add a swap Swap is undoubtedly a compromise solution.
Linux can temporarily set aside a Swap area on the disk instead of memory usage, although Swap much slower than physical memory, but it really is too small for physical memory or not enough, it still is a good temporary alternative. Of course, for small memory VPS, SWAP is also a good choice. In this article, we will describe how to divide Swap swap partition on Ubuntu 14.04.
View the current system Swap Information
Before beginning to create a Swap partition in Ubuntu 14.04, we need to first look at the current operating system for available swap partitions. By default, Ubuntu during installation the system will remind the user partition Swap partition, divided after the general good is not likely to change.
We can use the following command to view:
sudo swapon -s
Of course, we can also use the most common free command to see the current system if there Swap Swap:
free -m
See free space on a disk partition
The best way to divide the swap file is to put it into a separate partition which, of course, if you can not alone create a new swap file on an existing partition for dividing words.
But before creating a new Swap swap partition or swap file is created, we need to understand the following command under the current system disk space usage:
df -h
Good disk free space is determined, you can have your own actual situation to decide how to divide and create Swap swap partition.
Under normal circumstances, create a Swap partition sizes are multiples of the physical memory size or memory size of the current system.
Creating Swap partition file
To Ubuntu 14.04 To create Swap partition has the following two ways:
A traditional way to create
Under normal circumstances, we will use the dd command to create a swap file in advance, and then use the / dev content / zero of the file will be used bs all parameters set to zero, created to set the swap space to be created, as well as use count to specify the number of block to be created.
For example, we want to create a swap file 4G can use the following command:
sudo dd if = / dev / zero of = / swapfile bs = 1G count = 4
1 way to quickly create
You may have noticed, the above-described manner to create a swap file Swap process is relatively slow, if you want to quickly create a swap partition can be used fallocate a program. This command creates a pre-allocated swap file immediately, and production is based on the actual size of the write allocation size.
If the same is to create a 4G size swap file is created and quick way to create order is as follows:
sudo fallocate -l 4G / swapfile
Enable Swap partition file
Our swapfile swap file has been created, but Ubuntu 14.04 do not know it is being used as a swap partition, so we also need to format the file to enable it to cross-Swap partition.
First, we need to use the following command to change the permissions under the swapfile file to avoid it being unintentionally Rationality to:
sudo chmod 600 / swapfile
Then, we need to use the following initialization for the swap file swapfile:
sudo mkswap / swapfile
Finally, we need to use the following command to enable the swap file:
sudo swapon / swapfile
Swap partition mount configuration to enable file
Swap swap file although already configured and enabled, but Ubuntu 14.04 after the restart is not mounted swap file we just created, so we also need to / etc / fstab file to make changes that allow the system to start when automatically mount / swapfile file we created.
Use vi or nano in / etc / fstab bottom of the file add the following:
/ Swapfile none swap sw 0 0 |
|
|
|