6

I wanted to automatically mount a directory in my home directory, so I attempted to use autofs for this resulting in autofs removing everything in my home directory.

The setup was something like auto.master:

/home/my-user auto.my-user

auto.my-user:

# Mount points for the media folder

external-media -fstype=auto :/dev/sdb1

After restarting autofs I was horrified to see that it removed everything in my home directory.

Looking at the output of df -h it looks like the files are still taking up room on my disk which makes me hopefully I might be able to recover them. But how would I go about finding them?

I've tried:

sudo service autofs stop

But the folder is still empty:

ls -al /home/my-user
total 4
drwxr-xr-x 2 root root    0 May  4 12:58 .
drwxr-xr-x 4 root root 4096 Nov 13 20:30 ..

Any tips for how to recover the files?

2 Answers2

14

After restarting autofs I was horrified to see that it removed everything in my home directory.

It has not removed anything. It has mounted the virtual autofs filesystem on the directory, corresponding to the autofs map you've defined. You'd see this by looking at findmnt.

Autofs is designed to support wildcards (* entries) and even dynamic lookups (e.g. the map may be a script), and the only way to implement that is to let it handle the entire directory where autofs mounts will be present, instead of just the mounts themselves – this is called an "indirect" map.

All mounts on Linux are opaque, so if something was mounted on a directory, the directory's real contents become invisible even though they're still on the physical filesystem. To get access to your files, unmount the autofs filesystem that's mounted there (again, see findmnt output).

# umount /home/my-user

(Or remove it from your auto.master map and reboot.)

If you want only /home/my-user/external-media to become an autofs mount, you need to define it through a direct map, first by defining the special /- entry in the master map:

/etc/auto.master
/- auto.direct

and then defining mounts with their full paths:

/etc/auto.direct
/home/my-user/external-media -fstype=auto :/dev/sdb1

or, to make things easier, by using systemd's built-in support for direct autofs mounts (which doesn't require the autofs daemon):

/etc/fstab
/dev/sdb1 /home/my-user/external-media auto ro,x-systemd.automount 0 0
grawity
  • 501,077
4

The files are located in the /home or / filesystem and you "hide" them by mounting over the disk /dev/sdb1. You need to unmount the disk you use with autofs:

umount /dev/sdb1

or

umount /home/my-user

But for this you need to be root (or other user via sudo). Do not attempt to login to your user and use sudo, will return error (something like resource/disk busy).

Romeo Ninov
  • 7,848