File is corrupt linux

e2fsck – Repair Your Corrupted Linux File System

There might be many reasons for your Linux file system to go into unusable or corrupted state. Such as: Sudden power failure, faulty device drivers, faulty software package, unstable updates etc. and this might leave your Linux system in unusable state. e2fsck is a tool that comes handy in such situations and helps you recover your file system and restore your Linux system to usable state. e2fsck checks for ext2/ext3/ext4 for errors and repair them accordingly. In case of ext3 and ext4 filesystems which uses journal, if your Linux OS has been shut down uncleanly without any errors, usually, after replaying the committed transactions in the journal, the file system should be marked as clean and ready for use. Thus, for filesystems that use Journaling, it will normally replay the journal and exit, unless its superblock shows that further checking is needed.

e2fsck in action

Usually it is not recommend to use this tool on mounted file system as it might cause further problems. Even if you still choose to run it on safe file system, result produced by e2fsck still won’t be valid.

Check a partition

You should have root privileges to run this command. If not, you’ll get the error message.

File system need not to be mounted. If the file system is mounted, you’ll get the error message shown below.

Automatic repair using e2fsck

Using -p option, you can direct e2fsck to check and automatically repair all found problems without asking user for confirmation.

You can also use option -y, which will automatically answer “yes” to all the questions that will be asked by the e2fsck command.

Check only (no change)

Using -n option, will direct the e2fsck to perform check only. i.e it will not make any changes to the filesystem, it will only check.

Force the filesystem check

If you have a clean file system but you want to force the filesystem check then use the -f option as shown below.

Display a progress bar during e2fsck check

Using -C option, this option is used for file descriptor, where e2fsck will send the output, it is very useful if you are doing e2fsck from a shell script.

Moreover if you specify “-C 0”, it will display a progress bar while e2fsck is doing the check, which is very handy, if you want to track the progress of your checking process.

Syntax

All the other useful options

