Unlock GRUB and Single-User Mode in Azure VMs with Serial Console

Table of Contents

Unlock GRUB and Single-User Mode in Azure VMs with Serial Console

The GRand Unified Bootloader (GRUB) is the foundational software that initiates the boot process of a virtual machine (VM). It is typically the first interface you encounter when starting your VM, appearing before the operating system fully loads. GRUB’s pre-OS environment means standard access methods like SSH are unavailable for interaction. Within GRUB, users possess the capability to alter boot configurations, including booting into single-user mode, which is crucial for system maintenance and recovery.

Single-user mode provides a stripped-down environment, offering minimal functionalities. This mode is invaluable for diagnosing and resolving boot failures, file system inconsistencies, or network connectivity problems. With a reduced set of background services and potentially unmounted file systems depending on the runlevel, single-user mode offers a focused environment for system repair. Furthermore, single-user mode becomes particularly useful when VMs are secured to accept only SSH key-based logins. In such scenarios, it can be leveraged to establish an account with password authentication, providing an alternative access route.

It is important to note that accessing the Serial Console, which is essential for interacting with GRUB and single-user mode, requires appropriate Azure permissions. Only users with contributor-level permissions or higher are authorized to utilize the serial console functionality of a VM. To access single-user mode, the process generally involves entering GRUB during the VM’s boot sequence and modifying the boot configuration from within GRUB. Detailed steps for accessing GRUB are provided in the subsequent sections. In most configurations where GRUB is enabled, initiating a restart from the VM’s serial console interface will typically present the GRUB menu upon reboot.

General GRUB Access

General GRUB Access

To gain access to GRUB, the initial step is to reboot your virtual machine while actively monitoring the Serial Console pane in the Azure portal. The behavior of GRUB display varies across different Linux distributions. Some distributions are configured to require keyboard input to trigger the GRUB menu display, while others are set to automatically show GRUB for a brief period. This automatic display allows a short window for user intervention via keyboard input to interrupt the timeout and access the GRUB menu.

For the purpose of accessing single-user mode or performing boot-level configurations, ensuring that GRUB is enabled on your VM is paramount. Depending on the specific Linux distribution your VM is running, certain preliminary setup steps might be necessary to guarantee GRUB is active and accessible. Distribution-specific guidelines for enabling and accessing GRUB are detailed in the sections that follow, providing tailored instructions for various Linux environments.

Restarting Your VM to Access GRUB in Serial Console

Restarting Your VM to Access GRUB in Serial Console

Initiating a VM restart directly from the Serial Console is a straightforward process. Within the Serial Console interface, locate and hover over the Restart button. Upon hovering, you will see an option to Restart VM. Selecting this option will trigger a VM reboot. Confirmation of the restart action is typically indicated by a notification message displayed at the bottom of the Serial Console pane.

Alternatively, for VMs where SysRq functionality is enabled, a restart can also be initiated by sending a SysRq “b” command. SysRq, or System Request, is a powerful kernel feature that allows for low-level commands to be sent directly to the kernel. For more information regarding SysRq and its capabilities in conjunction with Serial Console, you can refer to the documentation on Serial Console NMI and SysRq. Understanding the expected GRUB behavior during a reboot is crucial for successful access. Therefore, it is recommended to consult the distribution-specific instructions provided in the subsequent sections, as these will outline the precise steps and expected outcomes for accessing GRUB on different Linux distributions.

General Single-User Mode Access

General Single-User Mode Access

Manual entry into single-user mode might be necessary in scenarios where a password-authenticated account has not been pre-configured on the virtual machine. In such cases, modifying the GRUB configuration becomes the primary method to access single-user mode. This involves interrupting the normal boot process through GRUB and instructing the system to boot into a minimal, single-user environment. Once in single-user mode, you can proceed with tasks such as resetting forgotten passwords or creating new user accounts. Refer to the subsequent section titled “Use single-user mode to reset or add a password” for detailed instructions on these post-access procedures.

