var img = document.createElement('img'); img.src = "https://easystat.de/piwik.php?idsite=13&rec=1&url=https://docs.servinga.cloud" + location.pathname; img.style = "border:0"; img.alt = "tracker"; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(img,s);
Skip to main content

Access your server's data in rescue mode

Forgetting your password or misconfiguring your system can make it impossible to access your server. Nearly all providers have a so-called rescue system in place for such situations. This is usually a Linux-based live OS that is booted instead of your usual operating system. In this tutorial, you will learn how to manually mount your operating system's boot disk in a Live Linux in preparation to use it to fix issues such as resetting passwords or correcting misconfigurations.

As Windows and Linux is using different file systems under the hood, the steps depend on which kind of operating system you have installed on your server.

Linux

Mounting the disk

The first step is to create a directory to mount your operating system into.

mkdir /target

To determine the location of your operating system, you can e.g. use lsblk or fdisk -l. Both commands provide you a list of disks and their partitions. If your server only has a single disk, it's usually the largest partition of that disk, but details may vary depending on your exact installation. If in doubt, you can try mounting all partitions until you find the correct one.

After you've identified the correct partition, you can go ahead and mount it into your freshly created mount directory.

mount /dev/sda1 /target
info

If you want to chroot into your installed operating system from the Live Linux, it's highly recommended to also bind the following pseudo-directories into the mount folder. As those directories are populated at runtime, they will be empty unless you manually mount them as well. Some tools might not work correctly within your chroot'ed environment, unless you bind them.

mount --bind /sys /target/sys
mount --bind /dev /target/dev
mount --bind /proc /target/proc

These commands bind essential system directories (/sys, /dev, and /proc) from the host system to the mounted operating system. This allows the mounted OS to access critical data about hardware, processes, and kernel parameters, ensuring proper functionality and interaction with the system.

Accessing your operating system

Once the operating system is mounted, you can either work with the files mounted under /target or perform a chroot to switch into it using the following command. This allows you to run commands that affect your installed operating system as you would have actually booted up the system.

chroot /target

After you're done, in order to leave the chroot environment, simply press CTRL + D or type exit.

Unmounting the disk

In case you've changed any files on your server's disk, it's recommended to safely unmount your Linux system. This process is the reverse of the mounting process, therefore starting with the unmounting of the three pseudo-directories. If you have not mounted those, you can skip over this step.

umount /target/dev
umount /target/sys
umount /target/proc

Once this has been done, you can now remove the actual mount of your disk that holds your data.

unmount /target

Windows

Prerequisites

As Windows installations are using a Microsoft proprietary filesystem called NTFS, in order to mount your NTFS disks in a way you can not only read from them but also write to them, there are two packages that need to be installed before continuing with the mount.

Depending on the exact nature of your rescue system, you might need to use another packet manager. The servinga Cloud Rescue System however is using a Ubuntu-based Live Linux and hence, you can work with apt here.

apt-get update -y
apt install -y fuse
apt install -y ntfs-3g

Mounting the disk

The first step is then to create a directory to mount your operating system into.

mkdir /target

To determine the location of your operating system, you can e.g. use lsblk or fdisk -l. Both commands provide you a list of disks and their partitions. If your server only has a single disk, it's usually the largest partition of that disk, but details may vary depending on your exact installation. If in doubt, you can try mounting all partitions until you find the correct one.

tip

Contrary to Linux, Windows installations tend to have a smaller boot or rescue partition before the actual partition where your operating system and data is being stored on.

$ lsblk
sda 8:0 0 50G
├─sda1 8:1 0 100M
└─sda2 8:2 0 49.9G

In the example above, the disk you want to mount is /dev/sda2 that uses 49.9 GB of the available 50 GB.

After you've identified the correct partition, you can go ahead and mount it into your freshly created mount directory.

mount -t ntfs /dev/sda2 /target/
info

If your server wasn't shut down gracefully you might get the following error message when running the mount command above.

Could not mount read-write, trying read-only

If this error occurs, use the ntfsfix command to resolve it.

ntfsfix /dev/sda2

The ntfsfix command is used to fix minor issues with NTFS filesystems on Linux. It is only necessary when you encounter the error message mentioned above.

Unmounting the disk

For Windows, a single command is all you need to unmount your operating system after you finished working on it. It's recommended to properly unmount the disk, especially if you have altered files on the partition.

umount /target

Exit the rescue system

As rescue systems tend to be Live Linux environments, the easiest way to exit it is by just restarting your server.

reboot