Option Description
-a It’s a similar option as -p. Only difference is, It’s used for backward compatibly.
-b Using this option, you can give an substitute superblock. This option is handy when the main superblock is corrupted. Filesystems that has 1k blocksizes, a backup superblock can be found at block 8193; for filesystems with 2k blocksizes, at block 16384; and for 4k block‐sizes, at block 32768. Use -n option to see otherwise available backup superblocks. The -b option, which specifies blocksize of the filesystem must be specified in order for the superblock locations that are printed out to be accurate
-B Using this option will result in searching for the superblock using different block sizes. This option forces to use only the given superblock blocksize. If the superblock is not found, it will terminate with a fatal error.
-c Using this option, it will use badblocks program to do a read-only scan of the device in order to find any bad blocks. If any bad blocks are found, they are added to the bad block inode to prevent them from being allocated to a file or directory. If this option is specified twice, then the bad block scan will be done using a non-destructive read-write test.
-C Using this option it will write completion information to the specified file descriptor so that the progress of the filesystem check can be monitored. This option is typically used by programs which are running e2fsck.
-d Print debugging output. Not useful except to debug e2fsck command itself.
-D Use this option to optimize directories in filesystem. Does this by reindexing them, or by sorting and compressing directories for smaller directories, or for filesystems using traditional linear directories.
-E Using this option you can set e2fsck extended options. These are comma separated, and may take an argument using the equals (‘=’) sign. It supports ea_ver=extended_attribute_version and fragcheck
-f Force checking even if the file system seems clean
-F Flush the filesystem device’s buffer caches before beginning. Only really useful for doing time trials.
-j Set the pathname where the external-journal for this filesystem can be found.
-k When combined with the -c option, any existing bad blocks in the bad blocks list are preserved, and any new bad blocks found by running badblocks(8) will be added to the existing bad blocks list.
-l Add the block numbers listed in the file specified by filename to the list of bad blocks.
-L Using this option set the bad blocks list to be the list of blocks specified by filename. (This option is the same as the -l option, except the bad blocks list is cleared before the blocks listed in the file are added to the bad blocks list.)
-n Using this option open the filesystem read-only, and assume an answer of `no’ to all questions. Allows e2fsck to be used non-interactively. This option may not be specified at the same time as the -p or -y options.
-p Automatically repair (“preen”) the file system. This option will cause the automatic fixing of any filesystem problems that can be safely fixed without human intervention. If e2fsck discovers a problem which may require the system administrator to take additional corrective action, it will print a description of the problem and then exit with the value 4 logically or’ed into the exit code.
-r This option does nothing at all; it is provided only for backwards compatibility.
-t Print the timing statistics. If the option is used two times, additional timing statistics are printed on a pass by pass basis.
-v Verbose mode. Shows detail view of the processes.
-V Print version information and exit.
-y Set the default answers to “yes” for all questions; allows e2fsck to be used without interacting. It is not recommended option to use when optoins -n or -p are allowed.
Читайте также:  Linux как запустить php скрипты

The exit code returned by e2fsck is the sum of the following conditions:

0 – No errors
1 – File system errors corrected
2 – File system errors corrected, system should
be rebooted
4 – File system errors left uncorrected
8 – Operational error
16 – Usage or syntax error
32 – E2fsck canceled by user request
128 – Shared library error

Источник

File is corrupt linux

Below issue is happend rare case on Linux OS reboot .

after reboot the Linux OS , then Ffile systems are corrupted (issue).

1) any command for caputure file systems mount point report -( OS restart before )

2) how to verify file systems health check ( after restart OS ) . Kindly share

  • Mark as New
  • Bookmark
  • Subscribe
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Since the file system was corrupted upon reboot , my wild but educated guess (coz of lack of technical details) is that

1) your mounted file system did not get unmounted gracefully upon shutdown

1.1) a bad software or utility has messed up the FAT at MBR or equivalent.

1.2) Your system was too busy and I/O itensive but not optimized for such environment.

2) your restart procedure could not or did not check (and repair) the file system with inconsistencies before mouting it though found corrupted

3) your system has got a deeper hardware error such as bad blocks on the HDD or more weird hardware ones (such as hdd controller or bad memory)

4) last but not least, a bug in the kernel’s FS Module.

Читайте также:  Какие данные собирает windows

And here we go the answers to your questions:

1) any command for caputure file systems mount point report -( OS restart before )

> df -hT, mount, dmesg, lsblk -f

2) how to verify file systems health check ( after restart OS ) . Kindly share

But I really wonder what kind of file system are we talking about? ext2/3/4, xfs, etc. etc?

  • Mark as New
  • Bookmark
  • Subscribe
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Very glad we could be of help and gladder you found the support helpful.

Additionally, I’d like to point out a couple of things regardig the rare but very critical file system corruption case.

Though any linux compatible modern file systems are quite versatile and resilient, there are trade offs between performance and consistency and they can depending on the situation be found inconsistant or corrupted.

And further more, when you do fsck or xfs_repair, the safest way is to do so on an UNmounted file system. As such, you will sometimes have to deal with rescue or emergency targets aka single user or maintenance mode.. And you might even need to boot from a bootalbe dvd/usb or iso before safely working on or recovering the corrupted file systems.

And then, what if the file systems are beyound repair?

Then, you have no choice but to mkfs.* (aka to format) again provided you have a full back of the file systems.

Источник

Tech Trouble?

Technology with a bit of humor !

Linux : Corrupted files ?

A check on corrupt Linux file system

For your Linux installations, you might be using native Linux file system either ext2 or ext3. These file systems are very robust, near-maintenance-free (don’t need de-fragmentation like Windows FAT 32 etc.) and have ability to survive in most unfavorable conditions. However, it is also equally true that when Linux file system gets corrupted, identifying errors and eliminating them become biggest headaches and often you end up with lost data. A file system is prone to errors due to one or more of these:

  • Bad, ageing disk
  • Defective / broken IDE / SCSI cable
  • Errors in Memory Modules
  • Bugs in Programs
  • Power Interruptions
  • The removable storage device is removed (like Floppy disk, Ram Drive etc. ) before Kernel has finished with it.

You never know that which one of the above had silently and suddenly attacked your file system and had made it corrupt. Still, when file system error occurs due to the reasons mentioned above, you can minimize the damages by timely and effectively using tools that are available for Linux.

Fsck is front end tool for various file system checkers for Linux, e.g. e2fsck(8). It runs as part of boot process in almost all Linux installations. Fsck is a utility that checks for file system errors and repairs a damaged and corrupted Linux file system. When you halt or shut down your machine, the File system is properly and cleanly unmounted and Kernel writes a special signature on the file system that indicate that files and data are intact. When the file system is mounted again, this signature is removed and a fresh signature is written when it is properly unmounted again. During boot process, before mounting the file system, the said signature is checked. If the signature is found, it is assumed that the file system was unmounted properly last time, and file system is intact and can be used without errors. If other argument are not found (such as periodic forced check), then file system is not checked by the fsck, it is assumed clean and therefore mounted. When the said signature is not found for any of the device having supported file system, fsck checks them for the errors and optionally can remove the errors if it finds. Some errors may not be repairable by fsck, and in this case, data loss may occur.

Читайте также:  Тестирование жестких дисков windows

If fsck finds (this property of fsck can be set through tune2fs, another utility that lets you configure usage of fsck) that it has been a lot of time (say, six months) or number of reboots exceeds (say 20 reboots) since it has not checked the file system, it forces full file system check even when it finds a clean file system. Further, if you use Journaling file system (ext3), the file system is not marked corrupted and hence needs periodic force check. In general, during boot process, if any argument is not given, fsck checks file system in order that are entered in /etc/fstab.

File system checks should not be performed on mounted devices and file systems. You must unmount them to check them properly. Serious file system damage may occur if you run fsck on mounted file system. Similarly, sometimes, boot time file checking may fail and you need to check your files manually.

Steps to check a corrupt file system:

When automatic file system check at boot time fails, you need to check the file system manually. Su to root, unmount it if it is mounted and run command :

For checking with some advanced options, you can use e2fsck instead. There are many advanced options that you can use for special file checking. See man pages of e2fsck for details about advance options. Path name can be a device name, for example, /dev/hda1; a mount point such as /usr or a UUID identifier. The arguments or options for advanced check are usually not necessary for simple file check and for finding and correcting simple file system errors such as correcting inodes. Usually a manual check removes the errors from Linux file system and you will be able to use your files again. Some time, you may not be able to boot in to Linux even for file check, then you can use rescue disks to boot the machine. A better way is to boot through bootable Live CDs that are distributed with LFY and run fsck from there.

Tune2fs

This tool allows you to adjust various tunable file system parameters on Linux ext2 / ext3 file system. With tune2fs, you can define the way fsck checks your file system during boot time. Tune2fs lets you define maximum time interval (with –i option), or maximum count between two file system checks (with – C option). Mount count dependent or time dependent full file checking is best planned for healthy file system even if there is remote possibility of occurrences of file system errors. You might have seen following message during boot time when you restart your Linux machine without proper shutdown:

Your system appears to have shut down uncleanly

Press Y within 5 seconds to force file system integrity check.

Through tune2fs you can set these behaviors and manage file system checks accordingly.

Dumpe2fs

At times, you need some information about your file system. There is a utility dumpe2fs which can give you number of information about Linux file system. For example, if you want status of bad blocks on a device containing Linux file system, run dumpe2fs with option –b. It will check for bad blocks and give you information about the bad blocks it finds in a dumped file. Dumpe2fs has various arguments and options and you can get the information you need about your file system for a quick diagnosis. For more information on dumpe2fs, see its man pages.

Источник

Оцените статью