In situations where a VM encounters critical boot failures, many Linux distributions are designed to automatically transition into single-user mode or emergency mode. This automated transition serves as a built-in recovery mechanism, providing a console environment for diagnosing and rectifying the boot issues. However, it’s important to note that the automatic fallback to single-user or emergency mode is not universally configured across all distributions. Some distributions require specific pre-configurations, such as setting up a root password, before they can automatically drop into these recovery modes. Therefore, understanding the specific behavior of your Linux distribution in boot failure scenarios is crucial for effective system recovery.

Use Single-User Mode to Reset or Add a Password

Use Single-User Mode to Reset or Add a Password

Once you have successfully booted your virtual machine into single-user mode, you can perform administrative tasks such as adding a new user account with sudo privileges. This is particularly useful for regaining access to a system where administrative credentials might be lost or inaccessible. The process for adding a user with sudo privileges within single-user mode involves a series of command-line operations.

  1. Add a new user: Execute the command useradd <username>, replacing <username> with the desired username for the new account. This command creates a new user account on the system.
  2. Grant sudo privileges: To grant the newly created user root-level administrative privileges, run the command sudo usermod -a -G sudo <username>. This command adds the user to the sudo group, which confers the ability to execute commands with superuser privileges.
  3. Set the user password: Finally, to set a password for the new user, use the command passwd <username>. You will be prompted to enter and confirm the new password. After successfully setting the password, you can then log into the VM using the newly created user account and password.

Access for Red Hat Enterprise Linux (RHEL)

Red Hat Enterprise Linux (RHEL)

Red Hat Enterprise Linux (RHEL) is designed to automatically initiate single-user mode if it encounters issues during the normal boot process. This feature is intended to provide a recovery environment for system administrators to diagnose and resolve boot-related problems. However, a critical aspect of RHEL’s single-user mode configuration is the requirement for root access to be properly set up beforehand. If root access is not configured, specifically if a root password has not been established, you will be unable to sign in to single-user mode, even if the system successfully enters it.

While workarounds exist to address this situation, such as the manual single-user mode entry method described later, it is strongly recommended to proactively set up root access. Configuring root access in advance ensures a smoother and more efficient recovery process should single-user mode be required. This initial setup involves enabling the root user and setting a strong root password, which will be necessary for authentication when accessing single-user mode.

GRUB Access in RHEL

GRUB Access in RHEL

Red Hat Enterprise Linux (RHEL) distributions come with GRUB pre-enabled by default. This out-of-the-box configuration simplifies the process of accessing GRUB for boot configuration modifications or troubleshooting. To enter the GRUB menu on a RHEL VM, the procedure is relatively straightforward. Begin by rebooting the VM. This can be done by executing the command sudo reboot from within a terminal session if you have SSH access, or by using the restart option in the Azure portal. Immediately after initiating the reboot, and while the system is restarting, press any key on your keyboard. This key press action signals GRUB to interrupt the normal boot sequence and display the GRUB menu.

If, for any reason, the GRUB menu does not appear upon reboot and key press, it is essential to verify the GRUB configuration file. The primary GRUB configuration file in RHEL is located at /etc/default/grub. Ensure that the following lines are present and correctly configured within this file, as they are crucial for enabling GRUB access via the serial console, especially in Azure environments:

For RHEL 8:

GRUB_TIMEOUT=5
GRUB_TERMINAL="serial console"
GRUB_CMDLINE_LINUX="console=tty1 console=ttyS0 earlyprintk=ttyS0"

For RHEL 7:

GRUB_TIMEOUT=5
GRUB_TERMINAL_OUTPUT="serial console"
GRUB_CMDLINE_LINUX="console=tty1 console=ttyS0,115200n8 earlyprintk=ttyS0,115200 net.ifnames=0"

These configurations specify a 5-second timeout for the GRUB menu, designate the serial console as the terminal for GRUB output, and configure the Linux kernel command line to utilize both tty1 and ttyS0 (serial port 0) for console output, which is essential for serial console access in Azure.

Set Up Root Access for Single-User Mode in RHEL

Set Up Root Access for Single-User Mode in RHEL

