Solved: Error with swapon: swapon failed: Invalid argument.

Today in this article, we will look at an interesting issue where we are getting error while adding new swap.

 

I. Issue/Error Message

bash-4.2$ sudo swapon -a
swapon: /oracle/swapfile: swapon failed: Invalid argument

 

II. Analysis
Such error message says that the swapfile or swap disk is not identified as a valid swap area by default.

Lets check out the error message.

bash-4.2$ tail -50f /var/log/messages
Apr 21 05:42:13 ngelinux001 kernel: swapon: swapfile has holes

 

III. Solution
We can resolve this issue by deleting old swap file /oracle/swapfile and create new one and then re-formatting it as swap.

bash-4.2$ sudo dd if=/dev/zero of=/oracle/swapfile bs=1M count=4100 status=progress
Apr 21 05:47:42 ngelinux001 sudo: user : TTY=pts/5 ; PWD=/oracle ; USER=root ; COMMAND=/usr/bin/dd if=/dev/zero of=/oracle/swapfile bs=1M count=4100 status=progress
3381657600 bytes (3.4 GB) copied, 4.001839 s, 845 MB/s
4100+0 records in
4100+0 records out
4299161600 bytes (4.3 GB) copied, 4.84931 s, 887 MB/s
bash-4.2$

bash-4.2$ sudo mkswap /oracle/swapfile
Apr 21 05:51:02 ngelinux001 sudo: user : TTY=pts/5 ; PWD=/var/log ; USER=root ; COMMAND=/usr/sbin/mkswap /oracle/swapfile
Setting up swapspace version 1, size = 4198396 KiB
no label, UUID=43ebe7a2-3844-4da4-aaa7-3ed0b5a7f6f0

bash-4.2$ swapon -a
Apr 21 05:51:14 ngelinux001 sudo: user : TTY=pts/5 ; PWD=/var/log ; USER=root ; COMMAND=/usr/sbin/swapon -a
Apr 21 05:51:14 ngelinux001 kernel: Adding 4198396k swap on /oracle/swapfile. Priority:-2 extents:2 across:4328472k FS

As we can see above by creating the swapfile again via dd command and then turning it on, resolved the issue.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments