Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

[SOLVED] Swap Error: skipping - it appears to have holes

Linux Kernel, Network, and Services configuration.
Post Reply
Message
Author
bootsie123`
Posts: 10
Joined: 2019-01-02 23:22

[SOLVED] Swap Error: skipping - it appears to have holes

#1 Post by bootsie123` »

Hi. I'm trying to create a swap file with Debian Jessie and I keep running into an error when running
swapon /swap


Here are my steps I'm using to create said swap file

Code: Select all


dd if=/dev/zero of=/var/swap bs=1M count=4096

chmod 600 /var/swap

mkswap /var/swap

swapon /var/swap

I've also tried editing
/etc/fstab
before running
swapon
and that didn't fix the issue either. Any ideas on how I can fix this?
Last edited by bootsie123` on 2019-01-03 11:15, edited 3 times in total.

p.H
Global Moderator
Global Moderator
Posts: 3049
Joined: 2017-09-17 07:12
Has thanked: 5 times
Been thanked: 132 times

Re: Swap Error: skipping - it appears to have holes

#2 Post by p.H »

Do you really need a 4-TB swap file ?
A swap file must not have holes because the kernel needs to map all its blocks to the underlying block device, but the dd command should create a file without holes.
What is the filesystem type for /var ?

Code: Select all

df -hT /var

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 133 times

Re: Swap Error: skipping - it appears to have holes

#3 Post by Head_on_a_Stick »

Code: Select all

fallocate -l 4G /var/swap
^ Quicker than `dd` ;)
deadbang

p.H
Global Moderator
Global Moderator
Posts: 3049
Joined: 2017-09-17 07:12
Has thanked: 5 times
Been thanked: 132 times

Re: Swap Error: skipping - it appears to have holes

#4 Post by p.H »

The OP's dd command creates a 4-TB swap file, not 4-GB.
swapon and mkswap man pages warn against using fallocate on some filesystems (ext4, xfs) because it can create a file with holes.

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 133 times

Re: Swap Error: skipping - it appears to have holes

#5 Post by Head_on_a_Stick »

p.H wrote:The OP's dd command creates a 4-TB swap file, not 4-GB.
Curse my maths :x
swapon and mkswap man pages warn against using fallocate on some filesystems (ext4, xfs) because it can create a file with holes.
But the OP already has holes so perhaps it's worth a try?
deadbang

bootsie123`
Posts: 10
Joined: 2019-01-02 23:22

Re: Swap Error: skipping - it appears to have holes

#6 Post by bootsie123` »

To clear up the confusion. I didn't realize this until you guys said something, but I meant 4GB. Not 4TB. I'm not exactly sure what I was thinking when I wrote that part. The file system I'm using is zfs. I ran fallocate as Head_on_a_Stick suggested and I get
fallocate: fallocate failed: Operation not supported

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 133 times

Re: Swap Error: skipping - it appears to have holes

#7 Post by Head_on_a_Stick »

deadbang

bootsie123`
Posts: 10
Joined: 2019-01-02 23:22

Re: Swap Error: skipping - it appears to have holes

#8 Post by bootsie123` »

There we go. That worked. Thanks!

User avatar
None1975
df -h | participant
df -h | participant
Posts: 1400
Joined: 2015-11-29 18:23
Location: Russia, Kaliningrad
Has thanked: 46 times
Been thanked: 68 times

Re: Swap Error: skipping - it appears to have holes

#9 Post by None1975 »

p.H wrote:The OP's dd command creates a 4-TB swap file, not 4-GB.
I'm curious how much he has RAM ...
OS: Debian 12.4 Bookworm / DE: Enlightenment
Debian Wiki | DontBreakDebian, My config files on github

bootsie123`
Posts: 10
Joined: 2019-01-02 23:22

Re: Swap Error: skipping - it appears to have holes

#10 Post by bootsie123` »

None1975 wrote:
p.H wrote:The OP's dd command creates a 4-TB swap file, not 4-GB.
I'm curious how much he has RAM ...
I made a mistake. It was supposed to be 4GB and not 4TB. Although, I wish I had 4TB of ram. Anyways, hope that clears things up.

p.H
Global Moderator
Global Moderator
Posts: 3049
Joined: 2017-09-17 07:12
Has thanked: 5 times
Been thanked: 132 times

Re: [SOLVED] Swap Error: skipping - it appears to have holes

#11 Post by p.H »

Looks like zfs is another filesystem which does not support Linux swap files, like btrfs and nilfs2.
Linux swap files are broken by design. Do not use them.

Tip : if you really need to create a temporay swap file on an unsupporting filesystem, you can create a loop device with losetup.

Post Reply