swapon 命令详解

| 选择喜欢的代码风格  

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

swapon 命令安装:


  1. -bash/zsh: swapon command not found
  2.  
  3. #Debian
  4. apt-get install mount
  5.  
  6. #Ubuntu
  7. apt-get install mount
  8.  
  9. #Alpine
  10. apk add util-linux
  11.  
  12. #Arch Linux
  13. pacman -S util-linux
  14.  
  15. #Kali Linux
  16. apt-get install mount
  17.  
  18. #CentOS
  19. yum install util-linux
  20.  
  21. #Fedora
  22. dnf install util-linux
  23.  
  24. #OS X
  25. brew install util-linux
  26.  
  27. #Raspbian
  28. apt-get install loop-aes-utils
  29.  
  30. #Docker
  31. docker run cmd.cat/swapon swapon

swapon 命令补充说明:


swapon 命令用于激活 Linux 系统中交换空间,Linux 系统的内存管理必须使用交换区来建立虚拟内存。

swapon 命令语法:


  1. swapon [options] [specialfile...]
  2.  
  3. --------------------------------
  4. To get swap information:
  5. swapon -s [-h] [-V]
  6.  
  7. To enable a swap area:
  8. swapon [-d] [-f] [-p priority] [-v] specialfile...
  9.  
  10. To disable a swap area:
  11. swapoff [-v] specialfile...
  12.  
  13. To enable all swap areas:
  14. swapon -a [-e] [-f] [-v]
  15.  
  16. To disable all swap areas:
  17. swapoff -a [-v]

swapon 命令选项:


  1. -a, --all
  2. All devices marked as ``swap'' in /etc/fstab are made
  3. available, except for those with the ``noauto'' option.
  4. Devices that are already being used as swap are silently
  5. skipped.
  6.  
  7. -d, --discard[=policy]
  8. Enable swap discards, if the swap backing device supports
  9. the discard or trim operation. This may improve
  10. performance on some Solid State Devices, but often it does
  11. not. The option allows one to select between two
  12. available swap discard policies: --discard=once to perform
  13. a single-time discard operation for the whole swap area at
  14. swapon; or --discard=pages to asynchronously discard freed
  15. swap pages before they are available for reuse. If no
  16. policy is selected, the default behavior is to enable both
  17. discard types. The /etc/fstab mount options discard,
  18. discard=once, or discard=pages may also be used to enable
  19. discard flags.
  20.  
  21. -e, --ifexists
  22. Silently skip devices that do not exist. The /etc/fstab
  23. mount option nofail may also be used to skip non-existing
  24. device.
  25.  
  26. -f, --fixpgsz
  27. Reinitialize (exec mkswap) the swap space if its page size
  28. does not match that of the current running kernel.
  29. mkswap(8) initializes the whole device and does not check
  30. for bad blocks.
  31.  
  32. -h, --help
  33. Display help text and exit.
  34.  
  35. -L label
  36. Use the partition that has the specified label. (For
  37. this, access to /proc/partitions is needed.)
  38.  
  39. -o, --options opts
  40. Specify swap options by an fstab-compatible comma-
  41. separated string. For example:
  42.  
  43. swapon -o pri=1,discard=pages,nofail /dev/sda2
  44.  
  45. The opts string is evaluated last and overrides all other
  46. command line options.
  47.  
  48. -p, --priority priority
  49. Specify the priority of the swap device. priority is a
  50. value between -1 and 32767. Higher numbers indicate
  51. higher priority. See swapon(2) for a full description of
  52. swap priorities. Add pri=value to the option field of
  53. /etc/fstab for use with swapon -a. When no priority is
  54. defined, it defaults to -1.
  55.  
  56. -s, --summary
  57. Display swap usage summary by device. Equivalent to "cat
  58. /proc/swaps". This output format is DEPRECATED in favour
  59. of --show that provides better control on output data.
  60.  
  61. --show[=column...]
  62. Display a definable table of swap areas. See the --help
  63. output for a list of available columns.
  64.  
  65. --output-all
  66. Output all available columns.
  67.  
  68. --noheadings
  69. Do not print headings when displaying --show output.
  70.  
  71. --raw Display --show output without aligning table columns.
  72.  
  73. --bytes
  74. Display swap size in bytes in --show output instead of in
  75. user-friendly units.
  76.  
  77. -U uuid
  78. Use the partition that has the specified uuid.
  79.  
  80. -v, --verbose
  81. Be verbose.
  82.  
  83. -V, --version
  84. Display version information and exit.

swapon 命令实例:


swapon 获取交换信息:

  1. swapon -s

swapon 启用给定的交换分区:

  1. swapon /dev/sdb7

swapon 启用给定的交换文件:

  1. swapon path/to/file

swapon 启用所有交换区域:

  1. swapon -a

swapon 通过设备或文件的标签启用交换:

  1. swapon -L swap1

swapon 命令扩展阅读:




swapon 命令评论