• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Geek Diary

CONCEPTS | BASICS | HOWTO

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • Linux Services
    • VCS
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
    • Data Guard
  • DevOps
    • Docker
    • Shell Scripting
  • Interview Questions
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to Recover from a Corrupted or empty /etc/mtab file in CentOS/RHEL 7

By admin

Sometimes you may get an error while running the df command saying that tat the /etc/mtab file is either corrupt or empty(removed). It may be a case that someone accidentally edited the /etc/mtab file and has incorrect data. Well, this post will help you restore your correct mtab file.

What is the use of /etc/mtab file

Before we begin let’s see what an mtab file is. /etc/mtab is the file that maintains a list of currently mounted filesystems. So when you run a “df” command, it referes to this file to generate an output to you. The term “mtab” referes to “Table of Mounted Filesystems”. The mtab file has a soft link to the file /proc/self/mounts.

# ls -lrt /etc/mtab
lrwxrwxrwx. 1 root root 17 Sep 29  2014 /etc/mtab -> /proc/self/mounts

There is another file called “/proc/mounts” which is also soft linked to the file “/proc/self/mounts”.

# ls -lrt /proc/mounts
lrwxrwxrwx. 1 root root 11 Jun 11 11:49 /proc/mounts -> self/mounts

/proc/mounts is the kernel’s view of the mount points. So its kind of stored in the realtime memory of the system. For the man page of mount:

# man mount 
...
It is possible that files /etc/mtab and /proc/mounts don’t match. The first file is based only on
the mount command options, but the content of the second file also depends on the kernel and oth-
ers settings (e.g.  remote NFS server. In particular case the mount command may reports unreliable
information about an NFS mount point and the  /proc/mounts  file  usually  contains  more  reliable
information.)

How to recover a corrupt or removed /etc/mtab file

1. In order to recreate /etc/mtab file, we simply have to copy the /proc/mounts contents to /etc/mtab file. In other words, copy the kernel’s mount table to the mount table file with:

# cp /proc/mounts /etc/mtab

/proc/mounts is the kernel’s view of all the filesystems whereas the file /etc/mtab is the configuration file for the currently mounted filesystems. So /proc/mounts has a more accurate view of all the filesystems that are currently mounted. It also has the complete set of options that were used while mounting these filesystems.

Accidental removal of soft link to /proc/self/mounts

It may occur that, the soft link to the /etc/mtab file might get removed accidently, causing df to not work. It may also severely impact the server by making it un-bootable. To fix the issue, you can recreate the symlink using:

# rm -f /etc/mtab
# ln -s /proc/self/mounts /etc/mtab

Filed Under: CentOS/RHEL 7, Linux

Some more articles you might also be interested in …

  1. CentOS / RHEL 7 : How to recover from deleted root entry in /etc/shadow and/or /etc/passwd files
  2. Choosing SSSD or Winbind & Samba for Active Directory Integration in CentOS/RHEL
  3. How to Configure Multiple Fencing-device Levels in Pacemaker Cluster
  4. How To Migrate Existing Iptables rules to Nftables In CentOS/RHEL 8
  5. Anonymous User Fails to Upload File to VSFTP Server
  6. How to install an RPM package into a different directory in CentOS/RHEL/Fedora
  7. How to Check Btrfs FileSystem Usage and Perform Balancing
  8. How to transfer files securely using sftp (examples included)
  9. Linux OS Service ‘sendmail’
  10. How to change the path of the auditd log file /var/log/audit/audit.log

You May Also Like

Primary Sidebar

Recent Posts

  • Oracle Database – Configuring Secure Application Roles
  • Extend rule sets by using factors in Oracle Database Vault
  • What are Command Rules in oracle Database
  • Using Rule Sets in Oracle Database Vault
  • Archives
  • Contact Us
  • Copyright

© 2021 · The Geek Diary