PDA

View Full Version : /etc/mtab out of sync



onemyndseye
01-10-2007, 11:38 AM
I've ran into this before on another distro. But for the life of me I cant remember the fix..

The root of the problem is I suppose that when things are umounted they are not removed from the mtab... so after awhile you end up with a mtab thats stuffed full of mount entries. I tried to "band-aid" this by ' echo "" >/etc/mtab ' at startup followed by ' ./etc/init.d/mtab.sh start ' after all filesystems where setup...

This sort of fixes the problem except its still alittle out of sync.... for instance my root is /dev/sda1. But this entry is not present in mtab... so ofcoarse the system reports /dev/sda1 as unmounted.

All and all this is a small problem for me since this is just a portable system that I use away from home..... but still an anonyance.

Any ideas?... hrmm.. maybe just ` ln -s /proc/mounts /etc/mtab ` ?

Thanks,
-Justin
One Mynds Eye

mrsalmonella
01-12-2007, 07:27 AM
The hack I came up with (following also the ISO boot thread with ruymbeke's binaries) is to tack onto linuxrc in minirt.gz the following just before the call to exit():

# SMartin - HACK below just forces unmount of ntfs drive
# we are booting from (if we are booting from one)
# and gets mtab back in sync if its messed up.
/sbin/umount.ntfs ${LOOP_SOURCE} > /dev/null 2>&1
cat /proc/mounts > /etc/mtab



Good luck.
I can provide a minirt.gz for you if need be.

onemyndseye
01-12-2007, 09:56 AM
Thanks for the reply :)

That works very well for rebuilding a mtab from scratch but still the root of the problem lies in the mtab NEVER being updated by umount (maybe a bug in umount but I doubt it). So umounted drives are simply left in the mtab to collect until the user clears the file and rebuilds it.

I didnt notice for afew days after installing 5.1... I issued ' mount ' just to check to see what was mounted and got a screen full of stuff ....LOL

From what I've been reading gthe past few days alot modern distros are moving away from a file based mtab to a simple symlink to /proc/mounts since its basicly impossible from /proc/mounts to get out of sync since it is the kernels view of the mounted filesystems....

I tried this and its working quite well except for one very small issue I've found so far.

I have a smiple bash script called " diskfree " that parses the output of ' df ' and returns it in a nice, readable format.


#!/bin/sh

DISC=$1

if [ "$DISC" ]; then
CHECK=`mount | grep $DISC ` ;
if [ "$CHECK" ]; then
PARTITION=`df -h |grep $DISC |awk '{print $1}'` ;
SIZE=`df -h|grep $DISC|awk '{print $2}'` ;
USED=`df -h|grep $DISC|awk '{print $3}'` ;
FREE=`df -h|grep $DISC|awk '{print $4}'` ;
echo "Partition: $PARTITION" ;
echo "Total size: $SIZE" ;
echo "Used space: $USED" ;
echo "Free space: $FREE" ;
else echo $DISC is not mounted or does not exist!
fi
else echo "You must specify a device. (Example: /dev/hda1)"
fi




if I issue ` diskfree /dev/sda1 ' i get:


onemyndseye@exodus:~$ diskfree /dev/sda1
df: `/dev/.static/dev': Permission denied
df: `/dev/.static/dev': Permission denied
df: `/dev/.static/dev': Permission denied
df: `/dev/.static/dev': Permission denied
Partition: /dev/sda1
Total size: 17G
Used space: 11G
Free space: 7.0G
onemyndseye@exodus:~$


Or ` df ` .... I get:


onemyndseye@exodus:~$ df
Filesystem 1K-blocks Used Available Use% Mounted on
rootfs 17823516 10491092 7332424 59% /
udev 10240 88 10152 1% /dev
/dev/sda1 17823516 10491092 7332424 59% /
df: `/dev/.static/dev': Permission denied
none 147456 0 147456 0% /dev/shm



But the little burp goes away if issued by root:


root@exodus:/home/onemyndseye# df
Filesystem 1K-blocks Used Available Use% Mounted on
rootfs 17823516 10491092 7332424 59% /
udev 10240 88 10152 1% /dev
/dev/sda1 17823516 10491092 7332424 59% /
/dev/sda1 17823516 10491092 7332424 59% /dev/.static/dev
none 147456 0 147456 0% /dev/shm



This may can be fixed by reconfiguring udev in some way but unfortunatley my experience is limited with udev itself..... If you ` chmod 0755 /dev/.static ` it goes away all together...... But I do not know is this is a sane fix :).... also this fix does not persist across a reboot for me....so it would have to be added to a script to-be-exec'ed at bootime.

Take Care,
-Justin
One Mynds Eye