启动时未安装交换区(UUID 正确)

启动时未安装交换区(UUID 正确)

我无法在启动时自动挂载交换区。Ubuntu 16.04。

我读过很多文章/论坛,通常每个人都指向错误的 UUID。我的 UUID 100% 正确。我也尝试过通过 /dev/sdc1 而不是 UUID 进行挂载,这没什么区别。

journalctl 指示交换分区已被识别并安装,但 free 显示尚未识别并安装。

root@openflixr:~# free
              total        used        free      shared  buff/cache   available
Mem:       10232716     1363616     7179204       24664     1689896     8455264
Swap:             0           0           0

root@openflixr:~# lsblk -fm
NAME   FSTYPE LABEL UUID                                 MOUNTPOINT     NAME    SIZE OWNER GROUP MODE
sdb                                                                     sdb      52G root  disk  brw-rw----
└─sdb1 ext3         a3ea80ea-9304-44b5-b780-2cc66e56a75e /mnt/downloads └─sdb1   52G root  disk  brw-rw----
sr0                                                                     sr0    1024M root  cdrom brw-rw----
sdc                                                                     sdc      16G root  disk  brw-rw----
└─sdc1 swap         4c778935-85d6-4399-8083-43906ba1872f                └─sdc1   16G root  disk  brw-rw----
sda                                                                     sda     100G root  disk  brw-rw----
└─sda1 ext4         8f023205-2b57-4f4d-80d3-b557a3f2aa58 /              └─sda1   96G root  disk  brw-rw----

root@openflixr:~# journalctl | grep -i swap
Sep 22 11:43:14 openflixr kernel: zswap: loaded using pool lzo/zbud
Sep 22 11:43:14 openflixr systemd[1]: Activating swap /dev/disk/by-uuid/4c778935-85d6-4399-8083-43906ba1872f...
Sep 22 11:43:14 openflixr kernel: Adding 16771068k swap on /dev/sdc1.  Priority:-2 extents:1 across:16771068k FS
Sep 22 11:43:14 openflixr systemd[1]: Activated swap /dev/disk/by-uuid/4c778935-85d6-4399-8083-43906ba1872f.
Sep 22 11:43:14 openflixr systemd[1]: Reached target Swap.

root@openflixr:~# journalctl | grep sdc
Sep 22 11:43:14 openflixr kernel: sd 2:0:2:0: [sdc] 33554432 512-byte logical blocks: (17.2 GB/16.0 GiB)
Sep 22 11:43:14 openflixr kernel: sd 2:0:2:0: [sdc] Write Protect is off
Sep 22 11:43:14 openflixr kernel: sd 2:0:2:0: [sdc] Mode Sense: 61 00 00 00
Sep 22 11:43:14 openflixr kernel: sd 2:0:2:0: [sdc] Cache data unavailable
Sep 22 11:43:14 openflixr kernel: sd 2:0:2:0: [sdc] Assuming drive cache: write through
Sep 22 11:43:14 openflixr kernel:  sdc: sdc1
Sep 22 11:43:14 openflixr kernel: sd 2:0:2:0: [sdc] Attached SCSI disk
Sep 22 11:43:14 openflixr kernel: Adding 16771068k swap on /dev/sdc1.  Priority:-2 extents:1 across:16771068k FS

root@openflixr:~# mount -va
/                        : ignored
/mnt/downloads           : already mounted
swap                     : ignored

root@openflixr:~# cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda1 during installation
UUID=8f023205-2b57-4f4d-80d3-b557a3f2aa58 /               ext4    errors=remount-ro 0       1
/dev/sdb1       /mnt/downloads  ext3    defaults        0       0
UUID=4c778935-85d6-4399-8083-43906ba1872f       none    swap    sw      0       0

root@openflixr:~# fdisk -l /dev/sdc
Disk /dev/sdc: 16 GiB, 17179869184 bytes, 33554432 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: 0xb623abb1

Device     Boot Start      End  Sectors Size Id Type
/dev/sdc1        2048 33544191 33542144  16G 82 Linux swap / Solaris

root@openflixr:~# systemctl status swap.target
● swap.target - Swap
   Loaded: loaded (/lib/systemd/system/swap.target; static; vendor preset: enabled)
   Active: active since Sat 2018-09-22 11:43:14 NZST; 14min ago
     Docs: man:systemd.special(7)

Sep 22 11:43:14 openflixr systemd[1]: Reached target Swap.

但这似乎是不正确的:

root@openflixr:~# systemctl --type swap
0 loaded units listed. Pass --all to see loaded but inactive units, too.

root@openflixr:~# systemctl --type swap --all
UNIT                                         LOAD   ACTIVE   SUB  DESCRIPTION
dev-disk-by\x2duuid-4c778935\x2d85d6\x2d4399\x2d8083\x2d43906ba1872f.swap loaded inactive dead /dev/disk/by-uui

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.

1 loaded units listed.

只要我做任何与交换相关的事情,它就显示正常。

root@openflixr:~# swapon -va
swapon /dev/sdc1
swapon: /dev/sdc1: found swap signature: version 1d, page-size 4, same byte order
swapon: /dev/sdc1: pagesize=4096, swapsize=17173577728, devsize=17173577728

root@openflixr:~# free
              total        used        free      shared  buff/cache   available
Mem:       10232728     1450820     7083756       24664     1698152     8366116
Swap:      16771068           0    16771068

我已经擦除并重新创建了磁盘的分区表,我最初将其创建为 GPT,但我知道 GPT 上的交换可能存在问题,所以它现在是 MS-DOS。

我觉得这与 systemd 有关,而不是与“旧”的交换方式有关,但我已经尝试了很多方法都没有成功。

我现在已经用完了谷歌搜索结果,因此非常感谢任何帮助。

编辑:更新 /etc/fstab 以使用挂载点“none”而不是“swap” - 没有变化。

编辑:问题似乎集中在这个 systemctl 上:

root@openflixr:~# systemctl --type swap --all
UNIT                                         LOAD   ACTIVE   SUB  DESCRIPTION
dev-disk-by\x2duuid-4c778935\x2d85d6\x2d4399\x2d8083\x2d43906ba1872f.swap loaded inactive dead /dev/disk/by-uui

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.

1 loaded units listed.
To show all installed unit files use 'systemctl list-unit-files'.

root@openflixr:~# systemctl start swap.target

root@openflixr:~# systemctl --type swap --all
UNIT                                         LOAD   ACTIVE SUB    DESCRIPTION
dev-disk-by\x2dpath-pci\x2d0000:03:00.0\x2dsas\x2dphy2\x2dlun\x2d0\x2dpart1.swap loaded active active /dev/disk
dev-disk-by\x2duuid-4c778935\x2d85d6\x2d4399\x2d8083\x2d43906ba1872f.swap loaded active active /dev/disk/by-uui
dev-sdc1.swap                                loaded active active /dev/sdc1

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.

3 loaded units listed.

我不明白 - systemctl 的 swap.target 单元已启用,并且如上所述,journalctl 输出显示已找到并激活交换。

  • 杰伊

答案1

哇哦。发现问题了:

root@openflixr:/etc# cat rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
echo "32768 61000" >/proc/sys/net/ipv4/ip_local_port_range
swapoff -a  <------------------------------------------------- doh
echo noop >/sys/block/sda/queue/scheduler
echo 1 >/sys/kernel/mm/ksm/run
echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs

这就是你不建造机器时会发生的情况。大家一定要检查基础知识。

我会现身的。

相关内容