我的swap在哪?为什么要有swap?没有swap行不行?

root@debian:/home/liujianwei# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 113G 11G 96G 11% / udev 10M 0 10M 0% /dev tmpfs 1.6G 9.1M 1.6G 1% /run tmpfs 4.0G 228K 4.0G 1% /dev/shm tmpfs 5.0M 4.0K 5.0M 1% /run/lock tmpfs 4.0G 0 4.0G 0% /sys/fs/cgroup tmpfs 801M 8.0K 801M 1% /run/user/117 tmpfs 801M 20K 801M 1% /run/user/1000

一般情况下 df 用于显示已挂载文件系统的用量情况。swap 不属此列
执行以下指令将结果全部复制贴上来

fdisk -l

若没有 swap {分区, 文件},其一是 OOM 时会比较窘迫,其二是无法实现休眠

[quote=“cuthead”]root@debian:/home/liujianwei# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 113G 11G 96G 11% / udev 10M 0 10M 0% /dev tmpfs 1.6G 9.1M 1.6G 1% /run tmpfs 4.0G 228K 4.0G 1% /dev/shm tmpfs 5.0M 4.0K 5.0M 1% /run/lock tmpfs 4.0G 0 4.0G 0% /sys/fs/cgroup tmpfs 801M 8.0K 801M 1% /run/user/117 tmpfs 801M 20K 801M 1% /run/user/1000 [/quote]

内存大可以不要swap,如果你有ssd+8G以上内存,就别要了

有4g内存就可以不要swap了

liujianwei@debian:~$ fdisk -l bash: fdisk: command not found liujianwei@debian:~$ su Password: root@debian:/home/liujianwei# apt-get install fdisk Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package fdisk root@debian:/home/liujianwei#

[quote=“cuthead”]liujianwei@debian:~$ fdisk -l
bash: fdisk: command not found[/quote]

fdisk 的可执行文件位于 /sbin,默认情况下普通用户的 PATH 不包含 /sbin
可使用 su 切换到 root 身份运行。

[quote=“cuthead”]root@debian:/home/liujianwei# apt-get install fdisk
E: Unable to locate package fdisk[/quote]

fdisk 包含在软件包 util-linux 中,默认应该已安装

==============================
附 如何搜索包含 fdisk 的软件包名称

方法1
用 apt-file 搜索包含某个具体文件的包名
先安装 apt-file 套件
第一次使用 apt-file 需要先建立索引(用 root 身份运行一次 apt-file update)

$ apt-file search fdisk | grep bin acorn-fdisk: /sbin/acorn-fdisk afflib-tools: /usr/bin/affdiskprint amiga-fdisk-cross: /sbin/amiga-fdisk mtd-utils: /usr/sbin/docfdisk util-linux: /sbin/cfdisk util-linux: /sbin/fdisk util-linux: /sbin/sfdisk
可见 fdisk 包含在 util-linux 中

方法2
debian.org/distrib/packages#search_contents
单选按钮选择 'packages that contain files whose names contain the keyword’
关键词填 fdisk
搜索,得到 packages.debian.org/search?searchon=contents&keywords=fdisk&mode=filename&suite=stable&arch=any
可见 fdisk 包含在 util-linux 中

[code]liujianwei@debian:~$ su
Password:
root@debian:/home/liujianwei# fdisk -l

Disk /dev/sda: 119.2 GiB, 128035676160 bytes, 250069680 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x2e86fc1f

Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 239855615 239853568 114.4G 83 Linux
/dev/sda2 239857662 250068991 10211330 4.9G 5 Extended
/dev/sda5 239857664 250068991 10211328 4.9G 82 Linux swap / Solaris

