🔍 Introduction
When your VPS becomes inaccessible — due to a lost root password, broken network, or a firewall blocking SSH access — it’s often possible to recover it without reinstalling by using Virtualizor’s Shadow Mode.
This mode allows you to mount the VPS disk directly on the host server to access its files and perform repairs (network, password, iptables, CSF, etc.) via the command line.
🧱 Step 1: Mount the VPS Disk in Shadow Mode
Connect to your host server (the physical machine where the VPS is hosted) via SSH, then run the following commands:
modprobe nbd max_part=8
🔸 This command loads the nbd (Network Block Device) module into the Linux kernel.
The max_part=8 option allows each virtual disk to have up to 8 partitions.
This prepares the system to connect a virtual disk (image file) as if it were a physical disk.
💡 If Your Host Server Runs Multiple VPS
The nbd module only needs to be loaded once, but you can connect several VPS disks to different block devices:
# Example: multiple VPS on the same host
modprobe nbd max_part=8 # Load the module (only once)
qemu-nbd --connect=/dev/nbd0 /dev/vz/private/100.raw # VPS ID 100
qemu-nbd --connect=/dev/nbd1 /dev/vz/private/101.raw # VPS ID 101
qemu-nbd --connect=/dev/nbd2 /dev/vz/private/102.raw # VPS ID 102
Each VPS is linked to a separate device:
/dev/nbd0→ VPS 100/dev/nbd1→ VPS 101/dev/nbd2→ VPS 102
By default, Linux creates up to 16 NBD devices (/dev/nbd0 to /dev/nbd15).
If you need more, load the module with:
modprobe nbd max_part=8 nbds_max=32
👉 This step is the starting point to select the correct VPS to repair.
Identify the VPS disk file using:
ls /dev/vz/private/
Connecting the VPS Disk
qemu-nbd --connect=/dev/nbd0 /dev/vz/private/100.raw
🔸 This command uses qemu-nbd to associate a VPS disk file with a block device.
– /dev/nbd0: the created block device
– /dev/vz/private/100.raw: the VPS image file to mount
💡 The path depends on your Virtualizor configuration:
- For KVM VPS:
/var/virtualizor/kvm/<VMID>/ - For OpenVZ:
/dev/vz/private/<VMID>.raw
Replace 100.raw with the file corresponding to the VPS you want to repair.
kpartx -av /dev/nbd0
🔸 Creates access points for the disk partitions (e.g., /dev/mapper/nbd0p1).
mount /dev/mapper/nbd0p1 /mnt
🔸 Mounts the first partition of the VPS to the /mnt directory for access.
mount --bind /dev /mnt/dev
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys
🔸 These commands “bind” the system directories from the host into the VPS chroot so that system tools work properly.
chroot /mnt
🔸 You are now inside the VPS system as if you were directly logged into it.
All subsequent commands will apply to the mounted VPS.
🔐 Step 2: Reset the Root Password
passwd
🔸 Type a new root password and confirm.
This password will let you regain control of the VPS once it’s restarted.
🌐 Step 3: Fix the Network Configuration
If nmcli doesn’t work (often due to a D-Bus error), configure the network manually:
nano /etc/sysconfig/network-scripts/ifcfg-eth0
Add or correct the following lines (adjusting the IPs to your setup):
DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
IPADDR=XXX.XXX.XXX.XXX
NETMASK=255.255.255.0
GATEWAY=XXX.XXX.XXX.1
DNS1=8.8.8.8
DNS2=1.1.1.1
Then, in /etc/resolv.conf:
nameserver 8.8.8.8
nameserver 1.1.1.1
🔥 Step 4: Reset iptables
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT
🔸 These commands clear all existing iptables rules and reopen SSH access (port 22).
You can save the configuration with:
iptables-save > /etc/sysconfig/iptables
🛡️ Step 5: Disable CSF (if installed)
ls /etc/csf/
nano /etc/csf/csf.conf
🔸 If CSF is installed, open the configuration file and enable test mode:
TESTING = "1"
This temporarily disables the firewall.
Also check the csf.allow and csf.deny files to unblock your IP if needed.
🔄 Step 6: Exit the chroot and Restart the VPS
exit
umount /mnt/dev
umount /mnt/proc
umount /mnt/sys
umount /mnt
kpartx -d /dev/nbd0
qemu-nbd --disconnect /dev/nbd0
virsh start v1002
🔸 These commands unmount the disk and restart the VPS (here v1002).
Replace v1002 with your virtual machine’s ID.
✅ Result: VPS Recovered Without Reinstallation
- Root access restored
- Network fixed
- iptables reset
- CSF disabled
- VPS restarted successfully
📦 Nitrohost Bash Capsule
If you need to quickly reset iptables:
iptables -F && iptables -X && iptables -t nat -F && iptables -t nat -X
iptables -P INPUT ACCEPT && iptables -P FORWARD ACCEPT && iptables -P OUTPUT ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT
Written by: Christian Hodari – Nitrohost


