我最近发现每次我关闭/重新启动机器时,都会记录一条错误,内容为swapoff failed: Invalid argument
。
Jul 22 21:09:02 Frederick-Kubuntu systemd[1]: Stopping Update UTMP about System Boot/Shutdown...
Jul 22 21:09:02 Frederick-Kubuntu swapoff[5049]: swapoff: /dev/disk/by-uuid/cc08e210-8609-4cf8-9b7c-6af95b0c38eb: swapoff failed: Invalid argument
Jul 22 21:09:02 Frederick-Kubuntu systemd[1]: Stopped target Remote File Systems.
Jul 22 21:09:02 Frederick-Kubuntu systemd[1]: Stopped target Remote File Systems (Pre).
Jul 22 21:09:02 Frederick-Kubuntu systemd[1]: Stopped target User and Group Name Lookups.
Jul 22 21:09:02 Frederick-Kubuntu systemd[5049]: dev-disk-by\x2duuid-cc08e210\x2d8609\x2d4cf8\x2d9b7c\x2d6af95b0c38eb.swap: Executing: /sbin/swapoff /dev/disk/by-uuid/cc08e210-8609-4cf8-9b7c-6af95b0c38eb
Jul 22 21:09:02 Frederick-Kubuntu systemd[5048]: dev-nvme0n1p9.swap: Executing: /sbin/swapoff /dev/nvme0n1p9
Jul 22 21:09:02 Frederick-Kubuntu systemd[5051]: systemd-update-utmp.service: Executing: /lib/systemd/systemd-update-utmp shutdown
Jul 22 21:09:02 Frederick-Kubuntu systemd[1]: Stopped Load/Save Random Seed.
Jul 22 21:09:02 Frederick-Kubuntu systemd[1]: Stopped Load/Save Screen Backlight Brightness of backlight:acpi_video0.
Jul 22 21:09:02 Frederick-Kubuntu systemd[1]: dev-disk-by\x2duuid-cc08e210\x2d8609\x2d4cf8\x2d9b7c\x2d6af95b0c38eb.swap: Swap process exited, code=exited status=255
Jul 22 21:09:02 Frederick-Kubuntu systemd[1]: Deactivated swap /dev/disk/by-uuid/cc08e210-8609-4cf8-9b7c-6af95b0c38eb.
Jul 22 21:09:02 Frederick-Kubuntu systemd[1]: dev-disk-by\x2duuid-cc08e210\x2d8609\x2d4cf8\x2d9b7c\x2d6af95b0c38eb.swap: Unit entered failed state.
Jul 22 21:09:02 Frederick-Kubuntu systemd[1]: Deactivated swap /dev/disk/by-partuuid/3c715e0f-205c-4138-9249-127984925f66.
Jul 22 21:09:02 Frederick-Kubuntu systemd[1]: Deactivated swap /dev/disk/by-partlabel/Linux\x20Swap.
Jul 22 21:09:02 Frederick-Kubuntu systemd[1]: Deactivated swap Swap Partition.
Jul 22 21:09:02 Frederick-Kubuntu systemd[1]: Stopped Update UTMP about System Boot/Shutdown.
我尝试手动执行该命令,没有发现任何错误。
frederick@Frederick-Kubuntu:~$ sudo blkid /dev/nvme0n1p9 # this is the swap part
/dev/nvme0n1p9: UUID="cc08e210-8609-4cf8-9b7c-6af95b0c38eb" TYPE="swap" PARTLABEL="Linux Swap" PARTUUID="3c715e0f-205c-4138-9249-127984925f66"
frederick@Frederick-Kubuntu:~$ free -m
total used free shared buff/cache available
Mem: 16000 1828 12462 88 1709 13734
Swap: 7629 0 7629
frederick@Frederick-Kubuntu:~$ sudo /sbin/swapoff /dev/disk/by-uuid/cc08e210-8609-4cf8-9b7c-6af95b0c38eb
frederick@Frederick-Kubuntu:~$ free -m
total used free shared buff/cache available
Mem: 16000 1826 12466 88 1708 13736
Swap: 0 0 0
frederick@Frederick-Kubuntu:~$ sudo /sbin/swapon /dev/disk/by-uuid/cc08e210-8609-4cf8-9b7c-6af95b0c38eb
frederick@Frederick-Kubuntu:~$ free -m
total used free shared buff/cache available
Mem: 16000 1828 12463 88 1708 13734
Swap: 7629 0 7629
我尝试使用它mkswap
来重建交换分区,但没有成功(我指定了 UUID,所以/etc/fstab
仍然正确)。
我该如何消除此错误?提前致谢。
答案1
swapoff
告诉您swapoff failed: Invalid argument
设备何时不再用于交换。例如:
deltik@node51 [~]$ sudo swapoff /dev/zero
swapoff: /dev/zero: swapoff failed: Invalid argument
这不是一个错误。它只是意味着当您关闭计算机时,该设备未被用作交换设备。
如果你想知道为什么 systemd 甚至会尝试这样做swapoff
,那是通过设计(强调矿):
在关闭之前,此二进制文件将尝试卸载所有剩余的文件系统,禁用所有剩余的交换设备,分离所有剩余的存储设备并终止所有剩余的进程。