Chimu
1
While using this page Linux Add a Swap File Tutorial - nixCraft I get the error when I type swapon command:
swapon /swapfile
swapon: /swapfile: read swap header failed
How do I fix " read swap header failed " error and make swap file on Linux machine?
You forget to run the mkswap command to set up a Linux swap area.
mkswap syntax
The syntax is
sudo mkswap /path/to/file
sudo mkswap /dev/DEVICE_NAME
To fix “swapon: /swapfile: read swap header failed” error” on Linux run:
Step 1: First, use the dd command to make 4GiB swap file named /swap.file1:
sudo dd if=/dev/zero of=/swap.file1 bs=1MiB count=$((4*1024)) status=progress
Here is what you will see
[sudo] password for vivek:
3334471680 bytes (3.3 GB, 3.1 GiB) copied, 3 s, 1.1 GB/s
4096+0 records in
4096+0 records out
4294967296 bytes (4.3 GB, 4.0 GiB) copied, 3.98239 s, 1.1 GB/s
Step 2: Set permissions to avoid “mkswap: /swap.file1: insecure permissions 0644, 0600 suggested” warning:
sudo chmod -v 0600 /swap.file1
Outputs:
mode of '/swap.file1' changed from 0644 (rw-r--r--) to 0600 (rw-------)
Step 3: Set up swap area:
sudo mkswap /swap.file1
Outputs:
Setting up swapspace version 1, size = 4 GiB (4294963200 bytes)
no label, UUID=6ce70fe5-53c3-4c02-9f7e-a768d9e53add
Step 4: That is all, turn it on swap space and verify it:
sudo swapon /swap.file1
Verify it:
swapon -s
top
htop
1 Like