Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scheduling ChkDsk & Defrag?

Status
Not open for further replies.

cpjust

Programmer
Sep 23, 2003
2,132
US
Hi,
I'm trying to write a batch file that I can use to schedule automatic CHKDSK and DEFRAG of my disks, but I'm having some problems.
Here is my code:
Code:
@ECHO OFF
SETLOCAL


IF "%1"=="" GOTO Syntax

@ECHO =====================================================================
@ECHO %0 started at the following date and time:
DATE /T
TIME /T
@ECHO =====================================================================


:LoopStart
@ECHO ========================= Checking drive %1 =========================
CHKDSK %1 /V

IF ERRORLEVEL 1 (
   @ECHO ********** CHKDSK returned Error Level = %ERRORLEVEL%
   @ECHO ********** Errors found on drive %1 !!  Re-Running CHKDSK with /F /R switches.
   CHKDSK %1 /F /R /V
) ELSE (
   @ECHO ==================== Defragmenting drive %1 ====================
   DEFRAG %1 -V
)

SHIFT
IF NOT "%1"=="" GOTO LoopStart

@ECHO =====================================================================
GOTO End


:Syntax
@ECHO Syntax:  %0 {drive} [{drive}...]
@ECHO .
@ECHO Example:  %0 C: D: E:


:End
ENDLOCAL
The first problem is that I cannot tell CHKDSK to fix errors on the C: drive because it's being used by Windows, so it prompts me whether I want to schedule it during my next boot...
Since it's running in a batch file, nobody will be there to press Y or N. Is there a way to automatically default to Y?

My next problem is checking the return code from CHKDSK. For some of my disks it returns 0; but for others it returns 2 which appears to mean a Warning, but not an Error; then sometimes I see an ERRORLEVEL of 3 when there are actual Errors found. Does anyone know what all the return codes are for CHKDSK and what they mean (how serious they are)?

I get this problem on the C: drive:
Code:
C:\>CHKDSK c: /V
The type of the file system is NTFS.
Volume label is Main_OS.

WARNING!  F parameter not specified.
Running CHKDSK in read-only mode.

CHKDSK is verifying files (stage 1 of 3)...
File verification completed.
CHKDSK is verifying indexes (stage 2 of 3)...
Index verification completed.
Detected minor inconsistencies on the drive.  This is not a corruption.
CHKDSK is verifying security descriptors (stage 3 of 3)...
Cleaning up 3 unused index entries from index $SII of file 9.
Cleaning up 3 unused index entries from index $SDH of file 9.
Cleaning up 3 unused security descriptors.
Security descriptor verification completed.
[b]Correcting errors in the Volume Bitmap.
Windows found problems with the file system.
Run CHKDSK with the /F (fix) option to correct these.[/b]

  20482874 KB total disk space.
   4613528 KB in 30927 files.
      9340 KB in 2818 indexes.
         0 KB in bad sectors.
    100750 KB in use by the system.
     65536 KB occupied by the log file.
  15759256 KB available on disk.

      4096 bytes in each allocation unit.
   5120718 total allocation units on disk.
   3939814 allocation units available on disk.

C:\>ECHO %ERRORLEVEL%
3
But no matter how many times I run CHKDSK with /F /R (and reboot), the problem still appears.
I did some research about this problem and found lots of webpages talking about it. From what I can tell, it's an NTFS bug, Microsoft has no idea how to fix it, and they tell everyone to just ignore it because it's not a real problem...
Well that's what I'd like to do -- just ignore it; but it also returns ERRORLEVEL 3 which it what I get when CHKDSK actually finds "real" problems on the disk. So how can I automate CHKDSK and tell it to ignore the above error, but to re-run with /F /R for real problems?
 
I think you should fix this corruption problem.To automatizating a script is not the real solution.If the problem reoccurs continuous this would indicate that chkdsk cannot fix the problem.

There some newer versions available from chkdsk.You can try it with the newer versions.

What events are registered for this problem ?
Are you using 2003 with SP1 or w2k ?
I think you are using an old version of chkdsk ?
Are you ever loose your ACL's ?

Regards,
Cengiz Kuskaya
 
There are no events logged for this.
Actually, the output I posted above was from an XP Pro SP2 box, but I've seen the same thing on Win2000 & 2003 servers as well.
Can I download the latest chkdsk from somewhere?
I'm not sure what you mean about my ACL's?

Here are some of the pages I found about this problem:
[ignore][/ignore]
 
Before chkdsk, be sure there are no viruses on system.
On some systems you need to run chkdsk /f many times to correct all problems. It is better to boot in recovery console and run chkdsk from there, it is faster because you should not reboot every time.

===
Karlis
ECDL; MCSA
 
ACL is the Access Control List.

The following fix looks great KB831374.You can request it over the Microsoft Support Center.

Regards,
Cengiz Kuskaya
 
Just make sure you're not trying to run that over a partition with a database running on it, like Exchange or SQL.

Pat Richard, MCSE MCSA:Messaging CNA
Microsoft Exchange MVP
 
Well the XP machine does have MS SQL 2000 running on it. What should I do in that case?
 
Make a backup and also an image of your pc.After that you can install the fix and try to repair it again with chkdsk.exe

Regards,
Cengiz Kuskaya
 
BTW, the KB article says the problem happens when:
KB831374 said:
This problem occurs because the Chkdsk utility may not find references to all the security IDs if the master file table is larger than 4 gigabytes (GB) or if there are more than 4,194,303 files on the volume.
Since my system has nowhere near 4 million files or 4GB "in use by the system", does this fix still apply to me?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top