Linux manually add swap

Source: Internet
Author: User

Linux manually add swap partitions
Usage: dd [operand] ...  Or: DD option copy a file, converting and formatting according to the operands.      Bs=bytes Read and write up to BYTES BYTES at a time cbs=bytes convert BYTES BYTES at a time Conv=convs Convert the file as per the comma separated symbol list count=n copy only N input blocks ibs=bytes read U P to BYTES BYTES at a time (default:512) if=file read from FILE instead of stdin iflag=flags read as per th e Comma separated symbol list obs=bytes write BYTES BYTES at a time (default:512) Of=file write to FILE I  Nstead of stdout Oflag=flags write as per the comma separated symbol list seek=n skip N obs-sized blocks at Start of output skip=n skip N ibs-sized blocks at start of input status=level the level of information to P                  Rint to stderr;                  ' None ' suppresses everything but error messages, ' Noxfer ' suppresses the final transfer statistics, ' Progress 'Shows periodic transfer STATISTICSN and BYTES May is followed by the following multiplicative Suffixes:c =1, w =2, B = 512, KB =1000, K =1024, MB =1000*1000, M =1024*1024, XM =mgb =1000*1000*1000, G =1024*1024*1024, and so on for T, P, E, Z, Y.E  Ach CONV symbol may be:ascii from EBCDIC to ASCII EBCDIC from ASCII to EBCDIC IBM from ASCII to alternate EBCDIC block pad newline-terminated records with spaces to cbs-size unblock replace trailing spaces in cbs-size R Ecords with newline LCase-upper case-to-lower case ucase-lower case-to-upper case sparse try T o Seek rather than write the output for NUL input blocks swab swap every pair of input bytes sync pad every in Put block with nuls to Ibs-size; When used with block or unblock, pad with spaces rather than nuls excl fail if the output file already exists Nocreat does not create the output file Notrunc does not truncate the input files NoError read the data after the error still continues Fdatasync before the end willThe output file data is written to disk Fsync similar to the above, but the metadata is also written together with the flag symbol can be: Append append mode (only meaningful for the output; implied Conv=notrunc) direct uses directly I/O access mode Director Y directory failure Dsync uses synchronous I/O access mode sync is similar to the previous one, except for directories, but also for metadata fullblock to accumulate complete blocks for input (Iflag only) Nonblo  CK uses nonblocking I/O access mode noatime does not update access time NoCache Request to drop cache.   See also Oflag=sync Noctty not based on file assignment control Terminal nofollow does not follow link file count_bytes treat ' count=n ' as a byte count (Iflag only) Skip_bytes treat ' skip=n ' as a byte count (Iflag only) seek_bytes treat ' seek=n ' as a byte count (Oflag-only) sending A USR1 signal to a running ' DD ' process makes Itprint I/O statistics to standard error and then resume copying.  Options is:--HELP displays this help information and exits--version display version information and exits the GNU coreutils Online assistance:<http://www.gnu.org/software/coreutils/>please send<http://translationproject.org/team/zh_cn.html>report DD translation error full documentation at:<http://WWW.GNU.ORG/SOFTWARE/COREUTILS/DD>or available locally via:info ' (coreutils) dd invocation '
DD Help

1. Check the current swap partition status

# free–m

Total used free shared buffers Cached
MEM:1006 84 922 0 11 38
-/+ buffers/cache:35 971
swap:0 0 0

2. Add swap partition file and size

As above, the size of the current swap partition is 0, if you need to increase the size of 1024M.

Determines the size of the new swap file, multiplying the size by the size of the 1024来 decision block. For example, a swap file of size 64MB has a block size of 65536, and at the shell prompt, type the following command as the root user, where count equals the desired block size.

# dd If=/dev/zero Of=/home/swap bs=1m count=1024

1024000+0 Records in
1024000+0 Records out

Format the swap file and format the swap file as an S file system for the system to use

# Mkswap/home/swap
Setting up Swapspace version 1, size = 1023996 KiB

3. Start the Swap partition file

If you want to enable the swap partition file immediately, do the following:

# Swapon/home/swap

To stop using the newly created swap file, simply execute the swapoff/home/swap command.

Check the size of the added swap partition

# free-m

Total used free shared buffers Cached
mem:1006 994 12 0 4 929
-/+ buffers/cache:60 946
swap:999 0 999

4. To automatically enable the newly added swap when the system starts again, edit the/etc/fstab file:

# Vi/etc/fstab, add up like the downside

/home/swap swap swap defaults 0 0

5. Modify the swappiness of the Linux swap space to reduce the cache on the hard disk

Linux uses a portion of the hard disk as a swap partition for process scheduling--the process is a running program--standby the currently unused process to ' wait ', or even ' sleep ', once it is used and then adjusted to ' Active ', the process of sleeping sleeps in the swap zone, emptying the memory out of the ' activity ' process.
If the memory is large enough, you should tell Linux not to use SWAP partitions too much, and you can modify the value of the swappiness. Swappiness=0 means to maximize the use of physical memory, then the swap space, swappiness=100 when the active use of the swap partition, and the memory of the data in a timely manner into the swap space. In Ubuntu, the default setting swappiness this value equals 60.
  
!!!! If the memory is small, and the process is scheduled frequently, the hard disk will be loud!!!!
  
Now generally 1 g of memory can be modified to 10, 2 G can be changed to 5, or even 0. Specifically, do this:


1. Check the swappiness in your system
$ cat/proc/sys/vm/swappiness
No accident, you should see it's 60.


2. Modify the Swappiness value to 10
$ sudo sysctl vm.swappiness=10


But this is only a temporary change, after you restart the system will restore the default of 60, for peace and stability, but also further:
$ sudo vi/etc/sysctl.conf
Add such a line at the end of this document:
vm.swappiness=10
Then save, restart. OK, your settings are in effect.

Linux manually add swap

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.