Can you have multiple lost and found directories

filesystemslost-found

I was unaware of the mklost+found command until I read this question.

The mklost+found command will make a new lost+found directory in the pwd.

  1. Why would you ever need to run this command? The lost+found directory already exists in / on every distro I've checked.

  2. What would happen if you have multiple lost and found directories? Would recovered data fragments go to the lost+found dir in / , or would it go to the most recently created lost+found dir?

I'm not sure how I could deliberately create a data fragment to test this.

Best Answer

Why would you ever need to run this command?

In case the lost+found directory doesn't exist. Since it's just an ordinary directory, the root user can remove it using rm -r. Some versions of fsck, when they need to make use of a lost+found directory, will create it if it doesn't exist, and some versions won't. If there's no lost+found directory, fsck can't recover orphaned files, that is, files that do not have any directory entries that refer to them.

The Linux version of mklost+found has the following feature (from the mklost+found man page):

mklost+found pre-allocates disk blocks to the lost+found directory so that when e2fsck(8) is being run to recover a filesystem, it does not need to allocate blocks in the filesystem to store a large number of unlinked files. This ensures that e2fsck will not have to allocate data blocks in the filesystem during recovery.

This means that, if you have to recover files from a damaged filesystem using fsck, fewer files will be lost as part of the recovery process because fsck won't need to allocate blocks from the filesystem; such blocks which may contain valid file data.

What would happen if you have multiple lost and found directories?

For a given filesystem, fsck will only use one lost+found directory: the one that is at the filesystem's root directory. Any other lost+found directory will not be treated specially.