Skip to main content

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.

Memory hotplug allows you to dynamically add or remove memory from a running virtual machine without requiring a reboot.
Prerequisites
  • A VPS with OnetSolutions
  • Root or sudo access

Configuration Steps

1

Create udev rule file

Navigate to the udev rules directory:
cd /etc/udev/rules.d/
2

Create the hotplug rule

Create and edit the rule file:
sudo nano 99-hotplug-cpu-mem.rules
3

Add the hotplug rules

Add the following content:
SUBSYSTEM=="memory", ACTION=="add", TEST=="state", ATTR{state}=="offline", ATTR{state}="online"
SUBSYSTEM=="cpu", ACTION=="add", TEST=="online", ATTR{online}=="0", ATTR{online}="1"
4

Save and exit

Save the file and exit the editor.
5

Reload udev rules

sudo udevadm control --reload

Activate Existing Resources

Run this script to bring online any currently offline CPU and memory:
#!/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
After setting up the udev rules, any future memory or CPU additions will be automatically brought online.