Back to articles
DevOps & Systems

Protect VPS from Ransomware: Read-Only System Configuration with OverlayFS

Detailed guide on configuring a read-only system on VPS using OverlayFS to defend against ransomware, including setup, verification, and troubleshooting steps.

DPTCloud Engineering4 min read
Protect VPS from Ransomware: Read-Only System Configuration with OverlayFS

Image credit: ricardorv30 · Pixabay Content License

Introduction to Protecting VPS from Ransomware with Read-Only Systems

In DevOps environments, Virtual Private Servers (VPS) are frequent targets of ransomware attacks—malicious software that encrypts data and demands payment. A highly effective mitigation strategy is configuring a read-only system, where system directories cannot be modified, even if malware executes with root privileges. OverlayFS is a Linux file system mechanism that enables a read-write layer on top of a read-only base, preserving the integrity of the original system.

This guide walks through deploying OverlayFS on a Linux system (Ubuntu 22.04) to configure a VPS as read-only, preventing ransomware and unwanted changes. This strategy is especially suitable for environments such as web servers, APIs, or services that do not require persistent data writes.

Setting Up OverlayFS on a VPS

OverlayFS operates by combining two directories: a read-only root directory and a read-write directory to store changes. During boot, the system is mounted using OverlayFS, allowing normal operations while ensuring all modifications are confined to the writable layer.

1. Install and Verify OverlayFS

OverlayFS is included in the Linux kernel by default. Verify its availability with:

modprobe overlay
lsmod | grep overlay

If the command returns output, OverlayFS is ready. If not, load the kernel module.

2. Create Directory Structure

Set up the following directories:

  • /root/overlayfs/ro: Read-only root directory.
  • /root/overlayfs/rw: Temporary writable directory.
  • /root/overlayfs/upper: Upper layer (writable).
  • /root/overlayfs/work: Work directory.

Run these commands:

mkdir -p /root/overlayfs/{ro,rw,upper,work}
cp -a /etc /root/overlayfs/ro/
cp -a /usr /root/overlayfs/ro/
cp -a /bin /root/overlayfs/ro/
cp -a /lib /root/overlayfs/ro/
cp -a /lib64 /root/overlayfs/ro/

3. Mount OverlayFS

Use the mount command to attach OverlayFS:

mount -t overlay overlay -o lowerdir=/root/overlayfs/ro,upperdir=/root/overlayfs/upper,workdir=/root/overlayfs/work /root/overlayfs/rw

The /root/overlayfs/rw directory now serves as the mounted read-only system. All changes are stored in /root/overlayfs/upper.

Verification and Troubleshooting

1. Check System Functionality

Run these commands to verify:

df -h
mount | grep overlay

Ensure /root/overlayfs/rw is mounted correctly and has appropriate space.

2. Handle Common Errors

Some common issues include:

  • OverlayFS mount failure: Verify the kernel module is loaded. Run modprobe overlay if missing.
  • Missing upper or work directories: Confirm all directories are created.
  • Permission denied to write to upper directory: Check permissions on /root/overlayfs/upper.

3. Fix Boot-Time Mount Issues

To ensure proper mounting at boot, add this line to /etc/fstab:

overlay /root/overlayfs/rw overlay lowerdir=/root/overlayfs/ro,upperdir=/root/overlayfs/upper,workdir=/root/overlayfs/work 0 0

Then run mount -a to mount all entries in /etc/fstab.

References

Assumptions: This guide assumes the user has root access and is running Ubuntu 22.04. Steps may vary depending on the Linux distribution.

Notes: This strategy does not protect user data. Persistent data should be stored outside the read-only system (e.g., in a separate volume or cloud storage).

Related infrastructure & engineering guides: NVMe Cloud VPS for Docker, Nginx & Databases

DPTCloud Tier III Infrastructure

Recommended NVMe Cloud VPS Plans to Deploy This Setup

Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.

View 22 VPS Plans
ECO · vn-02

VPS-2E

94.600 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 2 GB
  • SSD: 30 GB NVMe
ECO · vn-02Recommended

VPS-3E

170.500 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 4 GB
  • SSD: 50 GB NVMe
BASIC · vn-01Recommended

VPS-05

457.600 ₫ / mo

10% VAT included

  • CPU: 4 vCPU
  • RAM: 8 GB
  • SSD: 50 GB NVMe

Related Articles

View all
ZaloZalo SupportDiscord0384 753 478