Introduction to Linux swap partition and experiment scenarios and processes

Source: Internet
Author: User
Tags hex code

Do you want to know the truth about Linux swap partitions? Do you want to know the inherent meanings in Linux swap partitions? I will only give you a full introduction to Linux swap partitions. sometimes it is necessary to add more swap space after the operating system is installed.

For example, the system memory is upgraded from 64 MB to 128 MB, but the original swap space is only 128 MB. If the system executes a large number of memory operations or runs a program that requires a large amount of memory, it is more advantageous to increase the swap space to MB. There are two options for adding a swap space: Add a Linux swap partition or add a swap file. We recommend that you add a Linux swap partition here.

I. Introduction to Linux swap partitions

In Linux, swap partitions are used as cache of physical memory when physical memory RAM is full. When the system requires more memory resources and the physical memory is full, the inactive pages in the memory will be moved to the Linux swap partition. The Linux swap partition is on the hard disk, so its access speed is slower than the physical memory.

In general, the size of the SWAp partition in Linux should be twice the size of the computer's memory, but cannot exceed 2048MB2GB ).

Ii. Experiment scenarios

Resource Configuration: Host: Virtual Server 2K5 R2 memory: 512M Hard Disk: hda 6 Ghdb 1g Operating System: Fedora 2 lab requirement: Create a Linux swap partition on the second hard disk, and add it to the system.

Tutorial steps:
1. Start the file system and delete the current Linux swap partition.
2. Use fdisk to create a Linux swap partition.
3. Use the mkswap command to set Linux swap partitions.
4. Start swapon) Linux swap partition.
5. Edit the/etc/fstab file to enable Linux swap partition during boot.

Iii. Experiment Process

Before the experiment, we should first check the configuration of the system swap space and run the command to check which partition on the hard disk is used as the Linux swap partition. Fdisk-l

The result is as follows:

 
 
  1. [root@zheng root]#fdisk –l   
  2. Disk /dev/had:8589 MB,858990124 bytes  
  3. 16 heads,63 sectors/track,16644 cylinders  
  4. Units = culinders of 1008 * 512 = 516096 bytes   
  5. Device    BootStart  End Blocks     Id    System  
  6. /dev/hda1*1     203  102280+  83    Linux  
  7. /dev/hda2    204  14564     7237944  83    Linux  
  8. /dev/hda3    14565     16644     1048320  82    Linux swap  
  9. [root@zheng root]# 

/Dev/hda3 is the Linux swap partition in use. To add a new Linux swap partition, delete the currently used Linux swap partition and add a new Linux swap partition.

1. Start the file system and delete the current Linux swap partition.

In the Fedora 2 operating system, you can directly use the command to delete Linux swap partitions. With the information we know in advance, we can perform the following operations: run the swapoff command to Uninstall Linux swap partitions. Swapoff/dev/hda3

2. Use the fdisk command to create a Linux swap Partition

Use the fdisk command to create a Linux swap partition that is twice the total physical memory capacity. Use the following command:

 
 
  1. [Root @ zheng root] # fdisk/dev/hdb
  2. Command (m for help): n // create a new partition
  3. Command action
  4. E extend
  5. P primary partition (1-4)
  6. P // The primary partition type.
  7. Partition number (1-4): 1
  8. First cylinder (1-2080, default 1 ):
  9. Using default value 1
  10. Last cylinder or + size or + sizeM or + sizeK (1-2080, default 2080 ):
  11. Using default value 2080
 
 
  1. Command (m for help): t // change the partition format
  2. Selected partition 1
  3. Hex code (type L to list codes): 82 // The hexadecimal code of Linux swap is 82
  4. Command (m for help): p
  5. Disk/dev/hab: 1073 MB, 1073479680 bytes
  6. 16 heads, 63 sectors/track, 2080 cylinders
  7. Units=CulindersOf 1008 *512=516096Bytes
  8. Device BootStart End Blocks Id System
  9. /Dev/hdb1*1 20801048288 + 82 Linux swap
  10. Command (m for help): w // save partition information
  11. Command (m for help): q

By using the fdisk Command, we have created a partition/dev/hdb1 in Linux swap partition format.

3. Use the mkswap command to set Linux swap partitions

Command: [root @ zheng root] # mkswap/dev/hdb1 // format the partition as Linux swap partition format Setting up swapspace version 1, size = 1073442 kB

4. Start swapon) Linux swap Partition

[Root @ zheng root] # swapon/dev/hdb1 // enable Linux swap Partition

5. Edit the/etc/fstab file to enable Linux swap partition during boot.

After editing the fstab file, the content of the Linux swap partition is:/deb/hdb1swapswapdefaults 0 0. In this way, we have created a new Linux swap partition. Restart the system and verify that the Linux swap partition is correctly added.
The following information is displayed when the system restarts:

 
 
  1. Activiting swap partition: [OK] // activate Linux swap partition
  2. Enabling swap space: [OK] // create a swap space

After verification is successful, you can delete the original Linux swap partition/dev/hda3. Finally, the partition information is as follows:

 
 
  1. [root@zheng root]#fdisk –l   
  2. Disk /dev/had:8589 MB,858990124 bytes  
  3. 16 heads,63 sectors/track,16644 cylinders  
  4. Units = culinders of 1008 * 512 = 516096 bytes   
  5. Device    BootStart  End Blocks     Id    System  
  6. /dev/hda1* 1     203  102280+  83    Linux  
  7. /dev/hda2   204145647237944  83    Linux   
  8. Disk /dev/hab:1073 MB,1073479680 bytes  
  9. 16 heads,63 sectors/track,2080 cylinders  
  10. Units = culinders of 1008 * 512 = 516096 bytes  
  11. Device    BootStart  End Blocks     Id    System  
  12. /dev/hdb1*  1     20801048288+82    Linux swap  

This information indicates that the Linux swap partition has been added successfully. Note: The reference documents do not require that you use the rescue mode to start in the Fedora 2 system, and you cannot add Linux swap partitions in the rescue mode. This is totally different from the reference documents.

  1. To learn about Linux, we recommend that you start with Fedora.
  2. Linux hostname configuration file and file/etc/hosts
  3. Linux File redirection and file Filter
  4. Successful commercial behaviors and profit models of Linux open-source software
  5. Six advantages of Linux

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.