root@debian:/home/liujianwei# which fdisk
/sbin/fdisk
root@debian:/home/liujianwei# apt-get install apt-file
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following packages were automatically installed and are no longer required:
libglademm-2.4-1c2a libtrio2 libvorbisidec1
Use ‘apt-get autoremove’ to remove them.
The following extra packages will be installed:
curl libapt-pkg-perl libconfig-file-perl libcurl3 liblist-moreutils-perl
libregexp-assemble-perl
Suggested packages:
sudo
The following NEW packages will be installed:
apt-file curl libapt-pkg-perl libconfig-file-perl libcurl3
liblist-moreutils-perl libregexp-assemble-perl
0 upgraded, 7 newly installed, 0 to remove and 2 not upgraded.
Need to get 711 kB of archives.
After this operation, 1,631 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirrors.tuna.tsinghua.edu.cn/debian/ jessie/main libcurl3 amd64 7.38.0-4+deb8u4 [259 kB]
Get:2 http://mirrors.tuna.tsinghua.edu.cn/debian/ jessie/main curl amd64 7.38.0-4+deb8u4 [200 kB]
Get:3 http://mirrors.tuna.tsinghua.edu.cn/debian/ jessie/main libconfig-file-perl all 1.50-2 [10.0 kB]
Get:4 http://mirrors.tuna.tsinghua.edu.cn/debian/ jessie/main libapt-pkg-perl amd64 0.1.29+b2 [77.4 kB]
Get:5 http://mirrors.tuna.tsinghua.edu.cn/debian/ jessie/main liblist-moreutils-perl amd64 0.33-2+b1 [44.4 kB]
Get:6 http://mirrors.tuna.tsinghua.edu.cn/debian/ jessie/main libregexp-assemble-perl all 0.35-8 [90.0 kB]
Get:7 http://mirrors.tuna.tsinghua.edu.cn/debian/ jessie/main apt-file all 2.5.4 [29.9 kB]
Fetched 711 kB in 0s (1,005 kB/s)
Selecting previously unselected package libcurl3:amd64.
(Reading database … 158592 files and directories currently installed.)
Preparing to unpack …/libcurl3_7.38.0-4+deb8u4_amd64.deb …
Unpacking libcurl3:amd64 (7.38.0-4+deb8u4) …
Selecting previously unselected package curl.
Preparing to unpack …/curl_7.38.0-4+deb8u4_amd64.deb …
Unpacking curl (7.38.0-4+deb8u4) …
Selecting previously unselected package libconfig-file-perl.
Preparing to unpack …/libconfig-file-perl_1.50-2_all.deb …
Unpacking libconfig-file-perl (1.50-2) …
Selecting previously unselected package libapt-pkg-perl.
Preparing to unpack …/libapt-pkg-perl_0.1.29+b2_amd64.deb …
Unpacking libapt-pkg-perl (0.1.29+b2) …
Selecting previously unselected package liblist-moreutils-perl.
Preparing to unpack …/liblist-moreutils-perl_0.33-2+b1_amd64.deb …
Unpacking liblist-moreutils-perl (0.33-2+b1) …
Selecting previously unselected package libregexp-assemble-perl.
Preparing to unpack …/libregexp-assemble-perl_0.35-8_all.deb …
Unpacking libregexp-assemble-perl (0.35-8) …
Selecting previously unselected package apt-file.
Preparing to unpack …/apt-file_2.5.4_all.deb …
Unpacking apt-file (2.5.4) …
Processing triggers for man-db (2.7.0.2-5) …
Setting up libcurl3:amd64 (7.38.0-4+deb8u4) …
Setting up curl (7.38.0-4+deb8u4) …
Setting up libconfig-file-perl (1.50-2) …
Setting up libapt-pkg-perl (0.1.29+b2) …
Setting up liblist-moreutils-perl (0.33-2+b1) …
Setting up libregexp-assemble-perl (0.35-8) …
Setting up apt-file (2.5.4) …
The system-wide cache is empty. You may want to run 'apt-file update’
as root to update the cache. You can also run ‘apt-file update’ as
normal user to use a cache in the user’s home directory.
Processing triggers for libc-bin (2.19-18+deb8u6) …
root@debian:/home/liujianwei# apt-file search fdisk | grep bin
E: The cache is empty. You need to run ‘apt-file update’ first.
root@debian:/home/liujianwei# apt-file update
Downloading complete file http://mirrors.tuna.tsinghua.edu.cn/debian/dists/jessie/main/Contents-amd64.gz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 26.0M 100 26.0M 0 0 5003k 0 0:00:05 0:00:05 --:–:-- 4351k
Downloading complete file http://mirrors.tuna.tsinghua.edu.cn/debian/dists/jessie/contrib/Contents-amd64.gz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 88551 100 88551 0 0 714k 0 --:–:-- --:–:-- --:–:-- 714k
Downloading complete file http://mirrors.tuna.tsinghua.edu.cn/debian/dists/jessie/non-free/Contents-amd64.gz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 762k 100 762k 0 0 1995k 0 --:–:-- --:–:-- --:–:-- 2000k
Ignoring source without Contents File:
http://mirrors.tuna.tsinghua.edu.cn/debian-security/dists/jessie/updates/main/Contents-amd64.gz
Ignoring source without Contents File:
http://mirrors.tuna.tsinghua.edu.cn/debian-security/dists/jessie/updates/contrib/Contents-amd64.gz
Ignoring source without Contents File:
http://mirrors.tuna.tsinghua.edu.cn/debian-security/dists/jessie/updates/non-free/Contents-amd64.gz
Downloading complete file http://mirrors.tuna.tsinghua.edu.cn/debian/dists/jessie-updates/main/Contents-amd64.gz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 227k 100 227k 0 0 1440k 0 --:–:-- --:–:-- --:–:-- 1441k
Downloading complete file http://mirrors.tuna.tsinghua.edu.cn/debian/dists/jessie-updates/contrib/Contents-amd64.gz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 20 100 20 0 0 249 0 --:–:-- --:–:-- --:–:-- 253
Downloading complete file http://mirrors.tuna.tsinghua.edu.cn/debian/dists/jessie-updates/non-free/Contents-amd64.gz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 183 100 183 0 0 2402 0 --:–:-- --:–:-- --:–:-- 2376
root@debian:/home/liujianwei# apt-file search fdisk | grep bin
acorn-fdisk: /sbin/acorn-fdisk
afflib-tools: /usr/bin/affdiskprint
amiga-fdisk-cross: /sbin/amiga-fdisk
mtd-utils: /usr/sbin/docfdisk
util-linux: /sbin/cfdisk
util-linux: /sbin/fdisk
util-linux: /sbin/sfdisk
root@debian:/home/liujianwei#
[/code]

已有 swap 分区 sda5。可用多种方式查看其情况

$ free -h
              total        used        free      shared  buff/cache   available
Mem:           3.3G        1.8G        660M         97M        861M        1.1G
Swap:          3.7G        804M        2.9G

$ cat /proc/swaps
Filename                                Type            Size    Used    Priority
/dev/sda5                               partition       3891196 823748  -1

$ cat /proc/meminfo | grep Swap
SwapCached:        88784 kB
SwapTotal:       3891196 kB
SwapFree:        3067708 kB

# swapon -s
Filename                                Type            Size    Used    Priority
/dev/sda5                               partition       3891196 823524  -1

$ htop
$

http://p1.bpimg.com/1949/f8b5eeb350750016.png