1

I have created a swapfile successfully, but when I am trying to:

"sudo swapon /swapfile" 

this is what I see:

"swapon: /swapfile1: skipping"

It appears to have holes.

How can I create a swapfile that doesn't have a hole?

Pilot6
  • 88,764
  • 91
  • 205
  • 313
  • 2
    So how exactly did you create the swapfile? – steeldriver Jan 31 '23 at 21:43
  • @steeldriver: Some people have had a problem with holes when using fallocate to create swapfiles. https://askubuntu.com/a/1285218/43926 `sudo fallocate -l XG /swapfile` – C.S.Cameron Feb 03 '23 at 09:28
  • @C.S.Cameron hence my question ;) – steeldriver Feb 03 '23 at 12:30
  • @steeldriver: I only know of two methods to create a swapfile, one is `fallocate` the other is `dd`. `Fallocate` is known to occasionally create holes, `dd` is not. The method using fallocate is given above in my comment, and the method using dd is given in my answer below. Do you have a preferred method to create swapfiles not mentioned? The OP has not confirmed their method. – C.S.Cameron Feb 03 '23 at 13:55
  • @C.S.Cameron I know far less about it than you - I've upvoted your answer, but unless the OP engages we're spinning our wheels – steeldriver Feb 03 '23 at 14:00

1 Answers1

2

Swapfile Holes

There is a slight possibility of getting holes in a swapfile when creating it with fallocate.

/var/log/syslog can be searched for the phrase swapon: swapfile has holes to ensure there will be no data loss.

A swap file can alternatively be created using dd:

sudo dd if=/dev/zero of=/swapfile bs=1G count=8

An error when using dd may overwrite your HDD.

C.S.Cameron
  • 18,890
  • 10
  • 64
  • 105
  • 1
    I am still having the same problem, i tried using both fallocate and dd ...... still getting the error saying there is holes – Nathan Nyawaya Feb 05 '23 at 22:46