How to Create a SWAP partition file in Ubuntu14.04

Source: Internet
Author: User
We have described in detail the Swap partition in Linux (see the http://www.linuxidc.com/Linux/2014-05/102272.htm), in fact, in the server memory is insufficient and affect the server response capabilities and even cause application errors, adding a Swap partition for Ubuntu14.04 is undoubtedly a compromise solution. In Linux, A Swap area can be selected on the disk to replace the memory.

We have described in detail the Swap partition in Linux (see the http://www.linuxidc.com/Linux/2014-05/102272.htm), in fact, in the server memory is insufficient and affect the server response capabilities and even cause application errors, adding a Swap partition for Ubuntu 14.04 is undoubtedly a compromise solution.

In Linux, A Swap area can be selected on the disk to replace the memory usage. Although Swap is much slower than the physical memory, when the physical memory is too small or insufficient, it is also a good temporary alternative. Of course, SWAP is also a good choice for small memory VPS. In this article, we will introduce how to divide Swap partitions on Ubuntu 14.04.

How to manage Swap partition http://www.linuxidc.com/Linux/2012-12/75837.htm in Linux

How to extend/delete a SWAP partition http://www.linuxidc.com/Linux/2014-03/98311.htm

How to Prevent Oracle from using Linux's SWAP partition http://www.linuxidc.com/Linux/2013-08/88456.htm

Two solutions to SWAP insufficiency when installing Oracle in Linux http://www.linuxidc.com/Linux/2013-12/93746.htm

Linux SWAP partition configuration description http://www.linuxidc.com/Linux/2013-03/82008.htm

Ubuntu 12.04 SWAP settings http://www.linuxidc.com/Linux/2013-03/80208.htm

View Swap information of the current system

Before creating a Swap partition in Ubuntu 14.04, we need to first check whether the current operating system has an available Swap partition. By default, Ubuntu will remind you to divide the Swap partition when installing the system. Generally, it will not be changed after the partition is completed.

You can use the following command to view the details:

Sudo swapon-s

Of course, we can also use the most common free command to check whether Swap partitions exist in the current system:

Free-m

View the free space of the disk partition

The best way to divide the swap file is to put it into a separate partition. Of course, if you cannot separate it, you can also create a new swap file in an existing partition.

However, before creating a new Swap partition or creating a Swap file, we need to use the following command to understand the usage of the current system's disk space:

Df-h

After you have determined the free space of the disk, you can determine how to divide and create Swap partitions based on your actual situation.

Generally, the size of the created Swap partition is the physical memory size used by the current system or a multiple of the memory size.

Create a Swap partition File

To create a Swap partition in Ubuntu 14.04, you can use either of the following methods:

1. Traditional Creation Method

In general, we will use the dd command to create a swap partition file in advance, and then use/dev/zero to set all contents of the file to zero, the bs parameter is also used to set the size of the swap space to be created, and count is used to specify the number of blocks to be created.

For example, to create a 4G swap partition file, run the following command:

Sudo dd if =/dev/zero of =/swapfile bs = 1G count = 4

1. Quick Creation Method

You may have noticed that the process of creating Swap files is slow in the preceding method. If you want to quickly create Swap partitions, you can use the fallocate program. This command will immediately create a pre-allocated swap file, and write the allocated size according to the actual size.

If you want to create a 4G swap file, run the following command to create a shortcut:

Sudo fallocate-l 4G/swapfile

Enable Swap partition File

Our swapfile Swap file has been created, but Ubuntu 14.04 does not know that it is used as a Swap partition, so we also need to format this file as a Swap partition to enable it.

First, we need to use the following command to change the permissions of the swapfile file to avoid unintentional Rationality:

Sudo chmod 600/swapfile

Then, we need to use the following code to initialize swapfile as a swap file:

Sudo mkswap/swapfile

Finally, run the following command to enable file swap:

Sudo swapon/swapfile

Mount the Swap partition file when the configuration is enabled

Although Swap files have been configured and enabled, Ubuntu 14.04 will not mount the Swap partition file we just created after restart, therefore, we also need to change the/etc/fstab file so that it will automatically mount the/swapfile file we created when the system starts.

Use vi or nano to add the following content at the bottom of the/etc/fstab file:

/Swapfile none swap sw 0 0

Ubuntu 14.04Download, install, configure related knowledge http://www.linuxidc.com/Linux/2014-04/100370.htm

Ubuntu 14.04: Http://www.linuxidc.com/Linux/2014-04/100352.htm

Ubuntu 14.04 text tutorial on hard drive installation in Windows 7Http://www.linuxidc.com/Linux/2014-04/100369.htm

For more information about Ubuntu, see Ubuntu special page http://www.linuxidc.com/topicnews.aspx? Tid = 2

This article permanently updates the link address: Http://www.linuxidc.com/Linux/2014-08/105223.htm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.