Fixing ‘dup2: bad file descriptor error’ on Linux
Posted on 07 March 2007 by admin
If you run in to a problem on Linux when after a reboot you get the following error ‘dup2: bad file descriptor error’ do not be alarmed, your system has not been compromised and your hard drives have not failed. This error is displayed if you or someone (hopefully your coworkers) have accidentally deleted or overwritten a /dev/null file. The instructions below will show you how to easily fix that problem.
Among the errors that you might recieve are the following: “dup2: bad file descriptor” to “/dev/null: Read-only filesystem” to “could not open /proc/partitions some text about UUID and Label”. The step-by-step instructions below will help you fix these errors.
Warning: Only use these if you get “dup2: bad file descriptor” and “/dev/null: Read-only filesystem” during bootup, and
“could not open /proc/partitions some text about UUID and Label” when trying to remount a filesystem.
First you must boot into the single user mode. Although if you get the error and you restart the system it will automatically drop you in into the single user mode shell.
Next you need to mount the /proc partition:
$ mount -o ro /proc
Now you must mount the / filesystem in rw mode
$ mount -o remount,rw /
Next you must delete the /dev/null file and replace it with the correct inode.
$ rm -f /dev/null
$ mknod -m 666 /dev/null c 1 3
The last step is to remount / filesystem back to the ro mode, and restart the system
$ mount -o remount,ro /
$ reboot
That should do it. Hopefully these instruction will save your at the time when errors like that happen.