By default, in Red Hat Enterprise Linux (RHEL), the root user account is deliberately disabled as a security measure. However, accessing single-user mode in RHEL necessitates that the root user account be enabled. This is because single-user mode traditionally requires root privileges for system administration and recovery tasks. Therefore, if you anticipate needing to use single-user mode for system maintenance or troubleshooting, it is crucial to enable root access proactively. The following steps outline the procedure to enable root access for single-user mode in RHEL:

  1. SSH Login: Establish a secure shell (SSH) connection to your Red Hat system. This requires that SSH service is running and accessible, and that you have valid credentials for a user account with sudo privileges.
  2. Switch to Root: Once logged in via SSH, switch to the root user. This is typically done by using the command sudo su - or sudo -i. You may be prompted to enter the password of the current user with sudo privileges to proceed.
  3. Enable Root Password: Enable the password for the root user account. This is achieved by running the command passwd root. You will be prompted to set a new password for the root user. It is imperative to choose a strong, complex password to maintain system security.
  4. Restrict Root Login to ttyS0: For enhanced security, it is recommended to restrict root user logins to only the serial console (ttyS0). This limits potential remote access via root account through SSH. To enforce this restriction:
    a. Edit the SSH daemon configuration file: Open the /etc/ssh/sshd_config file using a text editor such as vi or nano. Locate the line PermitRootLogin. Ensure that this line is set to no. If the line is commented out (preceded by a #), uncomment it and set its value to no. This setting disables direct root login via SSH.
    b. Configure secure tty: Edit the /etc/securetty file. This file lists the TTY devices that are allowed for root logins. Ensure that only ttyS0 is listed in this file. Remove any other tty entries if you want to strictly limit root login to the serial console.

After completing these steps, if the RHEL system boots into single-user mode, you will be able to sign in using the root password that you have just created. This setup ensures that root access is enabled for recovery purposes while maintaining a secure configuration by disabling direct root SSH logins and potentially restricting root logins to the serial console.

Alternatively, for RHEL versions 7.4 and later, as well as 6.9 and later, there is another method to enable single-user mode directly from the GRUB prompts. This method is documented in Red Hat’s official documentation under “Booting into single-user mode”. This documentation provides specific instructions for modifying the GRUB boot parameters to initiate single-user mode.

Manually Enter Single-User Mode in RHEL

Manually Enter Single-User Mode in RHEL

If you have already configured GRUB and enabled root access following the previously outlined instructions for Red Hat Enterprise Linux (RHEL), you can manually initiate a boot into single-user mode through GRUB. This manual method allows you to deliberately enter single-user mode for maintenance or troubleshooting purposes. The steps to manually enter single-user mode are as follows:

  1. Access GRUB: Start by accessing the GRUB menu. During the VM restart process, as soon as the system begins to boot, press the Esc key repeatedly. This action should interrupt the normal boot sequence and bring up the GRUB menu.
  2. Edit Boot Entry: In the GRUB menu, navigate to and select the operating system entry that you wish to boot into single-user mode. Typically, the default OS is listed on the first line. Once selected, press the E key on your keyboard. This will open the GRUB edit menu, allowing you to modify the boot parameters for the selected OS entry.
  3. Locate Kernel Line: Within the GRUB edit menu, find the line that specifies the Linux kernel to be loaded. In Azure environments, this line usually begins with either linux or linux16. This line contains the kernel path and various boot parameters.
  4. Go to End of Line: Position the cursor at the very end of the kernel line. A convenient shortcut to quickly reach the end of a line in many text editors and consoles, including GRUB edit mode, is to press Ctrl+E (hold down the Ctrl key and press E).
  5. Add Systemd Target Parameter: At the end of the kernel line, append the parameter systemd.unit=rescue.target. Ensure that you add a space before this parameter to separate it from the preceding boot parameters. This parameter instructs the systemd init system to boot into the rescue.target, which corresponds to single-user mode. If you intend to boot into emergency mode instead, you would append systemd.unit=emergency.target at this step.
  6. Boot with Modified Settings: After adding the systemd.unit=rescue.target parameter (or systemd.unit=emergency.target for emergency mode), press Ctrl+X to exit the GRUB edit menu and initiate the boot process with the modified settings. This action will cause the system to reboot and boot directly into the specified target mode (single-user or emergency mode).

Upon booting into single-user mode using this manual method, you will typically be prompted to enter the administrator password before gaining access to the single-user mode shell. This password prompt is for the root password that you should have set up as per the previous instructions for enabling root access for single-user mode in RHEL.

Enter Single-User Mode Without Root Account Enabled in RHEL

Enter Single-User Mode Without Root Account Enabled in RHEL

If you find yourself in a situation where the root user account was not enabled following the earlier recommended procedures for Red Hat Enterprise Linux (RHEL), it is still possible to reset the root password and gain access to the system. This can be achieved by interrupting the boot process at a very early stage and gaining access to a shell environment with root privileges, albeit in a limited context. The steps to reset the root password when the root account is not enabled are as follows:

  1. Access GRUB: Initiate the process by accessing the GRUB menu. During the VM restart, press the Esc key as the VM starts booting. This should bring up the GRUB menu, allowing you to interrupt the normal boot sequence.
  2. Edit Boot Entry: In the GRUB menu, select the operating system entry you wish to modify, usually the first one listed. Press the E key to enter the GRUB edit mode for this entry.
  3. Locate Kernel Line: Find the kernel line within the GRUB edit menu. In Azure RHEL VMs, this line typically starts with linux16. This line specifies the kernel and its boot parameters.
  4. Add rd.break Parameter: Append the parameter rd.break to the end of the kernel line. Ensure there is a space separating rd.break from the preceding parameters. The rd.break parameter is a special boot option that instructs the boot process to interrupt just before control is handed over from initramfs to systemd. This interruption occurs in the initial RAM file system (initramfs) environment, as detailed in Red Hat’s documentation on root password reset.
  5. Boot with Modified Settings: Press Ctrl+X to exit the GRUB edit menu and boot the system with the newly added rd.break parameter. This will cause the system to reboot and halt the boot process at the specified breakpoint within the initramfs environment.
  6. Remount Root Filesystem Read-Write: After rebooting with rd.break, you will be dropped into an emergency shell environment. Initially, the root file system is mounted as read-only. To make changes, you need to remount it with read-write permissions. Execute the command mount -o remount,rw /sysroot. This command remounts the root file system, making it writable.
  7. Chroot into sysroot Jail: To perform system administration tasks on the actual root file system, you need to change the root directory to /sysroot. Use the command chroot /sysroot. This command changes the root directory to /sysroot, effectively placing you in the system’s root environment.
  8. Troubleshooting and Password Reset: You are now operating within the system’s root environment. From here, you can proceed with troubleshooting system issues or, in this case, resetting the root password. Use the passwd root command to set a new root password.
  9. SELinux Relabeling (RHEL): In RHEL systems with SELinux enforcing mode enabled, any changes made to file permissions or security contexts might be affected by SELinux policies. To ensure proper system operation after password changes, it is advisable to relabel the file system. Run the command touch /.autorelabel. This command creates a hidden file named .autorelabel in the root directory. Upon the next reboot, SELinux will automatically perform a full file system relabeling, ensuring consistency and correct security contexts.
  10. Reboot the System: Once you have completed the necessary troubleshooting or password reset tasks, reboot the system. Use the command reboot -f to force an immediate reboot. The -f flag is used to ensure a clean reboot in this emergency scenario.

Following these steps allows you to gain access to your RHEL system even when the root account was not initially enabled, enabling you to reset the root password and regain administrative control.

Access for CentOS

CentOS

Similar to Red Hat Enterprise Linux, CentOS’s single-user mode functionality relies on both GRUB being enabled and the root user account being properly configured. The underlying architecture and system management tools are largely consistent between CentOS and RHEL, especially for versions derived from the same upstream sources. Therefore, the procedures for accessing and utilizing single-user mode in CentOS closely mirror those for RHEL.

GRUB Access in CentOS

GRUB Access in CentOS

CentOS, like its upstream counterpart RHEL, comes with GRUB enabled by default in its standard installation. This pre-enabled GRUB simplifies the process of accessing the bootloader menu for system recovery or configuration adjustments. To access the GRUB menu on a CentOS virtual machine, the procedure is straightforward. Initiate a reboot of your CentOS VM. This can be done by executing sudo reboot from a terminal session if you have SSH access, or by using the restart function available in the Azure portal for your VM. Immediately following the initiation of the reboot, and as the system starts to restart, press any key on your keyboard. This key press signals GRUB to interrupt the normal boot sequence and display the GRUB menu.

Single-User Mode in CentOS

Single-User Mode in CentOS

To enable and configure single-user mode in CentOS, the recommended approach is to follow the same detailed instructions provided earlier for Red Hat Enterprise Linux (RHEL). Given the architectural similarities and shared heritage between CentOS and RHEL, the configuration steps for root access, GRUB settings, and manual single-user mode entry are largely identical. This consistency ensures that system administrators familiar with RHEL can readily apply their knowledge and procedures to CentOS environments for system recovery and maintenance tasks involving single-user mode.

Access for Ubuntu

Ubuntu

Ubuntu images are designed with a different security philosophy compared to RHEL and CentOS when it comes to the root user and single-user mode. Notably, Ubuntu images typically do not require a root password to be set. This design choice simplifies access to single-user mode in emergency scenarios. If an Ubuntu system boots into single-user mode, it can generally be used directly without the need for additional authentication credentials. This streamlined access can be advantageous for quick system recovery and troubleshooting.

GRUB Access in Ubuntu

GRUB Access in Ubuntu

Accessing the GRUB menu on Ubuntu virtual machines requires a slightly different approach compared to RHEL or CentOS. To bring up the GRUB menu during boot, you need to press and hold the Esc key while the VM is in the process of booting up. Holding down the Esc key from the early stages of the boot process is crucial to ensure that GRUB is invoked and the menu is displayed.

By default, Ubuntu images might be configured not to automatically display the GRUB menu during every boot. This default behavior is often set to provide a cleaner boot experience under normal circumstances. However, for troubleshooting or system recovery purposes, it is often necessary to access GRUB. To modify this default behavior and ensure that the GRUB menu is displayed, you can adjust the GRUB configuration settings. The following steps outline how to configure Ubuntu to consistently show the GRUB menu:

  1. Edit 50-cloudimg-settings.cfg: Open the file /etc/default/grub.d/50-cloudimg-settings.cfg in a text editor with root privileges (e.g., using sudo nano /etc/default/grub.d/50-cloudimg-settings.cfg). This file often contains cloud-specific GRUB settings in Ubuntu cloud images.
  2. Modify GRUB_TIMEOUT: Locate the line that defines GRUB_TIMEOUT. Change the value of GRUB_TIMEOUT to a non-zero value. A value like 10 (seconds) is commonly used, providing a 10-second window to interact with the GRUB menu. If the line is commented out (starts with #), uncomment it and then set the value.
  3. Edit /etc/default/grub: Open the main GRUB configuration file, /etc/default/grub, in a text editor with root privileges (e.g., sudo nano /etc/default/grub).
  4. Comment out GRUB_HIDDEN_TIMEOUT: Find the line GRUB_HIDDEN_TIMEOUT=1. Comment out this line by adding a # at the beginning of the line, so it becomes #GRUB_HIDDEN_TIMEOUT=1. This setting, when active, can hide the GRUB menu and proceed directly to booting the default OS after a timeout. Commenting it out disables this behavior.
  5. Ensure GRUB_TIMEOUT_STYLE=menu: Verify that there is a line GRUB_TIMEOUT_STYLE=menu. If this line is not present, add it. If it is set to a different value (like hidden), change it to menu. Setting GRUB_TIMEOUT_STYLE=menu explicitly tells GRUB to display the menu instead of a countdown timer or hiding the menu.
  6. Update GRUB Configuration: After making these changes to the GRUB configuration files, it is essential to update the GRUB boot configuration. Run the command sudo update-grub. This command regenerates the GRUB configuration files based on the settings in /etc/default/grub and /etc/default/grub.d/*, applying your changes to the bootloader.

After performing these steps and rebooting your Ubuntu VM, the GRUB menu should be consistently displayed during the boot process, allowing you to select boot options or enter single-user mode as needed.

Single-User Mode in Ubuntu

Single-User Mode in Ubuntu

Ubuntu’s behavior in handling boot failures is designed to be user-friendly for system recovery. If an Ubuntu system encounters issues that prevent it from booting normally, it is configured to automatically drop into single-user mode. This automatic transition provides a built-in recovery mechanism, allowing administrators to access a minimal environment for diagnosing and resolving boot problems without manual intervention in GRUB.

To manually initiate single-user mode in Ubuntu, even when the system is booting normally, you can modify the boot parameters through GRUB. This manual method is useful when you need to enter single-user mode for maintenance tasks or troubleshooting. The steps to manually enter single-user mode in Ubuntu are as follows:

  1. Access GRUB: First, access the GRUB menu by pressing and holding the Esc key during the VM boot process, as described in the previous section on GRUB access in Ubuntu.
  2. Edit Boot Entry: In the GRUB menu, select the boot entry for Ubuntu (usually the default entry). Press the E key to edit the boot entry’s parameters.
  3. Locate Kernel Line and ro Parameter: Within the GRUB edit screen, find the line that starts with linux. On this line, look for the parameter ro. The ro parameter stands for “read-only,” indicating that the root file system is initially mounted in read-only mode during boot.
  4. Add single Parameter: After the ro parameter, add the word single. Ensure that there is a space both before and after the word single to properly separate it from other boot parameters. Adding single instructs the system to boot into single-user mode.
  5. Boot with Modified Settings: Press Ctrl+X to exit the GRUB edit screen and initiate the boot process with these modified settings. The system will now boot directly into single-user mode.

Use GRUB to Invoke Bash in Ubuntu

Use GRUB to Invoke Bash in Ubuntu

In certain challenging situations, such as when dealing with a forgotten root password or other issues that prevent access to single-user mode through the standard methods in Ubuntu, there is an alternative approach. You can instruct the kernel to execute /bin/bash as the init process instead of the regular system initialization process (systemd or init). This method provides a direct bash shell environment with root privileges, which can be invaluable for system maintenance and recovery operations. This approach bypasses the normal system startup sequence, giving you immediate command-line access. The steps to use GRUB to invoke bash in Ubuntu are as follows:

  1. Access GRUB: Begin by accessing the GRUB menu. Press and hold the Esc key while the Ubuntu VM is booting to bring up the GRUB menu.
  2. Edit Boot Entry: Select the Ubuntu boot entry from the GRUB menu and press the E key to edit its boot parameters.
  3. Locate Kernel Line and ro Parameter: Find the kernel line (starting with linux) and locate the ro parameter within it.
  4. Replace ro with rw init=/bin/bash: Replace the ro parameter with rw init=/bin/bash. Make sure there is a space before rw and after bash. The rw parameter mounts the root file system in read-write mode, and init=/bin/bash specifies that /bin/bash should be used as the init process. This effectively replaces the standard init system with a bash shell.
  5. Boot with Modified Settings: Press Ctrl+X to exit the GRUB edit screen and boot the system with these modified settings. The system will now boot directly into a bash shell environment.

After booting with these settings, you will be presented with a bash prompt running as root. From this bash shell, you can perform a wide range of system maintenance tasks, including password resets, file system repairs, and other administrative operations. Remember that this method bypasses the normal system initialization, so services and daemons will not be started. Once you have completed your tasks, you will typically need to manually reboot the system to return to normal operation.

Access for CoreOS

CoreOS

Single-user mode in CoreOS, like in some other Linux distributions, is contingent upon GRUB being enabled and accessible. CoreOS, designed for containerized environments and automatic updates, has its own specific approach to system recovery and maintenance.

GRUB Access in CoreOS

GRUB Access in CoreOS

To access the GRUB menu in a CoreOS virtual machine, the process is quite simple. During the VM’s boot sequence, press any key on your keyboard. This key press will interrupt the automatic boot process and display the GRUB menu. This straightforward method ensures that you can access GRUB for boot option modifications or troubleshooting when needed.

Single-User Mode in CoreOS

Single-User Mode in CoreOS

CoreOS is designed to automatically enter single-user mode if it encounters issues that prevent a normal boot. This automatic fallback mechanism is intended to provide a recovery environment for system administrators. In addition to this automatic behavior, you can also manually initiate single-user mode in CoreOS through GRUB for maintenance or diagnostic purposes. The steps to manually enter single-user mode in CoreOS are as follows:

  1. Access GRUB: Access the GRUB menu by pressing any key during the VM boot process.
  2. Edit Boot Entry: In the GRUB menu, select the boot entry you wish to modify and press the E key to enter edit mode.
  3. Locate Kernel Line: Find the line that starts with linux$. In CoreOS GRUB configurations, there are typically two instances of such lines, each encapsulated within different if...else clauses. You need to modify both instances.
  4. Append coreos.autologin=ttyS0: Append the parameter coreos.autologin=ttyS0 to the end of each linux$ line. This parameter is specific to CoreOS and instructs the system to automatically log in to the console (ttyS0, the serial console) as the coreos user upon booting into single-user mode.
  5. Boot with Modified Settings: Press Ctrl+X to exit the GRUB edit screen and boot the system with these modified settings. CoreOS will now boot into single-user mode, and you will be automatically logged in as the coreos user on the serial console.

Access for SUSE SLES

SUSE SLES

Newer images of SUSE Linux Enterprise Server (SLES) 12 SP3 and later versions are configured to allow access via the serial console when the system boots into emergency mode. This feature is particularly useful for remote management and recovery of SLES VMs in Azure environments.

GRUB Access in SUSE SLES

GRUB Access in SUSE SLES

Accessing GRUB in SUSE SLES requires an initial bootloader configuration through YaST (Yet another Setup Tool), SUSE’s system configuration and management tool. This configuration is necessary to enable GRUB access via the serial console. The steps to configure GRUB access in SLES using YaST are as follows:

  1. Access YaST Bootloader Module: Establish an SSH connection to your SLES VM. Once connected, run the command sudo yast bootloader. This command launches the YaST control center directly into the bootloader configuration module. You can navigate through the YaST interface using Tab, Enter, and arrow keys.
  2. Navigate to Kernel Parameters: Within the YaST bootloader module, navigate to the section labeled Kernel Parameters. This section contains settings related to kernel boot options.
  3. Enable Serial Console: In the Kernel Parameters section, locate and select the checkbox labeled Use serial console. Enabling this option is crucial for directing GRUB output to the serial console.
  4. Add Console Arguments: In the Console arguments input field, add the following string: serial --unit=0 --speed=9600 --parity=no. This string specifies the serial port configuration for GRUB. --unit=0 refers to the first serial port (ttyS0), --speed=9600 sets the baud rate to 9600, and --parity=no indicates no parity. These settings are commonly used for serial console communication.
  5. Save and Exit YaST: After configuring the serial console settings, press F10 to save your changes and exit YaST. YaST will apply the new bootloader configuration.
  6. Access GRUB During Boot: To access the GRUB menu after configuring it through YaST, reboot your VM. During the boot sequence, press any key on your keyboard. This key press should keep the GRUB menu displayed. If you do not press a key, GRUB might proceed to boot the default OS after a short timeout.

Note that the default timeout for GRUB in SLES is set to a very short duration, typically 1 second. This short timeout means that the GRUB menu might appear only briefly unless you press a key to interrupt the boot process. If you need more time to interact with the GRUB menu, you can modify the GRUB_TIMEOUT variable in the /etc/default/grub file to increase the timeout period.

Single-User Mode in SUSE SLES

Single-User Mode in SUSE SLES

If a SUSE Linux Enterprise Server (SLES) system fails to boot normally, it is designed to automatically drop into an emergency shell. This emergency shell provides a minimal environment for system recovery and troubleshooting. In addition to automatic fallback, you can also manually initiate the emergency shell from GRUB. The steps to manually enter the emergency shell in SLES are as follows:

  1. Access GRUB: Access the GRUB menu during the VM boot process. Refer to the previous section on GRUB access in SLES for instructions on how to access the GRUB menu.
  2. Edit Boot Entry: In the GRUB menu, select the boot entry for SLES and press the E key to edit the boot parameters.
  3. Locate Kernel Line: Find the kernel line, which typically starts with linux.
  4. Append systemd.unit=emergency.target: Append the parameter systemd.unit=emergency.target to the end of the kernel line. Ensure there is a space before this parameter to separate it from the preceding parameters. This parameter instructs systemd to boot into the emergency.target, which corresponds to the emergency shell.
  5. Boot into Emergency Shell: Press Ctrl+X to exit the GRUB edit screen and boot the system with these modified settings. SLES will now boot into the emergency shell.

Note: When you boot into the emergency shell using this method, the file system is initially mounted as read-only. If you need to modify any files, you must remount the root file system with read-write permissions. To do this, once you are in the emergency shell, execute the command mount -o remount,rw /. This command remounts the root file system, making it writable, allowing you to perform necessary file modifications for system recovery or troubleshooting.

Access for Oracle Linux

Oracle Linux

Similar to Red Hat Enterprise Linux and CentOS, single-user mode in Oracle Linux relies on having GRUB enabled and the root user account properly configured. Oracle Linux is derived from RHEL, and as such, it shares many of the same system administration practices and configurations, particularly concerning boot processes and recovery modes.

GRUB Access in Oracle Linux

GRUB Access in Oracle Linux

Oracle Linux, like RHEL and CentOS, comes with GRUB enabled by default as part of its standard installation. This pre-configuration simplifies access to the bootloader menu for system maintenance and recovery tasks. To access the GRUB menu in an Oracle Linux virtual machine, the procedure is similar to RHEL and CentOS. Reboot your Oracle Linux VM. This can be done via SSH using sudo reboot or through the Azure portal’s VM restart option. Immediately after initiating the reboot, press the Esc key. This action should interrupt the normal boot sequence and display the GRUB menu.

If the GRUB menu does not appear as expected, it is important to verify the GRUB configuration. Specifically, check the GRUB configuration file, typically located at /etc/default/grub. Ensure that the line GRUB_TERMINAL contains serial console. It should look like GRUB_TERMINAL="serial console". This setting ensures that GRUB output is directed to the serial console, which is essential for accessing GRUB in Azure VMs via Serial Console. After verifying or modifying the GRUB_TERMINAL setting, you need to rebuild the GRUB configuration file to apply the changes. Run the command grub2-mkconfig -o /boot/grub/grub.cfg. This command regenerates the GRUB configuration file based on the settings in /etc/default/grub and other related configuration files.

Single-User Mode in Oracle Linux

Single-User Mode in Oracle Linux

To enable and configure single-user mode in Oracle Linux, it is recommended to follow the same instructions provided earlier for Red Hat Enterprise Linux (RHEL). Given the close relationship between Oracle Linux and RHEL, particularly at the kernel and core system level, the procedures for configuring root access, GRUB settings, and manually entering single-user mode are largely consistent. System administrators familiar with RHEL or CentOS will find these procedures directly applicable to Oracle Linux environments.

Next Steps

Next Steps

Utilizing Serial Console to access GRUB and single-user mode in Azure VMs is a powerful technique for system recovery and maintenance. For further exploration and deeper understanding of related topics, consider expanding your knowledge in these areas:

  • Linux Serial Console Documentation: Delve into the comprehensive documentation for Linux Serial Console to master its features and capabilities for Azure virtual machines.
  • GRUB in Various Distributions: Investigate how GRUB is implemented and configured across different Linux distributions to gain a broader perspective on bootloader management.
  • NMI and SysRq Calls: Learn about Non-Maskable Interrupt (NMI) and System Request (SysRq) calls and how they can be used in conjunction with Serial Console for advanced system debugging and control.
  • Serial Console for Windows VMs: Explore the functionalities and usage of Serial Console for Windows-based Azure virtual machines to understand cross-platform system management.
  • Boot Diagnostics: Study boot diagnostics tools and techniques to enhance your ability to troubleshoot and resolve VM startup issues effectively.

By continuing to learn and practice these skills, you will be well-equipped to handle a wide range of system administration and recovery scenarios in Azure environments.


If you found this guide helpful or have any questions, feel free to leave a comment below! Your feedback and experiences are valuable for improving this resource.

Post a Comment