Scheduling Boot-time CHKDSK

Posted on 2012-09-02
Last Modified: 2012-09-04
I see very little information out there regarding what I'm trying to do so I took the liberty of trying it out myself, but I want some expert advice before I go and deploy this method to multiple computers.

What I'm trying to accomplish is scheduling CHKDSK to run at next boot on any given machine, this way the system volume can be checked safely and automatically.

What I have learned is that Windows 2003 forces a CHKDSK on all volumes that have the NTFS dirty bit set. What I have also learned is that you can manually set the dirty bit. Now this is where information seems to be non-existent, at least not on the first few pages of google searches.

Is it safe to purposefully set the dirty bit on all local volumes of a computer so that they have to run a CHKDSK at next boot? I have tested this on a virtual machine and it seems that it worked fine, the Event Log shows normal CHKDSK functionality output.

The script I would use would look something like:

c:\windows\system32\fsutil dirty set c:
c:\windows\system32\fsutil dirty set d:
c:\windows\system32\shutdown /f/r

Open in new window

In this example the C: and D: volumes would have their dirty bit set, then a forced shutdown and reboot would occur. Since the dirty bit was set on both volumes Windows Server 2003 performs a CHKDSK /f on both.

If you can, please advise me of the CONS of this method, all I'm seeing are PROS (Which is common when researching something new). Thanks.

P.S. I am unaware if this works on Server 2008/R2/Windows 7 environments. Everything I have researched only talks about Server 2003. (Edit: It looks like I can use "chkntfs /c [drive]" to accomplish this on a newer OS)

Bonus 100 points to the person that can show me how to make a batch file that can run a FOR loop to check for valid drives. (Most likely using 'wmic logicaldisk get name') To avoid having to create hundreds of unique script files tailored to each machine. I'm very bad at FOR loops.
Question by:RADCOMP
    LVL 46

    Accepted Solution

    Actually if your systems have only C: and D: partitions then you do not need to set this dirty bit at all. Simply CHKDSK c:/r and CHKDSK d:/r and during next start it will take care of checking.
    But your method is absolutely ok as well.
    LVL 7

    Assisted Solution

    by:Sumit Gupta
    Basically if you just want to run chkdsk /f or maybe chkdsk /r on bootup every time, you can set it to run when you shut down rather than trying to make it work in HKLM\SYSTEM\CurrentControlSet\Control\Session Manager.

    Here is how:

    Create a file C:\WINDOWS\system32\confirm.txt with JUST y in it.

    Then create C:\WINDOWS\system32\Chkdsk_Reboot.bat with this code in it:

    echo y > confirm.txt
    chkdsk c: /f /x < confirm.txt

    Now if you have XP Pro, or other Pro-level OS'es, open gpedit.msc>Computer Configuration>Windows Settings>Scripts>Shutdown, and add that Chkdsk_Reboot.bat as a shutdown script.

    Next reboot you will run your chkdsk command.

    I am not sure if this will work for XP home since it does not have gpedit.msc. You may be able to create this directory structure and add the batch file there but I am not sure if it will work since Home does not use Group Policy: C:\WINDOWS\System32\GroupPolicy\Machine\Scripts\Shutdown

    Most people want to STOP chkdsk from running at every boot, but still good info for those looking. Here's a fun add-on, you could change your batch file to one line echo y > conf.txt && (chkdsk c: /f /x < conf.txt & del conf.txt) - Then it will only run chkdsk (and in turn delete the conf.txt) if it successfully creates the conf.txt in the first place. :)
    LVL 1

    Author Closing Comment

    Thanks for the feedback guys, I'm still looking for a way to dynamically grab all logical drives using WMIC or something. I'd prefer not to write to text files just to keep things as clean as possible, tho creating a file then having the script delete it later might not be too bad of a plan.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free book by J.Peter Bruzzese, Microsoft MVP

    Are you using Office 365? Trying to set up email signatures but you’re struggling with transport rules and connectors? Let renowned Microsoft MVP J.Peter Bruzzese show you how in this exclusive e-book on Office 365 email signatures. Better yet, it’s free!

    Problem Description: Actually I found the below issue with some customers after migration from SMS 2003 to SCCM 2007 and epically if they change site code, some clients may appear in the console with old site code, plus old sites still appearing …
    Remote Apps is a feature in server 2008 which allows users to run applications off Remote Desktop Servers without having to log into them to run the applications.  The user can either have a desktop shortcut installed or go through the web portal to…
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now