How to preserve original directory files after mounting in Linux?

When you mount a new file system on a Linux system, the original directory files will be hidden but not deleted. This allows you to recover the original directory files after unmounting the file system.

To preserve the original directory files, you can follow these steps:

  1. Before mounting the new file system, copy the original directory files to a safe location. You can use the “cp” command to accomplish this task. For example, if the file system you want to mount is /dev/sdb1 and the original directory files are in /mnt/old, you can use the following command to copy them:
  2. Copy the directory “old” from /mnt to /tmp.
  3. A copy named “old” will be created in the /tmp directory.
  4. Mounting a new file system. You can use the mount command to mount the file system. For example, if you want to mount the file system to /mnt/new, you can use the following command:
  5. Mount the device sdb1 to the directory /mnt/new.
  6. Make sure to create the /mnt/new directory before mounting.
  7. After completion, you can use the ‘umount’ command to unmount the new file system. For example, if you want to unmount /dev/sdb1, you can use the following command:
  8. unmount the device /dev/sdb1
  9. Restore the original directory files. You can use the mv command to move the backup files back to the original directory. For example, if your backup files are in /tmp/old, you can use the following command to move them back to the /mnt directory:
  10. Move the directory “old” from /tmp to /mnt.
  11. This will move the backup files back to the original directory.

Before performing these steps, make sure you have a sufficient understanding of mounting file systems and file operations, and take measures to backup the original directory files in case of unexpected events.

bannerAds