> ## Documentation Index
> Fetch the complete documentation index at: https://help.onetsolutions.net/llms.txt
> Use this file to discover all available pages before exploring further.

# Activate Memory Hotplug

> Enable dynamic memory management on your VPS

Memory hotplug allows you to dynamically add or remove memory from a running virtual machine without requiring a reboot.

<Info>
  **Prerequisites**

  * A VPS with OnetSolutions
  * Root or sudo access
</Info>

## Configuration Steps

<Steps>
  <Step title="Create udev rule file">
    Navigate to the udev rules directory:

    ```bash theme={null}
    cd /etc/udev/rules.d/
    ```
  </Step>

  <Step title="Create the hotplug rule">
    Create and edit the rule file:

    ```bash theme={null}
    sudo nano 99-hotplug-cpu-mem.rules
    ```
  </Step>

  <Step title="Add the hotplug rules">
    Add the following content:

    ```text theme={null}
    SUBSYSTEM=="memory", ACTION=="add", TEST=="state", ATTR{state}=="offline", ATTR{state}="online"
    SUBSYSTEM=="cpu", ACTION=="add", TEST=="online", ATTR{online}=="0", ATTR{online}="1"
    ```
  </Step>

  <Step title="Save and exit">
    Save the file and exit the editor.
  </Step>

  <Step title="Reload udev rules">
    ```bash theme={null}
    sudo udevadm control --reload
    ```
  </Step>
</Steps>

## Activate Existing Resources

Run this script to bring online any currently offline CPU and memory:

```bash theme={null}
#!/bin/bash

# Bring CPUs online
for CPU_DIR in /sys/devices/system/cpu/cpu[0-9]*; do
    CPU_STATE_FILE="${CPU_DIR}/online"
    if [ -f "${CPU_STATE_FILE}" ]; then
        if grep -qx 0 "${CPU_STATE_FILE}"; then
            echo 1 > "${CPU_STATE_FILE}"
        fi
    fi
done

# Bring Memory online
for RAM in $(grep offline /sys/devices/system/memory/*/state 2>/dev/null); do
    echo online > "$(echo $RAM | sed 's/:offline$//')"
done
```

<Note>
  After setting up the udev rules, any future memory or CPU additions will be automatically brought online.
</Note>
