Scenario
Linux users sometimes need to boot into single user mode to perform special operations, such as password management or sshd repair. This article describes how to boot into single user mode in common Linux distributions.
Directions
Determining your Linux distribution
Different distributions of Linux use different methods to boot into single user mode, so be sure to follow the instructions for your Linux distribution.
CentOS 6
CentOS 6 uses GRUB. The following process uses CentOS 6.9 as an example. Specific steps may vary slightly depending on the version of the operating system.
- Log in to the CVM.
- Run the following command to open
/etc/grub.conf
.vi /etc/grub.conf
- Press i to enter edit mode.
- Find “GRUB_TIMEOUT”, the waiting time before the default entry is booted, and modify its value based on your needs.
The default value of “GRUB_TIMEOUT” is 5 seconds. In order to avoid missing the boot interface because the waiting time is too short, we recommend you change it to 60s or longer.This setting affects the system start time. After you complete the tasks that require single user mode, change it back to the default value.
- Press Esc to exit edit mode, enter :wq, and press Enter to
save your file and exit the VI editor.
- Run the following command to reboot the server.
reboot
- Wait for one minute and use VNC to log into your CVM instance, as shown below:

- Press any key to enter the menu shown below:

- Press e to enter the kernel editing page and enter single, as shown below:

- Press Enter, as shown below:

- In the interface shown below, press b to enter single user mode.

- Run the following command to exit single user mode.
exec /sbin/init
CentOS 7
Unlike CentOS 6, CentOS 7 and above use GRUB 2. The following process uses CentOS 7.5 as an example. Specific steps may vary slightly depending on the version of the operating system.
- Log in to the CVM.
- Run the following command to open
/etc/default/grub
.vi /etc/default/grub
- Press i to enter edit mode.
- Find “GRUB_TIMEOUT”, the default boot item wait time, and modify its value based on your needs, as shown below:
The default value of “GRUB_TIMEOUT” is 5 seconds. In order to avoid missing the boot interface because the waiting time is too short, we recommend you change it to 60s or longer.This setting affects the system start time. After you complete the tasks that require single user mode, change it back to the default value.

- Press Esc to exit edit mode, enter :wq, and press Enter to
save your file and exit the VI editor.
- Run the following command to recompile and generate
grub.cfg
.grub2-mkconfig -o /boot/grub2/grub.cfg
The following appears:

- Run the following command to reboot the server.
reboot
- Wait for one minute and use VNC to log into your CVM instance, as shown below:

- Press e to enter the kernel editing interface and add init=/bin/sh to the red box area as shown below:

- Press Ctrl+X to start and enter single user mode, as shown below:

- Run the following command to exit single user mode.
exec /sbin/init
Ubuntu
The following process uses Ubuntu 16.04 as an example. Specific steps may vary slightly depending on the version of the operating system.
- Log in to the CVM.
- Run the following command to open
/etc/default/grub
.sudo vi /etc/default/grub
- Press i to enter edit mode.
- Find “GRUB_TIMEOUT”, the default boot item wait time, and modify its value based on your needs, as shown below:
The default value of “GRUB_TIMEOUT” is 5 seconds. In order to avoid missing the boot interface because the waiting time is too short, we recommend you change it to 60s or longer.
- This setting affects the system start time. After you complete the tasks that require single user mode, change it back to the default value.
- The default account in Ubuntu is not
root
. Use sudo
instead.

- Press Esc to exit edit mode, enter :wq, and press Enter to
save your file and exit the VI editor.
- Run the following command to recompile and generate
grub.cfg
.sudo update-grub
The following appears:

- Run the following command to reboot the server.
sudo reboot
- Wait for one minute and use VNC to log into your CVM instance, as shown below:

- Press e to enter the kernel editing interface and add rw single init=/bin/bash to the red box area as shown below:

- Press Ctrl+X to start and enter single user mode, as shown below:

Was this page helpful?