When you troubleshoot disks, you may encounter the loss of data disk partitions. This topic describes data disk partition loss in Linux and the solutions. This topic also describes the common mistakes and best practices for using disks to avoid the risk of data loss.

Prerequisites

Background information

In a Linux instance, you can use one of the following tools to restore data on a data disk:
  • fdisk: a tool provided by Linux for partitioning disks.
  • testdisk: a tool used to restore disk partitions or data in Linux. By default, the tool is not provided in Linux. You must install it on your own. For example, you can run the yum install -y testdisk command to install testdisk in CentOS.
  • partprobe: a tool provided by Linux. The tool is used to enable the kernel to re-read partitions without restarting the system.

Methods

After you restart a Linux instance, the partition or data of data disks may be lost. This may be because you did not set the partition to be mounted automatically upon startup of the instance in the etc/fstab file. In this case, you can manually mount the data disk partition. If the system prompts partition table loss when you manually mount the data disk partition, you can use one of the following methods to restore the partition or data:

Restore a partition by using fdisk

Typically, default values apply to the starting and ending sectors of a partition when you partition a data disk. You can first run the fdisk command to restore the partition. For more information, see Format a data disk for a Linux instance.Restore a partition by using fdisk

If the preceding operation cannot restore the partition, you can use testdisk to restore the partition.

Restore a partition by using testdisk

A disk device named /dev/xvdb is used in this example. To use testdisk to restore a partition, follow these steps:

  1. Run the testdisk /dev/xvdb command (you can replace the device name), select Proceed (default value), and then press the Enter key:
    Run testdisk /dev/xvdb
  2. Select the partition table type for scanning. Typically, the default value Intel is selected. Select EFI GPT if your data disk uses the GPT format.
    Scan the partition
  3. Select Analyse and press the Enter key.
    Select Analyse
  4. Select Quick Search and press the Enter key if the partition information is not displayed.
    Select Quick Search
    The partition information is displayed in the command output, as shown in the following figure.Command output
  5. Select the partition and press the Enter key.
  6. Select Write to save the partition.
    Note Select Deeper Search to continue to search if the expected partition is not listed.
    Select Write
  7. Press the Y key to save the partition.
    Press Y
  8. Run the partprobe /dev/xvdb command (you can replace the device name) to manually refresh the partition table.
  9. Mount the partition again and view the data in the data disk.
    Mount the partition again

Restore data by using testdisk

In some cases, you can scan and locate a disk partition by using testdisk. However, you cannot save the partition. In this case, you can directly restore the data. Follow these steps:

  1. Scan and locate a disk partition by using testdisk. For more information, see Step 1 to Step 4 in Restore a partition by using testdisk.
  2. Press the P key to list files.
    The following figure shows the command output.Press P
  3. Select the file that you want to restore and press the C key.
  4. Select the destination directory. In this example, the file is restored to the /home directory.
    Select the destination directory
    If Copy done! 1 ok, 0 failed is displayed, the file is copied, as shown in the following figure.Copied successfully
  5. Switch to the /home directory to view details.
    If the file is displayed, as shown in the following figure, the file is restored.The file is restored

Common mistakes and best practices

Data is the core asset of users. A large number of users build websites and databases such as MySQL, MongoDB, and Redis on ECS instances. Data loss may cause huge risks to businesses. This section describes the common mistakes and best practices in data security.

  • Common mistakes

    The underlying storage of Alibaba Cloud is based on triplicate technology. Therefore, some users consider that no risk of data loss in the operating system exists. This is a misunderstanding. The three copies of data stored in the underlying layer provide physical layer protection for data disks. However, if errors occur to the cloud disk logic in the system, such as infection with viruses, accidental data deletion, and file system damage, the data may still be lost. You must use technologies such as snapshots and geo-redundancy to ensure data security. For more information about three copies, see Triplicate storage.

  • Best practices

    Data disk partition restoration and data restoration are the final solutions to data loss problems, but they may not restore data as expected. We recommend that you follow the best practices to create automatic or manual snapshots for data and run different backup schemes to maximize your data security.

    • Apply automatic snapshot policies

      Automatic snapshot policies are applied to system and data disks to create automatic snapshots for the disks. Note that after the system disk is replaced, the instance expires, or the disk is manually released, the corresponding automatic snapshots may be released.

      If you want automatic snapshots of a disk to be released along with the disk, you can select Delete Automatic Snapshots While Releasing Disk in the Modify Disk Property dialog box in the ECS console. If you want to retain the automatic snapshots, you can clear this option.

      For more information, see Snapshot FAQ and Create an automatic snapshot policy.

    • Create manual snapshots
      Before you perform important or high-risk operations, you must manually create snapshots for the disk. These operations include:
      • Update the kernel.
      • Upgrade or change applications.
      • Restore data on disks.

      Before you restore a disk, you must create a snapshot for the disk. After the snapshot is created, you can perform other operations.

    • OSS backup, offline backup, and geo-redundancy

      You can back up important data by using OSS backup, offline backup, or geo-redundancy.