repair filesystem (chkdsk /f)

 

Overview

before trying any of this, you can probably fix your system better (if you are using a hard disk only, especially bigger ones) if you are using $89 grc.com's spinrite at level 3 (level 1 for SSD's). it recovers marginal sectors and treats the hard disk as analog data, works with SMART and tries very hard at recovering your data and works for hard disks and SSDs. if you can't afford this, or you are using a hybrid disk (not sure how well this would work with spinrite), then these methods below may work OK and getting some sense of normality. maybe. spinrite moves data off of marginal sectors and marks the blocks as bad. he said that if all hard disk drives included the same software he designed on their drives, drives would cost $1k (don't know how long ago that was).

do a chkdsk /f /r (fix filesystem with bad blocks check) every 3-6 months or repair filesystem after turning off the computer hard (without shutting down), especially if you have filesystem corruption as just mentioned (hardware doesn't seem to be working). here's how.

with DOS it doesn't matter about turning off the computer unless you happen to be writing to the disk at the time you are turning off the computer. but with other OS's, it matters!

I have recently discovered that, at least with Windows XP, it may make a difference if you defrag after repairing the filesystem (the cmd-shell method to repair is chkdsk /f c:). I believe this is because of the reasons specified in the videos on the spinrite web site, growing bad block areas on the disk - bit rot (entropy). defrag simply moves the data blocks around to different, new places, and simply might mask the defects - or mark some more as bad. this basically hides the problem. my guess is for a hard disk, that you are still running into the bit rot problem grc.com talks about (and I have experienced) and you still should get spinrite and run it every 3 months (without disk caching enabled!).

you do not want to defrag if you have an SSD or hybrid drive on that drive letter, a defrag will shorten its lifespan. SSD's have a limited number of Program/Erase cycles per block. those are spread out and it's called wear leveling, but writing over the whole disk you run into the limit of a certain amount, like 200TB on a 240GB drive.

you also should not defrag if you have a screen saver enabled, or power settings for turning off the monitor enabled. this will continuously interrupt defrag. there should be zero background processes running if at all possible. kill all the notification area icons that you can that are applications, gadgets, etc. nothing should be running.

for some cases like where you have a blue screen and you want to try one last time to repair the filesystem to see if that will make a difference before reinstaklling your OS, you will probably need a hard drive dock or usb hard drive interface (see navigation above).

DON'T DEFRAG on XP with a Service Pack of 2 or BELOW if you have sata drives, will cause file corruption. there is a patch for this, KB971715 which is in SP3.

MSDOS/FreeDOS/OpenDOS/other DOS

DOS doesn't get messed up too often. by default, it uses no disk caching and it's pretty stable - writes just go to disk and don't do anything special. if you are not using a disk cache like smartdrv, you can just power off the computer or hit the reset button.

MS-DOS and I maybe IBMDOS2000 have no provision for fixing the filesystem. If it's hosed you're out of luck.

FreeDOS has a number of filesystem fixing tools. FreeDOS uses I think 3 different filesystems, FAT12, FAT16, and FAT32. that program would have to support those. and the FAT32 is not a normal version of FAT32, it's modified I hear.

so that means if it messes up your filesystem, I am warning you beforehand (and so does the documentation). it would be your own fault.

with DOS it matters about rebooting the computer, because the OS doesn't know about what you are doing to the filesystem. it MIGHT have something cached in memory if you are using smartdrv. read the smartdrv manual on how to flush the cache, stick it in a batch file and call it shutdown.bat. I like to do this as a safety precaution after modifying the filesystem from underneath the OS's feet. fixing the filesystem or defragging is like pulling the rug out from underneath your feet, at least to the OS, and it needs to be restarted. these utilities seem to directly modify the disk, especially since there are no OS hooks to fix the filesystem.

I *think* these tools work with FAT16 as well as FreeDOS' FAT32.

  1. in freedos: fsck.exe -cd -cf or chkdsk.exe /f c: (chkdsk is currently at version 092 as of 4/15/2012 and very windows-NT/xp/2000/vista/7/8-like). msdos does not have any of these tools, sorry. IBMPCDOS2000 might have something -see help or info. there are 2 kinds of scandisk.exe, and diskscan.exe as well in freedos also. I really don't know which is the preferred method.
  2. ctrl-alt-del or do your usual shutdown procedure (especially if you have disk cache) as a safety precaution.
  3. defrag.exe if you have freedos. this program can use the mouse and it has a TUI, F1 for help.
  4. ctrl-alt-del or do your usual shutdown procedure (especially if you have disk cache) as a safety precaution.

9x/ME

I highly suggest you first read defragging virtual memory. the idea is to basically disable Virtual Memory, chkdsk /f, defrag, and then turn your Virtual Memory back on with its original settings (write them down). Unless you were having problems with "out of virtual memory" errors before at some point, I would suggest you do this if yo uhave a lot of thrashing. If you have LOTS of RAM, you don't need Virtual Memory and you can if ignore this paragraph.

  1. hit f8 repeatedly during boot immediately after memory count (if you have one, else just press repeatedly during logo screen) like mad during boot and do one of 2 things: ...
    1. ...choose safe mode.
    2. start, control panel, display,screen saver, disable the thing completely!!! it will interrupt scandisk and defrag forever!
    3. double-click My Computer
    4. right click on c:, pick properties
    5. Tools tab
    6. check now
    7. turn on "Automatically fix file system errors" (the other is purely optional,turn it on if your disk is 5 years old or more and consider replacing/upgrading the drive using fssdev.com's casper 7.0 iso - you must also buy $60 windows version to have $10 bootable iso)
    8. click OK
    9. definitely reboot if it asks!
    10. F8 repeatedly to go back into safe mode again.
    11. double-click My Computer again
    12. right click on c:, pick properties again
    13. Tools tab again
    14. click Defragment Now... (this will make your deleted files inaccessible, by the way)
    15. start, control panel, display, screen saver, re-enable the screen saver if you still want it.
    16. restart or shut down
    1. ...choose safe mode msdos prompt
    2. type in scandisk.exe /autofix /all and hit Enter
    3. exit
    4. ctrl-alt-del
    5. shut down
    6. NOTE:defrag should NOT be done within safe mode command prompt. it should be done from safe mode.

2000/xp

I highly suggest you first read defragging virtual memory. the idea is to basically disable Virtual Memory, chkdsk /f, defrag, and then turn your Virtual Memory back on with its original settings (write them down). Unless you were having problems with "out of virtual memory" errors before at some point, I would suggest you do this if you have a lot of thrashing. If you have LOTS of RAM, you don't need Virtual Memory and you can ignore this paragraph and simply tunr virtual memory off.

you do not want to defrag if you have an SSD or hybrid drive on that drive letter, a defrag will shorten its lifespan in a hurry.

  1. close any open programs/windows and things in the notification area/system tray
  2. start, control panel, display,screen saver, disable the thing completely!!! it will interrupt scandisk and defrag forever! this includes things like 20-minute lock screens, monitor blackouts after time period, anything that could trigger any program on a time event. these will cause defrag/optimize to restart from the beginning, over and over.
  3. [windows-logo-flag-key]-E
  4. start, My Computer
  5. right click on c:, pick properties
  6. Tools tab
  7. Error Checking, check now
  8. turn on "Automatically fix file system errors"
  9. every 3 months or so (once a quarter), additionally check "Scan for and attempt recovery of bad sectors".
  10. click start.
  11. if it asks to "force a dismount", click cancel.
  12. if it asks to "schedule disk check", click "schedule disk check".
  13. definitely reboot if it asks! in any case, reboot now that it's done so the disk check will occur.
  14. close any open programs and things in the notification area/system tray
  15. go back into safe mode, except this time f you see a defrag option in that same tools tab, use it.
  16. close any open programs and things in the notification area/system tray
  17. [windows-logo-flag-key]-E
  18. start, My Computer
  19. right click on c:, pick properties
  20. Tools tab
  21. Defrag
  22. Analyze
  23. Choose Defrag, even if it says you don't need to (this will make your deleted files inaccessible, by the way)
  24. wait for it to finish, could be 8 hours.
  25. click close and any OK buttons.
  26. restart the computer as a safety precaution!
  27. right click the desktop, properties,personalization, screen saver OR start, control panel, display, screen saver. re-enable the screen saver if you still want it. also go into power settings and if you want that, do the monitor power turnoff after x minutes of inactivity.

vista/7 [work in progress]

I highly suggest you first read defragging virtual memory. the idea is to basically disable Virtual Memory, chkdsk /f, defrag, and then turn your Virtual Memory back on with its original settings (write them down). Unless you were having problems with "out of virtual memory" errors before at some point, I would suggest you do this if you have a lot of thrashing. If you have LOTS of RAM, you don't need Virtual Memory and you can ignore this paragraph and simply tunr virtual memory off. [4/1/2014 I just found a bug in windows 7's virtual memory, it causes the system to become flaky. turn iot OFF. replace and max out the RAM.]

you do not want to defrag if you have an SSD or hybrid drive on that drive letter, a defrag will shorten its lifespan in a hurry.

  1. close any open programs/windows and things in the notification area/system tray
  2. start, control panel, display,screen saver, disable the thing completely!!! it will interrupt scandisk, defrag/chkdsk/autochk and defrag forever! this includes things like 20-minute lock screens, monitor blackouts after time period, anything that could trigger any program on a time event. these will cause defrag/optimize to restart from the beginning, over and over.
  3. [windows-logo-flag-key]-E
  4. start, My Computer
  5. right click on c:, pick properties
  6. Tools tab
  7. Error Checking, check now
  8. turn on "Automatically fix file system errors"
  9. every 3 months or so (once a quarter), additionally check "Scan for and attempt recovery of bad sectors" if your system is slow.
  10. click start.
  11. if it asks to "force a dismount", click cancel.
  12. if it asks to "schedule disk check", click "schedule disk check".
  13. definitely reboot if it asks! in any case, reboot now that it's done so the disk check will occur.
  14. this process can take between 30min-24 hours. to avoid screen image burn-in, turn the monitor(s) off during the chkdsk, and turn them on when you want to check them.
  15. close any open programs and things in the notification area/system tray
  16. [windows-logo-flag-key]-E
  17. start, My Computer
  18. right click on c:, pick properties
  19. Tools tab
  20. Defrag
  21. Analyze
  22. Choose Defrag, even if it says you don't need to (this will make your deleted files inaccessible, by the way)
  23. wait for it to finish, could be 8 hours.
  24. click close and any OK buttons.
  25. restart the computer as a safety precaution!
  26. right click the desktop, properties,personalization, screen saver OR start, control panel, display, screen saver. re-enable the screen saver if you still want it. also go into power settings and if you want that, do the monitor power turnoff after x minutes of inactivity.

8/rt/8.1

I highly suggest you first read defragging virtual memory. the idea is to basically disable Virtual Memory, chkdsk /f, defrag, and then turn your Virtual Memory back on with its original settings (write them down). Unless you were having problems with "out of virtual memory" errors before at some point, I would suggest you do this if you have a lot of thrashing. If you have LOTS of RAM, you don't need Virtual Memory and you can ignore this paragraph and simply tunr virtual memory off.

you do not want to defrag if you have an SSD or hybrid drive on that drive letter, a defrag will shorten its lifespan in a hurry.

  1. close any open programs/windows and things in the notification area/system tray
  2. start, control panel, display,screen saver, disable the thing completely!!! it will interrupt scandisk, defrag/chkdsk/autochk and defrag forever! this includes things like 20-minute lock screens, monitor blackouts after time period, anything that could trigger any program on a time event. these will cause defrag/optimize to restart from the beginning, over and over.
  3. [windows-logo-flag-key]-E
  4. right click on c: or whatever your system drive is, pick properties
  5. Tools tab
  6. Error Checking, check now...
  7. check "automatically fix file system errors". it will give you nonsense about not needing a scan. scan anyway.
  8. every 3 months or so (once a quarter), additionally check "Scan for and attempt recovery of bad sectors".
  9. click start.
  10. if it asks to "force a dismount", click cancel.
  11. if it asks to "schedule disk check", click "schedule disk check".
  12. click finish/ok or whatever to close all the dialog boxes when done.
  13. definitely reboot if it asks! in any case, reboot now that it's done so the disk check will occur.
  14. [windows-logo-flag-key]-E
  15. back to My Computer
  16. right click on c:, pick properties
  17. Tools tab
  18. Defrag
  19. Analyze
  20. Optimize, even if it says you don't need to or says it has already done it (this will make your deleted files inaccessible, by the way)
  21. wait for it to finish, could be 8 hours. a 34GB disk gets done in 8 minutes.
  22. click close and any OK buttons.
  23. restart the computer as a safety precaution!
  24. right click the desktop, properties,personalization, screen saver OR start, control panel, display, screen saver. re-enable the screen saver if you still want it. also go into power settings and if you want that, do the monitor power turnoff after x minutes of inactivity.

OR do the admin-cmd-shell-shortcut route (I like this better because I get the option to do fix bad blocks):

  1. hit the [windows-logo-flag-key] to switch to the desktop
  2. create "admin cmd shell" shortcut on desktop:
    1. right click on the desktop, New, Shortcut
    2. type in %comspec%
    3. name it admin cmd shell
    4. right click on the shortcut, Properties
    5. click Advanced, check Run as Administrator, click OK.
    6. click OK.
  3. double-click the shortcut. you are now running the admin cmd shell (has admin permissions).
  4. type chkdsk /f /r %SystemDrive% [Enter] or if the SystemDrive is c:, just chkdsk /f /r c: [Enter]. at this point, you will have to wing it.
  5. if windows asks to dismount the volume, tell it no (bad idea, other programs are obviously using/locking files in that filesystem or have files open!).
  6. if windows asks to do the disk check on next reboot, tell it Y
  7. should have quit now. you can process your other drives but not SSD's!).
  8. restart the machine via windows [windows-logo-flag-key]-I, power or do shutdown -r -f -t 0 in the cmd shell.
  9. wait 30min to 24 hours, whatever, until it's done, will reboot twice. turn off the monitor to avoid screen image burn-in.
  10. when windows boots up normally:
  11. [windows-logo-flag-key]-E
  12. back to My Computer
  13. right click on c:, pick properties
  14. Tools tab
  15. Defrag
  16. Analyze
  17. Optimize, even if it says you don't need to or says it has already done it (this will make your deleted files inaccessible, by the way)
  18. wait for it to finish, could be 8 hours. a 34GB disk gets done in 8 minutes.
  19. click close and any OK buttons.
  20. restart the computer as a safety precaution!
  21. right click the desktop, properties,personalization, screen saver OR start, control panel, display, screen saver. re-enable the screen saver if you still want it. also go into power settings and if you want that, do the monitor power turnoff after x minutes of inactivity.

Mac OS X

Socks is a shareware system maintenance and repair utility program. use it to fix your volumes. also, this pdf from Apple talks about how to schedule "repair a volume" using cron.

fix bad blocks on mac/*nix using commandline

refresh disk utility

UNIX/linux/bsd/bsdi/*ix/debian

Actually, with ubuntu and most linuxes, and modern kernels, these steps are not necessary anymore! especially if the filesystem is a journaling filesystem, like efs3, efs4, jfs, btrfs. it fixes itself. sorry, ntfs-3g from tuxera.com which everyone wants to use is not so automatic - requires special ntfs3g commands.

boot a livecd. start an xterm. list the devices you have using ls /dev/sda* then mkdir a directory under /mnt/ such as mkdir /mnt/c then mount -t ext4 /dev/sda1 /mnt/c then see if you can do the following commands safely:

su root (enter password)
sync;sync;fsck
exit

WARNING: THE ABOVE IS NOT A SAFE METHOD FOR *NIX. linux auto-fixes its ext4 [not sure about any other journaling] filesystem.

Th real test is to see if your *nix distribution survives after disconnecting power. I have not tried pulling the plug on other OS's yet to see what they do.

fix bad blocks on mac/*nix using commandline

Mac

tools for the job
this is required for laptops only.
gparted partition editor/resizer/mover free
partitioning and mpartition moving/resizing/copying utility
MyDefrag for windows, available from $donate
usb hard drive stuff
apricorn EZ Hard drive upgrade kit, available from apricorn $40
can work simply as a usb universal laptop hard drive bay
kingwin usb ide/sata hard drive interface, available from newegg.com $20
3.5" or 2.5"
IF you need to repair a filesystem, or get your data off of a drive, use this (for drives <= 3TB). for 3.5" drives > 3TB, get the ones below.
Thermaltake ST0018Z Silver River II 2.5" usb2.0 enclosure, available at newegg.com $24.99
6/11/2012. up to 2TB. SATA I/II/II/SSD, ALL capacities. Windows 7/Vista/XP/2003/2000, Mac 10.3 and later. Aluminum. I recommend this for 2.5" only, especially since it handles all disk capacies - nice! won't get old fora long time...
Thermaltake MAX 5, available at newegg.com $47.99
6/11/2012. USB 2.0, SATA I/II/III, Dual 80mm Blue LED Fans, ALL disk capacities. highly recommended!