First, using physical partitions to build swap
1, the first partition of the behavior.
1[Email protected] ~]# fdisk/dev/Xvdb2Welcome to Fdisk (util-linux2.23.2).3 4Changes'll remaininchMemory only,untilYou decide toWritethem.5Be careful before using theWritecommand.6 7 8Command (M forHelp ): N9 Partition Type:TenP Primary (1Primary0Extended3 Free) One e Extended A Select (default p): P -Partition Number (1,3,4, default1):4 -First Sector (20973568-62914559, default20973568): theUsing Default Value20973568 -Last sector, +sectors or +size{k,m,g} (20973568-62914559, default62914559): +512m -Partition4of type Linux and of sizeTenGiB is set - +Command (M forHelp ): P - +DISK/DEV/XVDB:32.2GB,32212254720bytes62914560Sectors AUnits = sectors of1* += +bytes atSector size (logical/physical): +Bytes/ +bytes -I/O size (minimum/optimal): +Bytes/ +bytes - Disk label Type:dos -Disk identifier:0x25a2caf5 - - Device Boot Start End Blocks Id System in/dev/xvdb22048 20973567 10485760 theLinux -/dev/xvdb420973568 41945087 10485760 theLinux to +Command (M forHelp ): T <== modify the System ID -Partition Number (2,4, default4):4 theHex code (type L to list all codes):the ID of the <== changed to swap *Changed type of partition'Linux'To'Linux Swap/solaris' $ Panax NotoginsengCommand (M forHelp ): P - theDISK/DEV/XVDB:32.2GB,32212254720bytes62914560Sectors +Units = sectors of1* += +bytes ASector size (logical/physical): +Bytes/ +bytes theI/O size (minimum/optimal): +Bytes/ +bytes + Disk label Type:dos -Disk identifier:0x25a2caf5 $ $ Device Boot Start End Blocks Id System -/dev/xvdb22048 20973567 10485760 theLinux -/dev/xvdb420973568 41945087 10485760 theLinux Swap/Solaris the -Command (M forHelp):WWuyiThe partition table has been altered! the -Calling IOCTL () to re-read partition table. WuSyncing disks.
Force kernel update partition table:
[Email protected] ~]# Partprobe
2. Start building swap format.
[Email protected] ~]# mkswap/dev/15485756 kibno label, UUID=033a1d75-88fd- 4347-8726-08d856cb9ad1
3. Check and load.
1[Email protected] ~]# swapon/dev/XVDB42[Email protected] ~]# Free3Total used Freeshared buffers Cached4Mem:1016656 152956 863700 6624 11036 758285-/+ Buffers/cache:66092 9505646Swap:10485756 0 10485756
[Email protected] ~]# swapon-sfilename Type Size used priority/DEV/XVDB4 Partition 10485756 0 -1
Ii. using a file system to build swap
1, use the DD command to add a 128MB file under/data:
1 DD if=/dev/zero of=/data/swap bs=1m count=2+0in3 +0 Recordsout 4536870912 bytes (537 7.8214968.6 MB/s
2, using Mkswap will/data/swap this file format swap file format:
1 [[email protected] ~]# mkswap/data/21524284 KiB3 No Label, UUID=EDE63D44-CF78-4D08-92CA-15FB38A625F4
3, use Swapon to start the/data/swap
1[Email protected] ~]# swapon/data/Swap2Swapon:/data/swap:insecure Permissions0644,0600suggested.3[Email protected] ~]# Free-m4Total used Freeshared buffers Cached5Mem:992 670 322 6 One 5866-/+ Buffers/cache: the 9197Swap:511 0 5118[Email protected] ~]# Swapon-s9 Filename Type Size used priorityTen/data/swapfile 524284 0-1
Use Swapoff to turn off Swapfile
1 [[email protected] ~]# swapoff/dev/xvdb42
To enable swap to mount automatically, modify the/etc/fstab file
At the end of the file, add
/data/swap Swap swap default 0 0
This way, the swap partition does not have to be mounted manually, even if the system is restarted.
Building of Memory swap space (swap)