LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   why is a lost+found folder in my newly created disk? (https://www.linuxquestions.org/questions/linux-newbie-8/why-is-a-lost-found-folder-in-my-newly-created-disk-4175577420/)

jzoudavy 04-13-2016 09:49 PM

why is a lost+found folder in my newly created disk?
 
hi all

Am running through a paritioning excersize. I just created the new sdb1 with fdisk and mkfs.ext3, and after mounting it I noticed that there is a folder called lost+found. what is the purpose of that folder?

What would get lost?

syg00 04-13-2016 11:08 PM

As this appears to be a learning exercise, what did your favourite search engine return ?.

rtmistler 04-14-2016 05:47 AM

I didn't know myself, looks like fsck uses it. I've noticed it for ext4 file systems I create. Unsure if it's there for all file system types.

http://unix.stackexchange.com/questi...linux-and-unix

Beefybison 04-14-2016 06:08 AM

You are correct that fsck uses it. It is used for any files that aren't properly closed for any reason such as a power failure.

jpollard 04-14-2016 06:32 AM

Quote:

Originally Posted by Beefybison (Post 5530957)
You are correct that fsck uses it. It is used for any files that aren't properly closed for any reason such as a power failure.

Not quite.

The lost+found directory is used by fsck when it identifies an inode (file) that is not recorded in any directory - in other words, it is lost, and cannot be accessed. In earlier filesystems (ext/ext2) this happens when the system crashes before updating a directory entry with a new file (it is in buffers to be written, but doesn't get written).

Ext3 added a journal to catch this situation, and will replay the journal to apply the updates, so it happens a LOT less. Ext4 continued that and made it work better so it happens even less.

It is actually not necessary (as per the developers statement) that fsck be run for ext4 at boot. Replaying the journal should be sufficient.

That doesn't mean problems can't occur... Specially when layering filesystems on top of other structures (lvm and md), but now it is more important that the other layers maintain their consistency to protect the data.

The use of the lost+found directory goes all the way back to the origin of UNIX, and nearly all UNIX/Linux native filesystems will have a lost+found directory for this purpose.

The last note is that the lost+found directory traditionally had at least 10 blocks (more for bigger disks) preallocated so that fsck could update the directory without having to allocate disk blocks (which may not be valid either during a crash recovery).

DavidMcCann 04-14-2016 10:19 AM

The lost+found directory even gets created on a usb stick if you format it with a Linux system!

After running fsck, you find it's full of files simply identified by a number. These are things that fsck thought looked like files but which had no entry in any directory. Some will indeed be wanted files, and some will be deleted files, and some will be bits of deleted files. You then have the dubious pleasure of examining each one and deciding what to do with it, but at least everything that could be recovered will have been recovered.


All times are GMT -5. The time now is 02:54 PM.