This article mainly explains the functions and differences of the three files in Linux/etc/fstab/etc/mtab/proc/mounts.
Transfer from http://haohaozhang.blog.51cto.com/9176600/1681827/
/etc/fstab
Operations are aware of the files, if you want to set Mount disk and Dir to automatically load each time the boot, then the relevant information should be written to this file. This file is also read when the "mount-a" command is used to mount automatically. For example:
12 |
LABEL= /hadoop/9 /hadoop/9 ext3 defaults,noatime,nodiratime,noauto 0 2 LABEL= /hadoop/10 /hadoop/10 ext3 defaults,noatime,nodiratime,noauto 0 2 |
/etc/mtab
This file is primarily used with the Mount command when the system generates data based on the actual mount situation, for example:
12 |
/dev/sdb1 /hadoop/9 ext3 rw,noatime,nodiratime 0 0 /dev/sdc1 /hadoop/10 ext3 rw,noatime,nodiratime 0 0 |
/proc/mounts
This file is a soft link to/proc/self/mounts,/proc the following files are stored in memory and are automatically generated by the kernel. So/proc/mounts can reflect the current mount situation more realistically than the/etc/mtab file.
Scenario Application:
There is a disk in the server because there is a bad way, was umount, through the "df-h" can not see the information of this disk.
Or you can use "chmod 000/dir" to set the disk to be unreadable and not writable.
At this point if you manage 1000 servers, you need to know which disks in your server are umount, what will you do?
Here is a shell script that can give you ideas for:
12345678910111213141516 |
function
check_disks {
for
m
in
`
awk
‘$3~/ext3/ {printf" %s ",$2}‘
/etc/fstab
` ;
do
fsdev=
""
fsdev=`
awk
-
v
m=$m
‘$2==m {print $1}‘
/proc/mounts
`;
if
[ -z
"$fsdev"
] ;
then
msg_=
"$msg_ $m(u)"
else
msg_=
"$msg_`awk -v m=$m ‘$2==m { if ( $4 ~ /^ro,/ ) {printf"
%s(ro)
",$2 } ; }‘ /proc/mounts`"
fi
done
if
[ -z
"$msg_"
] ;
then
echo
"disks ok"
;
exit
0
else
echo "$msg_"
;
exit
2
fi
}
|
The script first compares the differences in/etc/fstab and/proc/mounts, gets the disk that is Umount, and then analyzes the RO (read only) disk.
Analysis and comparison of the three files in Linux/etc/fstab/etc/mtab/proc/mounts partition table location