A volte potresti ricevere un errore durante l'esecuzione del comando df dicendo che tat il file /etc/mtab è danneggiato o vuoto (rimosso). È possibile che qualcuno abbia modificato accidentalmente il file /etc/mtab e abbia dati errati. Bene, questo post ti aiuterà a ripristinare il tuo file mtab corretto.
A cosa serve il file /etc/mtab
Prima di iniziare, vediamo cos'è un file mtab. /etc/mtab è il file che mantiene un elenco di filesystem attualmente montati. Quindi, quando esegui un comando "df", fa riferimento a questo file per generare un output per te. Il termine "mtab" si riferisce alla "Tabella dei filesystem montati". Il file mtab ha un collegamento software al file /proc/self/mounts .
# ls -lrt /etc/mtab lrwxrwxrwx. 1 root root 17 Sep 29 2014 /etc/mtab -> /proc/self/mounts
C'è un altro file chiamato “/proc/mounts ” che è anche collegato in modo soft al file “/proc/self/mounts”.
# ls -lrt /proc/mounts lrwxrwxrwx. 1 root root 11 Jun 11 11:49 /proc/mounts -> self/mounts
/proc/mounts è la vista del kernel dei punti di montaggio. Quindi è un po' archiviato nella memoria in tempo reale del sistema. Per la pagina man di 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.)
Come recuperare un file /etc/mtab corrotto o rimosso
1. Per ricreare il file /etc/mtab, dobbiamo semplicemente copiare il contenuto di /proc/mounts nel file /etc/mtab. In altre parole, copia la tabella di montaggio del kernel nel file della tabella di montaggio con:
# cp /proc/mounts /etc/mtab
/proc/mounts è la vista del kernel di tutti i filesystem mentre il file /etc/mtab è il file di configurazione per i filesystem attualmente montati. Quindi /proc/mounts ha una visione più accurata di tutti i filesystem che sono attualmente montati. Ha anche il set completo di opzioni che sono state usate durante il montaggio di questi filesystem.
Rimozione accidentale del collegamento software a /proc/self/mounts
Può accadere che il collegamento software al file /etc/mtab venga rimosso accidentalmente, causando il mancato funzionamento di df. Potrebbe anche avere un grave impatto sul server rendendolo non avviabile. Per risolvere il problema, puoi ricreare il collegamento simbolico utilizzando:
# rm -f /etc/mtab # ln -s /proc/self/mounts /etc/mtab