swapoff failed: Invalid argument
swapoff
tells you swapoff failed: Invalid argument
when the device is already not being used for swap. Example:
deltik@node51 [~]$ sudo swapoff /dev/zero
swapoff: /dev/zero: swapoff failed: Invalid argument
This is not an error. It just means that the device isn't being used as swap at the time you shut down your computer.
If you're wondering why systemd even tries to swapoff
, it's by design (emphasis mine):
Before shutting down, this binary will try to unmount all remaining file systems, disable all remaining swap devices, detach all remaining storage devices and kill all remaining processes.
Related videos on Youtube
Frederick Zhang
Updated on September 18, 2022Comments
-
Frederick Zhang over 1 year
I recently found that every time I shutdown/reboot my machine, there will be an logged error which says
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.
I tried to execute the command manually and nothing wrong was found.
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
I tried to use
mkswap
to rebuild the swap partition but it didn't work (I specified UUID so/etc/fstab
is still correct).How can I suppress this error? Thanks in advance.
-
Frederick Zhang almost 8 yearsWow, excellent answer. I was exactly wondering why there were several tries to disable the swap.