Welcome!

Linux Authors: Hovhannes Avoyan, Elizabeth White, Carmen Gonzalez, Liz McMillan, Imran Akbar

Related Topics: Linux

Linux: Article

Bad File Descriptor Error in Linux

Stellar Phoenix Linux Data Recovery is a comprehensive data recovery tool

In a Linux system, files, blocks, directories, sockets and other items are referred by corresponding file descriptors. If your system is reporting errors that the file descriptor is bad, one of possible causes is that file system is corrupt and thus, you require restoring from backup. But if backup is not valid enough to restore complete information, you need to use advanced Linux Data Recovery applications.

As an instance, you might encounter the below error message with your Linux based system:

Bad file descriptor”

You might receive this error while trying to access a file or while trying to boot the system.

Cause

Possible reasons for the ‘Bad file descriptor’ error to occur are:

  • Linux systems use a special file, called /dev/null (also called the null device). This file removes all the data that is written to it after reporting that the write process has successfully succeeded. You might receive the above error message if /dev/null has been deleted or overwritten. You can infer this cause when file system is reported as read-only at the time of booting through error messages, such as“/dev/null: Read-only filesystem” and “dup2: bad file descriptor”

  • If you get this error message while trying to access a file, the most prominent causes are file system corruption or damaged disk block(s). In such situations, you also get write errors.

Solution

You need to use these methods to troubleshoot the above behavior:

  • For solving deleted or overwritten /dev/null file issues, you need to replace it with the suitable inode. To do so, follow these steps:

    • Boot the system in single-user mode

    • Mount the /proc file system as:

mount -o ro /proc

/proc is the dynamically generated file system while boot process

  • Mount the file system in read-write mode as:

mount -o remount,rw /

  • Delete the /dev/null file:

m -f /dev/null

  • Use correct inode to replace it as:

mknod -m 666 /dev/null c 1 3

  • Remount the file system in read-only mode and restart the system

  • To correct file system and disk block issues, execute fsck command. You should run the command when the file system is not mounted. If problem persists, reformat the volume and restore from backup. In case of backup problems, you will need to use Linux Recovery tools. Such utilities perform Data Recovery Linux using powerful scanning algorthms and provide graphically rich user interface.

Stellar Phoenix Linux Data Recovery is a comprehensive data recovery tool for Linux-based system. It supports safe Data Recovery  Linux for Ext2, Ext3, and ReiserFS file systems. The application provides you advanced features such as, RAW File Recovery, File Filter, Append File Header etc. It is compatible with almost all Linux distributions including Gentoo, SlackWare, Mandrake, Red Hat, Ubuntu, SUSE etc.

More Stories By Allen Sood

Allen Sood is a student of Mass Communication doing research on Linux Data Recovery software.