6

I had a folder /acme, that contained data. I found out that I was supposed to have already mounted /dev/centos/lv_acme to /acme. I did a minimum amount of research on the web, and it appeared that mounting did not erase data. (Though I now assume I misunderstood what I read.)

I executed the command

mount /dev/centos/lv_acme /acme  

As I'm sure you've figured by now, /acme no longer contains my data. Is there any way of recovering the data that was in /acme?

Prvt_Yadav
  • 5,882
Chozang
  • 163
  • The question was already answered before it was incorrectly marked as a duplicate. Amazing how five people can agree on something wrong. – Chozang Jun 30 '18 at 23:56

3 Answers3

15

Mounting does not erase data, but it might hide data since the contents of the mountpoint are replaced with the mounted filesystem (which may be empty). Of course, there may be side effects (programs that behave differently depending on how things are mounted), so things can still go horribly wrong when you mismanage your mountpoints.

If you mounted an empty filesystem in the wrong place, simply umounting would do:

umount /acme

If you want to see what is below a mountpoint without umounting it, you can bind-mount the parent filesystem elsewhere:

mkdir /mnt/root
mount --bind / /mnt/root
ls /mnt/root/acme

It's more difficult if there are more filesystem layers mounted over one another. Use lsblk and cat /proc/mounts to figure out the structure. You can bind-mount each layer separately in a temporary directory and check out the contents.

Note those bind-mounts are writable by default so it's possible to change, rename and remove files. For a read-only view, just add --read-only.

frostschutz
  • 48,978
14

Easy,

umount /acme

Your original /acme directory is simply "hidden" under the mount point.

If nothing prevents you to umount the dir, you can umount it, copy the data elsewhere and remount it.

andcoz
  • 17,130
  • 14
    I frequently put a file named simply not-mounted in a directory that is supposed to be used as a mount point -- if I can see the file, then I know the volume isn't mounted. Unmounting the volume makes the file visible again. – KlaymenDK Jun 29 '18 at 14:01
3

If you can't unmount the mounted filesystem the original can still be reached by mounting it on a temporary mount point and accessing the files that way.