From owner-freebsd-questions@FreeBSD.ORG Sun May 5 07:19:03 2013 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id AB398830 for ; Sun, 5 May 2013 07:19:03 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mx02.qsc.de (mx02.qsc.de [213.148.130.14]) by mx1.freebsd.org (Postfix) with ESMTP id 57E4A282 for ; Sun, 5 May 2013 07:19:03 +0000 (UTC) Received: from r56.edvax.de (port-92-195-26-233.dynamic.qsc.de [92.195.26.233]) by mx02.qsc.de (Postfix) with ESMTP id 11C7E279F5; Sun, 5 May 2013 09:18:55 +0200 (CEST) Received: from r56.edvax.de (localhost [127.0.0.1]) by r56.edvax.de (8.14.5/8.14.5) with SMTP id r457J4Au007059; Sun, 5 May 2013 09:19:04 +0200 (CEST) (envelope-from freebsd@edvax.de) Date: Sun, 5 May 2013 09:19:04 +0200 From: Polytropon To: tak.official@gmail.com Subject: Re: pwd.db/spwd.db file corupption when having unsafe system poweroff Message-Id: <20130505091904.1cf8cda4.freebsd@edvax.de> In-Reply-To: References: <20130417173544.25266cd6.freebsd@edvax.de> <20130501110147.c69f408b.freebsd@edvax.de> Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: freebsd-questions@freebsd.org X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Polytropon List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 05 May 2013 07:19:03 -0000 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 > working?? Please check the correct syntax for the /etc/rc.conf entry: background_fsck="NO" 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 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 > of.. > 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 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 plug" trick. 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. :-) -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...