To automatically mount your data disk at startup, add its Universally Unique Identifier (UUID) to the /etc/fstab
file. Otherwise, you must manually mount the file system after each reboot to access the files on the disk.
Procedure
Before you begin, ensure your data disk is In Use, initialized, and has a mounted file system.
Log on to the Elastic Compute Service (ECS) instance.
Go to ECS console - Instance. In the top navigation bar, select the target region and resource group.
Go to the instance's details page. Click Connect and select Workbench. Follow the on-screen prompts to log on and access the terminal.
To prevent errors from incorrect configuration, create a backup of the
/etc/fstab
file.sudo cp /etc/fstab /etc/fstab.bak
Configure the mount information.
Get the information of the target disk.
Run the
sudo lsblk -f
command. Record the target device name, mount point, and file system type for the disk you want to configure.$ sudo lsblk -f
NAME FSTYPE LABEL UUID MOUNTPOINT vda └─vda1 ext4 root 33b46ac5-7482-4aa5-8de0-60ab4c3a4c78 / vdb ext4 3d7a3861-da22-484e-bbf4-b09375894b4f └─vdb1 ext4 f1645951-134f-4677-b5f4-c65c71f8f86d /mnt vdc xfs 3d7a3861-da22-484e-bbf4-b09375894b4f /test
If the device has a partition, the target device name is the partition name. In the example, for data disk
vdb
, the target device name isvdb1
, the mount point is/mnt
, and the file system type isext4
.If the device does not have a partition, the target device name is the same as the device name. In the example, for data disk
vdc
, the target device name isvdc
, the mount point is/test
, and the file system type isxfs
.
Add the mount information to
/etc/fstab
.Replace the
<target_device_name>
,<mount_point>
, and<file_system_type>
in the command with the information from the previous step, and then run the command. For parameter descriptions, see fstab man-pages.ImportantWhen you set the options to
defaults,nofail
, the instance can start normally even with an incorrect mount configuration. However, the system does not report an error. You must carefully verify that the automatic mount succeeded to avoid writing data to the wrong device.sudo sh -c "echo `sudo blkid /dev/<target_device_name> | awk '{print \$2}' | sed 's/\"//g'` <mount_point> <file_system_type> defaults 0 0 >> /etc/fstab"
For example, to configure a disk where the target device name is
vdb1
, the mount point is/mnt
, and the file system type isext4
:sudo sh -c "echo `sudo blkid /dev/vdb1 | awk '{print \$2}' | sed 's/\"//g'` /mnt ext4 defaults 0 0 >> /etc/fstab"
Verify the automatic mount configuration.
Unmount the current mount point.
Replace
<target_device_name>
with the target device name from Step 2.a.sudo umount /dev/<target_device_name>
Reload the
/etc/fstab
file.Run the following command to mount all unmounted file systems listed in
/etc/fstab
.sudo mount -a
If an error occurs, you can quickly restore the original
/etc/fstab
file by runningsudo mv /etc/fstab.bak /etc/fstab
.Check if the mount was successful.
Run the
sudo lsblk
command. If the output shows a mount point (MOUNTPOINT
) for the target device, the configuration is successful.
Run the
sudo reboot
command to restart the operating system and verify that it starts normally.ImportantRebooting the operating system can impact your live services. Proceed with caution.
If the instance starts successfully, run the
sudo lsblk
command. If the output shows a mount point (MOUNTPOINT
) for the target device, the configuration is successful.If the instance fails to start, follow the instructions in Troubleshoot system startup failures on a Linux instance caused by an /etc/fstab configuration error to resolve the issue.