Explain in detail how the Linux virtual machine enters single-user mode

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

  1. The FSTAB file is damaged or the configuration is wrong, resulting in the disk drive or partition not being found

  2. Wrong configuration of firewall rules

  3. File system corruption

  4. Problem with SSH configuration

  5. 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

https://docs.microsoft.com/zh-cn/azure/virtual-machines/troubleshooting/serial-console-overview?WT.mc_id=AZ-MVP-5001235

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

Picture 1.png


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.

Picture 2.png



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)

Picture 3.png


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

Picture 4.png

Press ESC to enter the GRUB interface, then E to edit

Picture 5.png


Add at the end of the kernel line (starting on Linux16)

systemd.unit=resuce.target

Picture 6.png


Ctrl+x to exit, you can see that it enters the rescue mode after restarting

Picture 8.png

Requires root password

Picture 9.png


Successfully logged in

Picture 10.png


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.

Picture 11.png

Guess you like

Origin blog.51cto.com/mxyit/2546169