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:
- [root@zheng root]#fdisk –l
- Disk /dev/had:8589 MB,858990124 bytes
- 16 heads,63 sectors/track,16644 cylinders
- Units = culinders of 1008 * 512 = 516096 bytes
- Device BootStart End Blocks Id System
- /dev/hda1*1 203 102280+ 83 Linux
- /dev/hda2 204 14564 7237944 83 Linux
- /dev/hda3 14565 16644 1048320 82 Linux swap
- [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:
- [Root @ zheng root] # fdisk/dev/hdb
- Command (m for help): n // create a new partition
- Command action
- E extend
- P primary partition (1-4)
- P // The primary partition type.
- Partition number (1-4): 1
- First cylinder (1-2080, default 1 ):
- Using default value 1
- Last cylinder or + size or + sizeM or + sizeK (1-2080, default 2080 ):
- Using default value 2080
- Command (m for help): t // change the partition format
- Selected partition 1
- Hex code (type L to list codes): 82 // The hexadecimal code of Linux swap is 82
- Command (m for help): p
- Disk/dev/hab: 1073 MB, 1073479680 bytes
- 16 heads, 63 sectors/track, 2080 cylinders
- Units=CulindersOf 1008 *512=516096Bytes
- Device BootStart End Blocks Id System
- /Dev/hdb1*1 20801048288 + 82 Linux swap
- Command (m for help): w // save partition information
- 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:
- Activiting swap partition: [OK] // activate Linux swap partition
- 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:
- [root@zheng root]#fdisk –l
- Disk /dev/had:8589 MB,858990124 bytes
- 16 heads,63 sectors/track,16644 cylinders
- Units = culinders of 1008 * 512 = 516096 bytes
- Device BootStart End Blocks Id System
- /dev/hda1* 1 203 102280+ 83 Linux
- /dev/hda2 204145647237944 83 Linux
- Disk /dev/hab:1073 MB,1073479680 bytes
- 16 heads,63 sectors/track,2080 cylinders
- Units = culinders of 1008 * 512 = 516096 bytes
- Device BootStart End Blocks Id System
- /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.
- To learn about Linux, we recommend that you start with Fedora.
- Linux hostname configuration file and file/etc/hosts
- Linux File redirection and file Filter
- Successful commercial behaviors and profit models of Linux open-source software
- Six advantages of Linux