Using a Data Disk to Take Over Service Data from a Linux System Disk
Scenarios
In addition to running the OS, a system disk is sometimes used by service processes as a directory for writing data. As service data grows, the system disk space becomes insufficient, potentially affecting system stability. Migrating service data to an independent data disk frees up system disk space and enables separated management of the system and data. This also simplifies future separated capacity expansion and backup of the data disk.
This section describes how to migrate service data from a specific directory on a system disk to a data disk and configure auto-mount upon system startup. This helps you smoothly migrate data during off-peak hours and relieve the pressure on the system disk space.
This operation involves data migration under the system directory, which may temporarily affect the running of the service system. You are advised to perform this operation during off-peak hours and create a system disk snapshot in advance for data backup. If conditions permit, it is recommended that you expand the capacity of the system disk instead.
Preparations
Before starting the migration, ensure that:
- You have run df -h to check that the system disk's root partition usage has not reached 100%. Otherwise, the migration may fail.
- You have created a data disk, attached it to the cloud server, and initialized it, but have not mounted it on any directory.
- You have created a snapshot for the system disk to back up data in case the operation fails.
Procedure
The following operations describe how to migrate service data from the /appdata directory to the /dev/sdb1 data disk. Replace the directory name and device name based on your actual environment.
- Migrate data.
Mount the data disk on a temporary directory and copy the service data to the data disk.
# Create a temporary directory and mount the data disk. mkdir /mnt/temp mount /dev/sdb1 /mnt/temp # Use rsync to copy service data (retaining attributes such as permissions, owners, and timestamps). rsync -avp /appdata/ /mnt/temp/ # Confirm that the data copy is complete. du -sh /appdata/ /mnt/temp/
Ensure that data is copied to /mnt/temp/, not /mnt/temp/appdata/. The trailing slash (/) in /appdata/ indicates copying the directory contents, not the directory itself.
Figure 2 Confirming that the data copy is complete and the path is correct
- Switch the mount point.
After the data copy is complete, switch the mount point of the data disk from the temporary directory to the service directory.
This process will temporarily affect service access. You are advised to stop related services first.
# Unmount the data disk from the temporary directory. umount /mnt/temp # Rename the original service directory for short-term backup. mv /appdata /appdata_bak # Re-create a service directory and mount the data disk. mkdir /appdata mount /dev/sdb1 /appdata # Delete the temporary directory. rmdir /mnt/temp # Check the mount status and data integrity. df -h /appdata ls -l /appdata/
Figure 3 Data disk has been mounted on the service directory
- Configure auto-mount upon system startup.
After the server is restarted, the data disk will not be automatically mounted. You need to write the mount information to the /etc/fstab file. It is recommended that you use UUIDs to configure auto-mount, which avoids mounting failures caused by device name changes.
# Check the UUID of the data disk partition. blkid /dev/sdb1 # Write the mount information to fstab (replace the UUID with the actual one). echo 'UUID=a1b2c3d4-5678-90ef-... /appdata ext4 defaults 0 2' >> /etc/fstab # Verify that the configuration is correct. mount -a
Use the UUID instead of the partition name (such as /dev/sdb1) to configure fstab because partition names may change after the mount sequence of the data disk changes. UUIDs are unique identifiers of data disks and are not affected by mount sequence changes.
- Perform the verification and rollback.
After the migration is complete, it is recommended that you perform the following steps to verify that services are running properly:
# Check that the data disk is mounted on the service directory. df -h /appdata # Confirm that the service data is complete and accessible. ls -l /appdata/ cat /appdata/readme.txt
Figure 4 Verifying that the data migration is complete
After the verification is successful, start the services and check their running status. Once everything is confirmed normal, delete the backup of the original directory to free up the system disk space.
# Delete the backup file of the original directory. rm -rf /appdata_bak
If an exception occurs during the operation, use either of the following methods to restore data:
- Unmount the data disk and restore the original directory.
# Detach the data disk. umount /appdata # Delete the empty directory. rmdir /appdata # Restore the backup directory to the service directory. mv /appdata_bak /appdata # Restart the services.
- If data in the original directory is corrupted or cannot be restored using the preceding method, on the EVS console, roll back the system disk data from a system disk snapshot to restore the system disk to the state before the migration. For details, see Rolling Back Disk Data from a Snapshot. To avoid data conflicts, ensure that the data disk has been detached before performing the rollback.
- Unmount the data disk and restore the original directory.
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot