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

Kernels & Hardware, configuring network, installing services

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

Postby bootsie123` » 2019-01-03 01:09

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.
bootsie123`
 
Posts: 10
Joined: 2019-01-02 23:22

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

Postby p.H » 2019-01-03 09:59

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
p.H
 
Posts: 1010
Joined: 2017-09-17 07:12

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

Postby Head_on_a_Stick » 2019-01-03 10:10

Code: Select all
fallocate -l 4G /var/swap

^ Quicker than `dd` ;)
User avatar
Head_on_a_Stick
 
Posts: 10321
Joined: 2014-06-01 17:46
Location: /dev/chair

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

Postby p.H » 2019-01-03 10:17

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.
p.H
 
Posts: 1010
Joined: 2017-09-17 07:12

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

Postby Head_on_a_Stick » 2019-01-03 10:20

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?
User avatar
Head_on_a_Stick
 
Posts: 10321
Joined: 2014-06-01 17:46
Location: /dev/chair

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

Postby bootsie123` » 2019-01-03 10:38

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
bootsie123`
 
Posts: 10
Joined: 2019-01-02 23:22


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

Postby bootsie123` » 2019-01-03 11:15

There we go. That worked. Thanks!
bootsie123`
 
Posts: 10
Joined: 2019-01-02 23:22

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

Postby None1975 » 2019-01-03 13:27

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 ...
User avatar
None1975
 
Posts: 901
Joined: 2015-11-29 18:23
Location: Lithuania, Vilnius

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

Postby bootsie123` » 2019-01-04 20:17

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.
bootsie123`
 
Posts: 10
Joined: 2019-01-02 23:22

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

Postby p.H » 2019-01-05 11:54

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.
p.H
 
Posts: 1010
Joined: 2017-09-17 07:12


Return to System configuration

Who is online

Users browsing this forum: No registered users and 13 guests

fashionable