Unmounting an Amazon Elastic File System (EFS) from a host, such as an EC2 instance, is a straightforward process but should be done carefully to avoid data loss. Here are the steps:
-
Stop Processes Using the File System: Before unmounting the file system, ensure that no processes are using it. You can check if any process is using the file system by running the
lsof
command:In this case ensure that the vmagent ECS is fully stopped and decommissioned
sudo lsof /efs/mnt
Replace
/efs/mnt
with the actual mount point of your EFS file system. If this command outputs any processes, you should stop them before proceeding. -
Unmount the File System: Use the
umount
command to unmount the EFS file system.sudo umount /efs/mnt
Again, replace
/efs/mnt
with your EFS mount point. If the file system is busy (perhaps due to some processes still using it), you might see an error. In that case, ensure all processes using the file system are stopped. -
Verify the File System is Unmounted: You can verify that the file system has been unmounted successfully by using the
df
command.df -h
This command will list all mounted file systems, and you should no longer see your EFS file system in the list.
- Data Persistence: Data in EFS persists after unmounting, so you can remount the file system whenever needed without data loss.
- Automatic Mounts: If you've set up the EFS file system to be automatically mounted at boot time (e.g., by adding an entry in
/etc/fstab
), you should remove or comment out the corresponding line in/etc/fstab
if you don't want it to be mounted automatically in the future. - Network Considerations: If you're unmounting the EFS from an EC2 instance in preparation for terminating the instance, remember that as long as the mount targets and security groups are configured correctly, you can mount the EFS on another instance.
- Unmounting on Multiple Instances: If your EFS is mounted on multiple instances, you'll need to repeat this unmounting process on each instance where it's mounted.
- Ensure Backups: Take a zip backup and store it in safe location before deleting the contents present in the mounted directory.
Always proceed with caution when unmounting file systems, especially in production environments, to avoid disrupting running applications or services that might depend on them.