All Products
Search
Document Center

Elastic Compute Service:What do I do if system startup exceptions occur due to configuration errors in the /etc/fstab file on a Linux instance?

Last Updated:Dec 09, 2024

In a Linux operating system, the /etc/fstab file is used to store disk mounting information. If the file contains configuration errors, the operating system may fail to start. This topic describes the cause of and solution to system startup exceptions that occur due to configuration errors in the /etc/fstab file on a Linux Elastic Compute Service (ECS) instance.

Problem description

If you restart the operating system of a Linux instance after you modify the /etc/fstab file, the operating system cannot start as expected. In addition, you cannot connect to the instance by using remote connection software. If you connect to the Linux instance by using Virtual Network Computing (VNC), you are prompted that the operating system must enter the emergency mode and relevant error messages appear, as shown in the following figures.

Alibaba Cloud Linux

image

CentOS

Ubuntu

image

Cause

In most cases, the preceding issue occurs when the /etc/fstab file contains incorrect file system or partition information. If the file contains incorrect mounting information or access errors exist for the file, such as improper permission configurations or data loss, an exception may occur when the operating system starts. As a result, the operating system may fail to start.

Solution

The configurations and descriptions described in this topic apply to Alibaba Cloud Linux 2, Alibaba Cloud Linux 3, CentOS 6, CentOS 7, CentOS 8, Ubuntu 22.04, and Ubuntu 24.04. The configurations of other operating system versions may be different. For more information, see the official documentation of the corresponding operating system.

Warning
  • The following operations are high-risk operations. Accidental operations may cause data loss. To ensure data security on the instance, we recommend that you create snapshots or enable features, such as RDS log backup, for the instance before you perform the operations. For more information, see Create a snapshot.

  • Before you perform operations that may pose risks, such as modifying instance configurations or data, we recommend that you check the disaster recovery and fault tolerance capabilities of the instances to ensure data security.

  • If you granted access permissions on sensitive information or submitted sensitive information, such as usernames and passwords, in the Alibaba Cloud Management Console, we recommend that you modify the information at the earliest opportunity.

  1. Connect to the instance.

    Connect to the instance by using VNC. For more information, see Connect to an instance by using VNC.

  2. Enter the emergency mode.

    Note

    To repair startup failures caused by configuration errors in the /etc/fstab file on the Linux instance, the operating system of the instance must enter the emergency mode. If the operating system is already in emergency mode, skip this step and proceed to the subsequent steps.

    Perform the following steps to modify the GRand Unified Bootloader (GRUB) configuration for the operating system to enter the emergency mode.

    Alibaba Cloud Linux

    1. Restart the instance. When the GRUB page appears, press the E key to enter the edit mode.

      image

    2. In the GRUB configuration, move the cursor to the configuration line that starts with linux, press Ctrl+E to move the cursor to the end of the configuration line, and then add the following content at the end of the line:

      systemd.unit=emergency.target

      The following figure shows an example of the configuration line.

      image

    3. Press Ctrl+X or the F10 key to boot the operating system into the emergency mode.

    4. In emergency mode, enter the password of the root user as prompted to log on to the operating system.

      image

    CentOS

    1. Restart the instance. When the GRUB page appears, press the E key to enter the edit mode.

      image

    2. In the GRUB configuration, move the cursor to the configuration line that starts with linux, press Ctrl+E to move the cursor to the end of the configuration line, and then add the following content at the end of the line:

      systemd.unit=emergency.target

      The following figure shows an example of the configuration line.

      image

    3. Press Ctrl+X or the F10 key to boot the operating system into the emergency mode.

    4. In emergency mode, enter the password of the root user as prompted to log on to the operating system.

      image

    Ubuntu

    1. Restart the instance. When the GRUB page appears, press the E key to enter the edit mode.

      image

    2. In the GRUB configuration, move the cursor to the configuration line that starts with linux, press Ctrl+E to move the cursor to the end of the configuration line, and then add the following content at the end of the line:

      systemd.unit=emergency.target

      The following figure shows an example of the configuration line.

      image

    3. Press Ctrl+X or the F10 key to boot the operating system into the emergency mode.

    4. In emergency mode, enter the password of the root user as prompted to log on to the operating system.

      image

  3. Correct configuration errors.

    1. Run the following command to change the mount mode of the root partition to read and write:

      mount / -o remount,rw
    2. Run the blkid command to view disk partitions and file systems on the ECS instance. The following figure shows that the data disk partition is /dev/xvdb1 and the file system type of the partition is Ext4 on the ECS instance.

    3. Run the following command to open the /etc/fstab file:

      vim /etc/fstab

      Check whether the disk partition and file system information in the command output is consistent with the information returned in the previous step.

    4. (Optional) If a configuration error exists, move the cursor to the configuration line that contains the error, press the I key to enter Insert mode, and then write the correct configuration to the line. The following sample code provides an example of the correct configuration:

      /dev/xvdb1 /mydata ext4 defaults,nofail 0 0
      Note

      You can add the nofail parameter when you mount a device. This way, if the device does not exist when you start the instance, the instance ignores the device to prevent exceptions.

    5. Press the Esc key to exit Insert mode, enter :wq, and then press the Enter key to save and close the file.

  4. Verify the repair result.

    Run the following command to check whether the /etc/fstab file contains configuration errors:

    mount -a

    If no error message is reported after you run the preceding command, the file does not contain configuration errors.

  5. Restart the operating system.

    Run the following command to restart the operating system. After the restart is complete, you can log on to the operating system.

    reboot

References

For information about how to mount a disk on a Linux instance, see Initialize a data disk on a Linux instance.