All Products
Search
Document Center

:How to migrate data from the system disk of a Linux instance

Last Updated:Apr 27, 2022

Disclaimer: This topic may contain information about third-party products. The information is for reference only. Alibaba Cloud does not make a guarantee in any form of the performance and reliability of the third-party products, and potential impacts of operations on these products.

Overview

When you purchase a Linux ECS instance, no data disks are purchased. After a period of use, the existing system disks can no longer meet the business requirements as the business increases. Run the df -h command to query the space usage. If the system disk usage is close to 100%, you need to migrate data to the newly purchased data disk.

Description

Take note of the following items:

  • Before you perform high-risk operations such as modifying the specifications or data of an Alibaba Cloud instance, we recommend that you check the disaster recovery and fault tolerance capabilities of the instance to ensure data security.
  • Before you modify the specifications or data of an Alibaba Cloud instance, such as an Elastic Compute Service (ECS) instance or an ApsaraDB RDS instance, we recommend that you create snapshots or enable backups for the instance. For example, you can enable log backups for an ApsaraDB RDS instance.
  • If you have granted specific users the permissions on sensitive information, such as usernames and passwords, or submitted sensitive information in the Alibaba Cloud Management Console, we recommend that you modify the sensitive information at the earliest opportunity.

For more information about how to solve this problem, see the following:

Note: This solution involves data operations. Before the operations, you must create a snapshot to back up data.

  1. Purchase a data disk. After creating partitions, mount the data disk to the /mnt/shujupan directory in the system.
  2. Create a snapshot backup of the system disk to roll back when the operation fails.
  3. For data security reasons, you must stop the running service program to ensure smooth migration. For more information, see the following example:
    /etc/init.d/nginx stop
    /etc/init.d/httpd stop
    /etc/init.d/mysqld stop
    /etc/init.d/php-fpm stop
    /etc/init.d/vsftpd stop



  4. Assume that the /mnt/www directory of the current system disk is the directory where data migration is required. Run the following command to migrate all files in the www directory to the data disk:
    cp -arp /mnt/www/* /mnt/shujupan/
    Note: This topic uses the /mnt/www directory as an example.
  5. Run the following command to uninstall the /mnt/shujupan/ directory:
    umount /mnt/shujupan/
  6. Run the following command to mount the /mnt/www directory:
    mount /dev/vdb1 /mnt/www
  7. Run the following command to modify the fstab file and specify the mount directory of the data disk to enable startup.
    vi /etc/fstab 
    Add the following content at the end of the file to save and restart the instance.
    /dev/xvdb1 /mnt/www ext4 defaults 0 0
    Note: ext4 indicates the file system type of the data disk, and xvdb1 indicates the partition of the data disk.
  8. After the restart, check whether the program services in the system are running normally, and test whether the site and database can be connected and accessed normally. If no exception occurs, the data is migrated. At this time, the system and program are still accessing the /mnt/www directory, but the directory is located on the data disk. Run the df -h command to confirm that the system disk space usage is back to normal.

Applicable scope

  • Elastic Compute Service (ECS)