cancel
Showing results for 
Search instead for 
Did you mean: 
TudorRaduta
Community Manager
Community Manager
  • 199 Views

Wednesday Challenge: The OOM Killer Is Loose!

No partition left. No reboot allowed. Now what?

Happy Wednesday! Time for another Problem & Polish scenario, the kind that shows up when everything is on fire and you need to react fast.

Today we tackle a moment many admins dread: the Out of Memory (OOM) Killer stepping in and taking down your application. This related to the objective: "Add new partitions and logical volumes, and swap to a system non-destructively."

The Scenario:

Your app server keeps crashing. The logs show:

Out of memory: Kill process 1234 (java)

You run free -h — and see that Swap is 0B. Nothing was ever configured.

Then you check lsblk and discover the real problem: no free partitions and no space left in the Volume Group. You can’t create a swap partition or an LV. And you can’t reboot.

Your only lifeline: create a Swap File on the running system.

Your Challenge:

You need to create a 1GB Swap File. This requires five commands, in the right order. What are they?

  1. Creation: Which dd command creates /swapfile at exactly 1GB?
  2. Security (critical step): Which chmod command locks it down to 600 so nobody can read memory from disk?
  3. Formatting: What command turns the file into a swap area?
  4. Activation: What enables it immediately without rebooting?
  5. Persistence: What line belongs in /etc/fstab so it stays active after reboot?
  • Bonus: Why is a swap file with world-readable permissions a serious security risk?

Show us how you'd keep the system alive under pressure.

4 Replies
Architect_005
Mission Specialist
Mission Specialist
  • 174 Views

Hi
Below steps to be followed and why swapfile should not be world-readable.

1. Creation: Which dd command creates /swapfile at exactly 1GB?
                    sudo dd if=/dev/zero of=/swapfile bs=1M count=1024
2. Security (critical step): Which chmod command locks it down to 600 so nobody can read memory from disk?
                    sudo chmod 600 /swapfile
3. Formatting: What command turns the file into a swap area?
                    sudo mkswap /swapfile
4. Activation: What enables it immediately without rebooting?
                    sudo swapon /swapfile
5. Persistence: What line belongs in /etc/fstab so it stays active after reboot?
                         /swapfile none swap sw 0 0
Bonus: Why world-readable swap is dangerous
A swap file may contain sensitive memory pages swapped out from RAM:
- Passwords, encryption keys, private data, cached files, or even fragments of secure sessions.
- If the file is world-readable, any user on the system could read raw memory contents, leading to data leaks, privilege escalation, or credential theft.
That’s why chmod 600 is non-negotiable — it locks down access so only root can read/write.

Chetan_Tiwary_
Community Manager
Community Manager
  • 150 Views

1. dd if=/dev/zero of=/swapfile bs=1M count=1024
2. chmod 600 /swapfile
3. mkswap /swapfile
4. swapon /swapfile
5. echo '/swapfile swap swap sw 0 0' >> /etc/fstab

 

It is crucial that the swap file maintains strict permissions, restricted solely to the root user, because if it were readable or writable by all users, it would create a serious security vulnerability. Swap space is essentially a memory overflow area, meaning it can contain remnants of sensitive data that were recently resident in RAM, such as passwords, private keys, session tokens, and application secrets. By limiting access to root only, the system ensures that this memory-dump (which can act as a goldmine for attackers) is shielded from any unprivileged or unauthorized user on the system.

 

Chetan_Tiwary_
Community Manager
Community Manager
  • 150 Views

Also remember that in the fstab entry - mount point does not matter - so it could be anything or it could be swap or none !

https://man7.org/linux/man-pages/man5/fstab.5.html 

Asma-Alfayyad
Flight Engineer
Flight Engineer
  • 131 Views

Hello ,,
The below is the correct commands:

sudo dd if=/dev/zero of=/swaptest bs=1M count=1024
sudo chmod 600 /swaptest
sudo mkswap /swaptest
sudo swapon /swaptest
Add this line to /etc/fstab:
/swaptest none swap sw 0 0

Now why is a swap file with world-readable permissions a serious security risk?

Actually making the swap file readable by everyone would let users access data from RAM, hence the importance of chmod 600.

AsmaAlfayyad_1-1765392001247.png

 

Join the discussion
You must log in to join this conversation.