pwd.db/spwd.db file corupption when having unsafe system poweroff
freebsd at edvax.de
Sun May 5 07:19:03 UTC 2013
On Sun, 5 May 2013 10:42:02 +0430, takCoder wrote:
> i added fsck_background=no to rc.conf but i still see the error.. and i
> don't see any differance in system startup output! how should i know it's
Please check the correct syntax for the /etc/rc.conf entry:
See /etc/defaults/rc.conf for the correct syntax example.
This will cause the system to perform a fsck _prior_ to
bringing up multi-user mode. In case of severe errors that
cannot be corrected by fsck without heavy modification of
a file system (and therefor _may_ cause data loss), it will
direct the decision to the operator and ask. In such a case,
# fsck -yf <filesystem(s)>
can be used, but read "man fsck" and "man fsck_ufs" for what
the options -y and -f do, and if it is what you _intend_.
> > Alternatively to pw, you could try adduser, which is more
> > an interactive program, but can perform the same tasks.
> > Again, it would take care of updating all required files.
> > This is the situation one would expect after the program
> > ended, or at least some seconds after one got back to the
> > root prompt.
> when i tried using adduser, when a error occurs(like multiple definition of
> a username), it's pw who reports the errors! it means that adduser also
> uses pw.. is this functionality of "taking care of updating all required
> files", an add-on appeared in add-user??
That's correct. Have a look as /usr/sbin/adduser: It is
actually a shell script, and it calls /usr/sbin/pw to
add entries. Running pwd_mkdb at any time can be used
to make sure all data is in the correct format and valid.
> > During the 2 minutes, you could use programs like lsof
> > (it's in ports) to check if a program has a file open,
> > so you could capture the "power off while writing to
> > file" incident.
> i tried using lsof as well , but there was no differance.. yes! when i use
> pw -h 0 parameter, 10 extra files are added to the lsof list.. but exactly
> after i enter the password, all of them are closed(none of these files are
> of those main 5 files of users..lib files and alike..).. and in later
> monitoring with lsof, i could not catch the time when these files are in
> use!.. i'll write a shell to monitor it more detailed though..
That would be a good idea. However, after the program finishes
and returns you to the shell prompt, no files should be left
open. At program exit, all files will be closed (part of the
exit routines "automatically" performed).
> > After you could not login again, did you check the
> > files involved in the login process?
> yes, file sizes are ok but pwd.db and swpd.db are out of use..(also once i
> opened passwd with nano and it had irrational characters..).
That's not good. Such a file inconsistency should not exist.
> always if i
> use pwd_mkdb or just replace these two files, in next startup system will
> come up fine!
So something damages those files. Not good.
> now there is something special about my own servers, which i'm suspicious
> i've add an executable file to my /usr/local/etc/rc.d dir, which tries to
> initiate some parts of myserver.. this includes usernames as well.. i mean,
> i may have template users during system uptime, which i won't need in next
> startup.. this initiliazer will remove those unwanted users and redifine
> main usernames, using pw..
If you intend to have "user templates", you can use the /usr/share/skel
(or /etc/skel or even /usr/local/etc/skel directories; adduser defaults
to /usr/share/skel, and pw has -k <directory> for a different location).
This means you can have multiple templates that you do not need to
instantiate unless you create an actual user. Just an idea.
> it works fine while having safe shutdowns but when i have the bug-generator
> scenario, it won't work.. may it be the conflict of running my initializer
> and fsck ?
That is possible, that's why fsck should be run _prior_ to doing
anything with (possibly) damaged file systems.
> or is it true that rc.d files are executed in shutdown process
> as well?
This depends on the rc.d files. If they define an action that
should be done at shutdown time, those actions will be called.
Additionally, and keep in mind people will call me old-fashioned
and un-modern for that suggestion:
You can put simple scripting stuff into /etc/rc.local for start,
and /etc/rc.shutdown.local for shutdown. It's still supported
and it works. For "stuff that is too simple to deserve a real
rc.d script", those files can be used.
> is shutdown process started when i start pressing power button for
> 4 seconds??
No. In this case, the system will be _forcedly_ powered off, no
shutdown procedures (performing rc.d shutdown commands, flushing
buffers, unmounting file systems and so on) will take place. It
is _not_ the way to power down a system!
Alternatively, use "shutdown -h now" and _then_ do the "pull the
Of course, "shutdown -p now" is more convenient if you intend to
power down your system.
If your power button acts properly (check BIOS settings!), press
it for just a moment. The system will then perform "shutdown -p now"
and bring the system down properly.
> i don't know what else to think of...
First I'd suggest to perform a SUM boot and run fsck. Then check
the files in /etc if they are damaged. Furthermore, keep calm and
carry a towel. :-)
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
More information about the freebsd-questions