1

I am trying to create 1GB swap file without success on my Ubuntu 22.04.

I use the following commands:

sudo rm /swapfile1
sudo dd if=/dev/zero of=/swapfile1 bs=1KB count=1MB status=progress
sudo chmod 0600 /swapfile1
sudo mkswap /swapfile1
sudo swapon /swapfile1

The output I get:

905663000 bytes (906 MB, 864 MiB) copied, 5 s, 181 MB/s
1000000+0 records in
1000000+0 records out
1000000000 bytes (1.0 GB, 954 MiB) copied, 5.46825 s, 183 MB/s

Setting up swapspace version 1, size = 953.7 MiB (999993344 bytes)
no label, UUID=4c4c204b-57ff-484d-848b-d719e0260156

swapon: /swapfile1: skipping - it appears to have holes.

Context

When looking at my free space, I see:

$ df /
Filesystem               1K-blocks      Used Available Use% Mounted on
rpool/ROOT/ubuntu_emx73f 879401216 225886848 653514368  26% /

Note that I use the Full Disk Encryption of Ubuntu (not sure if this is relevant)

Also, replacing dd with fallocate does not solve the problem

3
  • 3
    Are you using ZFS file system? Does this help? askubuntu.com/a/1203843/855322
    – FedKad
    May 21, 2023 at 14:49
  • 1
    swap files MUST be contiguous (block N on the physical disk must be followed by block N+1). Did you rm /swapfile before you tried fallocate? It would help us help you if you showed the fallocate command, and its result. Please edit your question to add whatever information you get. Don't use Add Comment, or you'll classify yourself as "Does Not Follow Instructions (DNFI)", and I'll ignore you. I view DNFIs as unhelpable.
    – waltinator
    May 22, 2023 at 13:41
  • Waltinator, your comment is unnecessarily aggressive
    – David Taub
    May 26, 2023 at 21:52

1 Answer 1

1

Credit to FedKad that pointed me to Stratus's answer.

What solved the issue:

sudo zfs create -V 1G -b 8192 -o logbias=throughput -o sync=always -o primarycache=metadata -o com.sun:auto-snapshot=false rpool/swap
sudo mkswap -f /dev/zvol/rpool/swap
sudo swapon /dev/zvol/rpool/swap

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .