Swap partition Swap:
When the CPU is running out of memory, it temporarily consumes a portion of the hard disk space to store memory information, which is the swap partition.
To create a new swap partition swap:
1 Create a new partition by setting the ID to create a swap partition
2 format swap partition MKSWAP device name
3 Start Swap:swapon device name
4 View Swap:free Commands
mkswap command : Set up a swap partition swap format via device or file
Mkswap [Options] device [size]
Parameters:
-C: Detect bad blocks before creating swap partitions
-F,--force: forcing creation
-L,--label ' label ': created according to the specified label
-u,--uuid UUID: Based on UUID creation
Free Command : View the usage status of memory and swap partition swaps
free [options]
-M: in megabytes
-G: in gigabytes
-H: Display capacity in an easy-to-read manner
swapon, Swapoff command :
Enabling and disabling devices and files as swap partitions
(Enable/disable devices and files for paging and swapping)
Swapon: Enable swap partition
swapon [option] [DEVICE]
-A: Activate all swap partitions
-P Priority: set its precedence;
-V: Show more information
Swapoff: Disable swap partition
swapoff [option] [DEVICE]
-A: Disable all swap partitions
-V: Show more information
Example:
#1 Create a new partition swap[[email protected] ~]# fdisk /dev/sdawelcome to fdisk ( util-linux 2.23.2). changes will remain in memory only, until you decide to Write them. Be careful before using the write command. command (m for help): nall primary partitions are in useadding logical partition 9First sector (107507712-251658239, default 107507712): &NBSP;USING&NBSP;DEFAULT&NBSP;VALUE&NBSP;107507712LAST&NBSP;SECTOR,&NBSP;+SECTORS&NBSP;OR&NBSP;+SIZE{K,M,G} (107507712-251658239, default 251658239): +512mpartition 9 of type linux and of size 512 mib is setcommand (M&NBSP;FOR&NBSP;HELP): pdisk /dev/sda: 128.8 gb, 128849018880 bytes, 251658240 sectorsunits = sectors of 1 * 512 = 512 bytessector size (logical/physical): 512 bytes / 512 bytesI/O size (Minimum/optimal): 512 bytes / 512 bytesdisk label type: dosdisk identifier: 0x000c2314 device boot start end Blocks Id System..../dev/sda6 82337792 86532095 2097152 82 Linux swap / Solaris/dev/sda7 61853696 61855743 1024 83 Linux/dev/sda8 86534144 107505663 10485760 83 linux/dev/sda9 107507712 108556287 524288 83 linuxpartition table entries are not in disk ordercommand (m for &NBSP;HELP): tpartition number (1-9, default 9): 9hex code (type L to list all codes): l 0 empty 24 NEC DOS 81 minix / old lin bf solaris 1 FAT12 27 hidden ntfs win 82 linux swap / so c1 drdos/sec (FAT-&NBSP;2&NBsp; xenix root 39 plan 9 83 Linux c4 DRDOS/sec (fat- 3 xenix usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (fat- 4 fat16 <32m 40 Venix 80286 85 Linux extended c7 Syrinx 5 Extended 41 ppc prep boot 86 ntfs volume set da non-fs data 6 fat16 42 sfs 87 NTFS volume set db CP/M / CTOS / . 7 hpfs/ntfs/exfat 4d qnx4.x 88 Linux plaintext de Dell Utility 8 AIX 4e qnx4.x 2nd part 8e linux lvm df bootit 9 aix bootable 4f QNX4.x 3rd part 93 Amoeba e1 dos access a os/2 boot&nBsp Manag 50 ontrack dm 94 amoeba bbt e3 DOS R/O b w95 fat32 51 ontrack dm6 Aux 9f BSD/OS e4 speedstor c w95 fat32 (LBA) 52 Cp/m a0 ibm thinkpad hi eb beos fs e w95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT &nbsP;f w95 ext ' d (LBA) 54 ontrackdm6 a6 OpenBSD ef EFI (FAT-12/16/10 opus 55 ez-drive a7 NeXTSTEP f0 Linux/PA-RISC b11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 speedstor 12 compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor 14 hidden fat16 ≪3 61 speedstor ab darwin boot f2 dos secondary 16 hidden fat16 63 gnu hurd or sys af hfs / hfs+ fb vmware vmfs 17 hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc vmware vmkcore 18 ast smartsleep 65 Novell Netware b8 BSDI swap fd Linux raid auto1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep 1c hidden w95 fat3 75 pc/ix be Solaris boot ff BBT 1e hidden w95 fat1 80 Old Minix Hex code (type l to list all codes): 82changed type of partition ' Linux ' to ' Linux swap / solaris ' command (m for help): pdisk /dev/sda: 128.8 gb, 128849018880 bytes, 251658240 sectorsunits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesi/o size (minimum/optimal): 512 bytes / 512 bytesdisk label type: dosdisk identifier: 0x000c2314 device boot start end blocks id system....../dev/sda6 82337792 86532095 2097152 82 linux swap / Solaris/dev/sda7 61853696 61855743 1024 83 linux/ dev/sda8 86534144 107505663 10485760 83 Linux/dev/sda9 107507712 108556287 524288 82 Linux swap / solarispartition table entries are not in disk ordercommand (m for &NBSP;HELP): wthe 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 will be used atthe next reboot or after you run partprobe (8) or kpartx (8) syncing disks. #2 Format swap partition [[email protected] ~]# mkswap / Dev/sda9setting up swapspace version 1, size = 524284 kibno label , uuid=7362fb3d-4bda-41d4-bef5-ba238de58aa2# viewing memory information [[email protected] ~]# free - h total used free shared buff/cache availableMem: 979M 127M 704M 6.7M 147M 703MSwap: 2.0G 0B 2.0G# 3 Load swap partition [[Email protected] ~]# swapon /dev/sda9[[email protected] ~]# free -h total used free shared buff/cache availablemem: 979M 128M 704M 6.7M 147M 702MSwap: 2.5G 0B 2.5g# deactivate the specified swap partition [[[email protected] ~]# swapoff -v /dev/ sda9swapoff /dev/sda9# enable the specified swap partition [[Email protected] ~]# swapon -v /dev/sda9swapon /dev/sda9swapon: /dev/sda9: found swap signature: version 1, Page-size 4, same byte orderswapon: /dev/sda9: pagesize=4096, swapsize=536870912, devsize=536870912
If there is any mistake, please correct me!
Thank you!
Linux disk and File System Management (5) _ Create swap partition