How to Create SWAP partition files in Ubuntu 14.04

Source: Internet
Author: User

How to Create SWAP partition files in Ubuntu 14.04

We have described in detail the Swap partition in Linux (see). In fact, when the server memory is insufficient and the server response capability is affected or even the application fails, 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 and configure Swap partitions in Linux

How to expand/delete SWAP partitions

How to Prevent Oracle from using Linux SWAP partitions

Two solutions to SWAP insufficiency when installing Oracle in Linux

Linux SWAP partition Configuration

Ubuntu 12.04 SWAP settings

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

Download, install, and configure Ubuntu 14.04

Ubuntu 14.04 system:

Ubuntu 14.04 text tutorial on hard drive installation in Windows 7

Related Article

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.