One
The basic role of the swap partition in Linux:
Linux swap partition is a Linux swap partition: When the Linux system physical memory is not enough, the system will automatically enable the swap partition to relieve the pressure of physical memory, the system to the physical memory of low-frequency access to the memory objects in the swap partition, A new connection is generated in the physical memory to point to a specific object in the swap partition;
Two
In contrast to busy servers, where physical memory and physical partitions are not enough, we need to temporarily expand the size of the swap partition, there are two ways to achieve this:
1. When the extended partition of the hard disk has remaining memory available, you can use the FDISK command to create a new partition, adjust the partition type to Linux-swap, and then enable.
Specific steps:
[[email protected] ~]# free-m//View the usage of physical memory and swap partition
Total used free shared buffers Cached
mem:502 474 28 0 76 274
-/+ buffers/cache:124 378
swap:1019 0 1019
[Email protected] ~]# Fdisk/dev/sdb
The number of cylinders for this disk was set to 2610.
There is nothing wrong with the, but this is larger than 1024,
And could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from the other OSs
(e.g., DOS fdisk, OS/2 fdisk)
Command (M for help): P//Lists the currently created partitions
disk/dev/sdb:21.4 GB, 21474836480 bytes
255 heads, Sectors/track, 2610 cylinders
Units = Cylinders of 16065 * 8225280 bytes
Device Boot Start End Blocks Id System
Command (M for help): N//Create a new partition
Command Action
E Extended
P primary partition (1-4)
P//Primary partition
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using Default value 1
Last cylinder or +size or +sizem or +sizek (1-2610, default 2610): +3g
Command (M for help): t//change partition type
Selected partition 1
Hex code (Type L to list codes): L//List the partitions supported by the kernel
0 Empty 1e Hidden W95 FAT1-old Minix BF Solaris
1 FAT12 NEC DOS bayi minix/old Lin C1 drdos/sec (fat-
2 Xenix root Plan 9 swap/so c4 drdos/sec (fat-
3 Xenix usr 3c partitionmagic Linux c6 drdos/sec (fat-
4 FAT16 <32m Venix 80286, os/2 hidden c:c7 syrinx
5 Extended PPC PReP Boot, Linux Extended da non-fs data
6 FAT16 SFS, NTFS volume set db cp/m/CTOS/.
7 Hpfs/ntfs 4d qnx4.x NTFS Volume set de Dell Utility
8 AIX 4e qnx4.x 2nd part Linux plaintext DF bootit
9 AIX Bootable 4f qnx4.x 3rd part 8e Linux LVM E1 DOS Access
A os/2 Boot manag ontrack DM amoeba E3 DOS r/o
b W95 FAT32 Wuyi Ontrack DM6 Aux 94 Amoeba BBT e4 SpeedStor
C W95 FAT32 (LBA) cp/m 9f bsd/os EB BeOS FS
E W95 FAT16 (LBA) Ontrack DM6 Aux a0 IBM Thinkpad hi ee EFI GPT
F W95 Ext ' d (LBA) OnTrackDM6 a5 FreeBSD ef EFI (fat-12/16/
Ten OPUS ez-drive a6 OpenBSD f0 linux/pa-risc b
Hidden FAT12 Bow A7 NeXTSTEP F1 SpeedStor
Compaq Diagnost 5c Priam edisk A8 Darwin UFS f4 SpeedStor
Hidden FAT16 <3 speedstor A9 NetBSD F2 DOS Secondary
Hidden FAT16, GNU HURD or Sys ab Darwin boot fb VMware VMFS
Hidden hpfs/ntf Novell Netware b7 BSDI FS FC VMware Vmkcore
AST smartsleep Novell Netware b8 BSDI swap fd Linux RAID auto
1b Hidden W95 FAT3 disksecure Mult bb Boot Wizard hid Fe lanstep
1c Hidden W95 FAT3 pc/ix be Solaris boot ff BBT
Hex code (type L to list codes): 82
Changed system type of partition 1 to Swap/solaris (Linux)
Command (M for help): w//Save partition
The partition table has been altered!
Calling IOCTL () to re-read partition table.
Warning:re-reading the partition table failed with error 16:device or resource busy.
The kernel still uses the old table.
The new table is used at the next reboot.
Syncing disks.
[[email protected] ~]# PARTPROBE/DEV/SDB//Let the kernel reread the partition table
[[email protected] ~]# cat/proc/partitions//Ensure kernel reread partition table complete
Major Minor #blocks name
8 0 20971520 SDA
8 1 305203 sda1
8 2 19615365 Sda2
8 3 1044225 Sda3
8 20971520 SDB
8 2939863 SDB1
[[Email protected] ~] #mkswap/dev/sdb1//Formatting
Setting up Swapspace version 1, size = 3010412 KB
[[email protected] ~]# SWAPON/DEV/SDB1//enable the swap partition
[Email protected] ~]# free-m
Total used free shared buffers Cached
mem:502 394 107 0 30 273
-/+ buffers/cache:90 412
swap:3890 0 3890
[[email protected] ~]# SWAPOFF/DEV/SDB1//close the swap partition
[Email protected] ~]# free-m
Total used free shared buffers Cached
mem:502 393 108 0 30 273
-/+ buffers/cache:89 413
swap:1019 0 1019
2. When the hard disk has no remaining storage to create a new partition, you can use the DD command to create a file in the saved partition to act as a swap partition.
Specific steps: (present script form)
[Email protected] ~]# VI createswap.sh
#!/bin/bash
Echo-n "Please input your number:"
Read number
Echo-n "Please input your swapfile name and the whole path:"
Read path
DD If=/dev/zero of= $path bs=1m count= $number
Mkswap $path
Swapon $path
Free-m
echo "The swap created"
Concluding remarks: This tutorial is complete.
Application of Linux DD in expanding swap partition