Modify Swap partition in linux

Source: Internet
Author: User
After installing the Linux system, modify the Swap partition size (two methods). after installing the Linux system, what should I do if the swap partition is too small? how can I expand the Swap partition? There are two ways to create a new swap partition, one is to add a swap partition. The following two methods are described...

Modify the Swap partition size after installing the Linux system (two methods)

After Linux is installed, what should I do if the swap partition is too small? how can I expand the Swap partition? There are two ways to create a new swap partition, one is to add a swap partition. The following two methods are described:
First, you must have the root permission. in the process, you must be very careful. if you accidentally destroy the data on the entire hard disk, you must think twice before executing the following process, the consequences of incorrect operations shall be borne by the performer.
Create a swap partition

1. enter the console as root and enter
# Swapoff-a # stop swap partition
 
2. run the fdisk command to add the drive letter of the swap partition. (for example, # fdisk/dev/sdb) remove the swap partition and enter d to delete the swap partition, then add n partitions (the hard disk must have available space when adding the partition, and then use t to change the newly added partition id to 82 (linux swap type ), finally, use w to write the operation to the hard disk (the operation before w is useless is invalid ).
 
3. # mkswap/dev/sdb2 # format the swap partition. the sdb2 here depends on the actual partition device name displayed by the p command after you have added it.
 
4. # swapon/dev/sdb2 # start a new swap partition
 
5. to enable swap partition automatically when the system starts, edit/etc/fstab and add the following line.
/Dev/sdb2 swap defaults 0 0
 
6. Complete
Add Swap partition

 
 
1. create a swap partition file: add a 1 GB swap partition, the command is written as follows, where count is equal to the expected block size.
# Dd if =/dev/zero of =/home/swapfile bs = 1 M count = 1024
 
2. set swap partition file:
# Mkswap/home/swapfile # Create a swap file system
 
3. enable swap partition file now:
# Swapon/home/swapfile # enable swap files
 
4. enable auto when the system is started. add a line in the file/etc/fstab:
/Home/swapfile swap defaults 0 0
 
5. Complete
This article is from the "hancj" blog

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.