Today I will discuss how to enter single-user mode on Linux virtual machines on the cloud. Many people may not have thought that virtual machines on the cloud can still play like this. In fact, it is possible. Of course, when you need to enter single-user mode in general It’s not for playing, but because of some accidents, we can’t enter the system through normal mode. For example, the more common ones include the following scenarios
The FSTAB file is damaged or the configuration is wrong, resulting in the disk drive or partition not being found
Wrong configuration of firewall rules
File system corruption
Problem with SSH configuration
Boot failed
Once these problems occur, we can't connect to the virtual machine through normal ssh, and we can't directly access the server room on the cloud server. At this time, we may be at a loss. In Global Azure, we can use a function of the VM serial console to log in to the system in single-user mode to solve the problem. This function is not currently supported in 21v, but it does not mean that this problem cannot be solved in 21v. If the above problems occur in 21v, we can directly contact support, they have a way to log in to the virtual machine directly at the hyper-v level
To put it simply, the serial console can be connected to the ttyS0 or COM1 serial port of a VM or virtual machine scale set instance to provide users with access rights regardless of its network or operating system status.
Please note that there are several key information we need to pay attention to
1. The serial console is currently not compatible with managed startup diagnostic storage accounts. To use the serial console, make sure you are using a custom storage account.
2. Classic ASM VM is not supported
3. The Azure account using the serial console must have the virtual machine participant role for the VM and startup diagnostic storage account
For detailed information, please refer to the link on the official website
Let’s look at how to do it. The serial console operation needs to be done on Azure Portal, so we must have an azure account.
First click on the virtual machine that needs to enter the single user, and then find the serial console
You can log in with your account password directly here, but it doesn’t make much sense to log in directly here. It’s not as convenient as xshell or putty.
However, because the single-user mode of CentOS requires the root account to be enabled, you can enable the root account here (it doesn’t matter if root is not enabled, there are other ways)
Modify /etc/ssh/sshd_config to ensure that PermitRootLogIn is set to no
Modify /etc/securetty to ensure that root will only log in through ttyS0
If you want to log in as a single user, restart the virtual machine directly in the serial console
Press ESC to enter the GRUB interface, then E to edit
Add at the end of the kernel line (starting on Linux16)
systemd.unit=resuce.target
Ctrl+x to exit, you can see that it enters the rescue mode after restarting
Requires root password
Successfully logged in
But at this time, sshd, etc. are not started, so if you want to access the virtual machine through ssh, you cannot access it. Next, if we have anything that needs to be repaired, we can repair it here.