Configure Linux CVM to Boot into Single User Mode

Last updated: 2020-03-06 12:17:33

    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.

    1. Log in to the CVM.
    2. Run the following command to open /etc/grub.conf.
      vi /etc/grub.conf
    3. Press i to enter edit mode.
    4. 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.

    5. Press Esc to exit edit mode, enter :wq, and press Enter to
      save your file and exit the VI editor.
    6. Run the following command to reboot the server.
      reboot
    7. Wait for one minute and use VNC to log into your CVM instance, as shown below:
    8. Press any key to enter the menu shown below:
    9. Press e to enter the kernel editing page and enter single, as shown below:
    10. Press Enter, as shown below:
    11. In the interface shown below, press b to enter single user mode.
    12. 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.

    1. Log in to the CVM.
    2. Run the following command to open /etc/default/grub.
      vi /etc/default/grub
    3. Press i to enter edit mode.
    4. 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.

    5. Press Esc to exit edit mode, enter :wq, and press Enter to
      save your file and exit the VI editor.
    6. Run the following command to recompile and generate grub.cfg.
      grub2-mkconfig -o /boot/grub2/grub.cfg
      The following appears:
    7. Run the following command to reboot the server.
      reboot
    8. Wait for one minute and use VNC to log into your CVM instance, as shown below:
    9. Press e to enter the kernel editing interface and add init=/bin/sh to the red box area as shown below:
    10. Press Ctrl+X to start and enter single user mode, as shown below:
    11. 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.

    1. Log in to the CVM.
    2. Run the following command to open /etc/default/grub.
      sudo vi /etc/default/grub
    3. Press i to enter edit mode.
    4. 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.
    5. Press Esc to exit edit mode, enter :wq, and press Enter to
      save your file and exit the VI editor.
    6. Run the following command to recompile and generate grub.cfg.
      sudo update-grub
      The following appears:
    7. Run the following command to reboot the server.
      sudo reboot
    8. Wait for one minute and use VNC to log into your CVM instance, as shown below:
    9. Press e to enter the kernel editing interface and add rw single init=/bin/bash to the red box area as shown below:
    10. Press Ctrl+X to start and enter single user mode, as shown below:

    Was this page helpful?

    Was this page helpful?

    • Not at all
    • Not very helpful
    • Somewhat helpful
    • Very helpful
    • Extremely helpful
    Send Feedback
    Help