Can I run fsck or e2fsck when Linux file system is mounted?

last updated in Categories , ,

Q. Can I run fsck or e2fsck command when Linux file system is mounted? Do you advice to run fsck on a live file system? I am using Cent OS.


A. No. Do not run fsck on a live or mounted file system. fsck is used to check and optionally repair one or more Linux file systems. Running fsck on a mounted filesystem can usually result in disk / data corruption. So please do not do it. You have two choices
(a) Take down system to single user mode and unmout system

(b) Boot from the installation CD into rescue mode

(a) Take down system to single user mode and unmout system

Following are steps :
=> Use init (process control initialization ) command to change runlevel 1 (singe user mode)
=> Use umount command to unmount /home file system
=> Run fsck using fsck command

Let us say you would like to run fsck on /home (/dev/sda3):

# init 1
# umount /home
# umount /dev/sda

# fsck /homeOR
# fsck /dev/sda3OR
# e2fsck -y /dev/sda3

(b) Boot from the installation CD into rescue mode

If you are using Cent OS/Fedora Core/RHEL linux, boot from first CD and at boot prompt type linux rescue nomount:
boot: linux rescue nomount

Now make new node for disk and partition 3:
# mknod /dev/sda
# mknod /dev/sda3
# fsck /dev/sda3

# e2fsck -y /dev/sda3

Don’t forget to reboot the system:
# exit;exit
# reboot


Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

38 comment

  1. That advise above worked great. But I used to be able to rub “shutdown -rF 0” to force fsck to run on reboot. But as of Fedora 9 on my i686 32 bit system the -F option is missing. Is there any way to get that option back in the shutdown menue?

  2. No …

    read and suggest flag -n if mounted

    For some filesystem-specific checkers, the -n option will cause the fs-specific fsck to avoid attempting to repair any problems, but simply report such problems to stdout. This is however not true for all filesystem-specific checkers. In particular, fsck.reiserfs(8) will not report any corruption if given this option. fsck.minix(8) does not support the -n option at all.

  3. this is the difference between windows and linux! too many steps to do a very simple task like scandisk, and also i bear the risk of having my data corrupted because of a scanddisk under linux OMG!
    the best thing i’ll do is to take the HD off the machine, scand disk it under windows and back again into the linux machine!

    medieval but sounds much safer!

    1. @akrum:
      1 – The real difference beween Linux and Windows is in troubleshooting: Windows = reboot | Linux = be root
      2 – Even in Windows you can have a Damaged System Disk after checking the disk for errors but Microsoft had never told you
      3 – Why THE F**K you think that if you want to correct sectors and FS errors you have to reboot in Windows and run chckdsk at boot-time? Obviously: you can’t do that on a mounted filesystem – just like in Linux!
      4 – Take the HD off the machine and mount it on a Windows System will notice that Windows cannot recognize the ext2/3/4 or any other Linux FileSystem. Strange, because almost any Linux System can recognize any Windows FS…
      5 – Make sure you have your brain set to “ON” before posting on any Web place…

      1. I love Linux, but I wish people would gets their facts straight about Windows…
        1. Windows = Be admin, use GUI. Linux = be root, find that file… if you’re lucky, someone else had that problem and it’s been documented.
        2. [citation needed]… at worst it continued to boot, but it did tell you and if you need a reminder, it’s in the log right in computer management.
        3. At least Windows can automatically unmount a disk (or partition) that is mounted but isn’t in use (and it will remount once done). In Linux you’d have to do this manually.
        4. Strange, because I can mount ext2/3 just fine in Windows… hmm…
        5. Make sure you have your bias set to “OFF” – and your politeness set to “ON” – before posting anywhere on the Internet, whether on the web or not.

        1. 1 – You can have much infos in online documentation EVEN for Windows, but this is not the point. The point is that Microsoft, just like Apple (or Canonical in Ubuntu) think about a stupid user when building their systems. The system have to KNOW before you even know what to do and how. But when something goes wrong it’s difficult to find a solution since YOU DO NOT KNOW how the system is built.
          2 – If the damaged block contains a system file (ie the kernel or tha boot) you cannot boot the machine and got NO log.
          3 – Yes. I think that Linux can be run by everyone but used only by advanced users.
          4 – Keliaron, I’m not sure you’re telling the truth: Windows CANNOT recognize any Linux Filesystem. On Windows machine you can mount ONLY Fat16/Fat32/ExFAT/NTFS Filesystems.
          If you want your machine to work with other ones you have to provide some additional drivers.
          5 – I think that akrum was too irriverent.

          1. 1 — Except knowing how the system is built only helps you if you can figure these things out yourself anyway; Otherwise, the end effect is the same. There’s a reason Linux is still not popular.
            2 — I was talking about when it does boot; when it doesn’t you get different symptoms that are in most cases visible onscreen (sometimes, though, you get no indication as to what the problem is). (By the way, if Linux can’t boot, you don’t get a log either – only what’s onscreen.)
            3 — Sadly, that’s the problem.
            4 — You are correct that *stock* Windows cannot. However, there are reliable drivers for ext2/3.
            5 — People may say stupid, uninformed, or mean things.. but in the end they’re just opinions. Don’t let it get to you.

            1. 1 – I can agree a little bit, but I think that Linux is not popular for million reasons else.
              2 – Yep, sure.
              3 – Yep, again.
              4 – You can mount Ext partirions in Windows only if you install the relative drivers.
              5 – There’s a big difference from a statement and an opinion. If one just give his opinion, that’s right, but if he make a stupid statement I fell the moral right to reveal the stupidity of its statement.

              1. 1 – I didn’t mean _literally_ one reason.
                4 – I don’t see how this is a problem. Windows and Mac (excluding the App Store *shudder*) have no package manager, thus lacking this, what would you do (aside implement one)? People already complain that they’re too fat after being installed (so you can’t include everything including the kitchen sink), nobody wants to stick the install disk in to install drivers (so you can’t do the above *without* wasting disk space), and everyone wants everything available now, now, now.

    2. That actually sounds insane and Linux fsck is much more consistent and accurate and advanced than windows scandisk. As well is the linux file system (choose one but default to ext3/4 to be normal) itself which is light years ahead of the trash called ntfs.

  4. @akrum This will actually not work at all. Windows scandisk will not recognize a Linux filesystem. What you are describing is actually the least safe option. Good luck with that.

    1. @ lekensteyn
      umount is the original command. some systems have an alias called unmount, but it calls umount

  5. when i start the computer Centos (2.6.18-53.1.19.e15) boot normally and hang up after
    Mounting local filesystems: [ OK ]
    Enabling local filesystems: [ OK ]
    and cursor jam and keyboard lights on/off contineously

    please resolve my problem

    Khalid Zaidi

    1. Try to start you PC with a live distro: if it works it’s a system issue, if it doesn’t it’s an hardware issue.

    2. Those keyboard lights going on/off indicate what’s referred to as a “Kernel oops” – equivalent to a Windows bluescreen. Try to get a log somehow – maybe (maybe) another VT is enabled at that time, and you could e.g. hit alt-f8 to switch to it and get more verbose information. Or maybe use interactive mode. I don’t remember if CentOS has that.
      Like the others have suggested, try booting another system; A liveCD of CentOS if you can.. you might get more information. Maybe the drive is corrupt or your /etc/fstab is incorrect.

  6. akrum does have a bit of a point.

    At least with Windows they’ve tried to be helpful. All you have to do is say that you’d like this disk checked before the next boot and restart the PC.
    It may not be as good a check as fsck (taking your word for it), but at least it’s quick.

    I don’t see any reason for not providing this functionality in Linux – Is there one?
    Why does it have to be awkward just because it’s Linux?

  7. From my dmesg.txt file the following issuses were noticed:
    [ 2.374562] EXT4-fs (sda1): mounted filesystem with ordered data mode. Opts: (null)
    [ 18.058424] udevd[253]: starting version 173
    [ 32.953222] EXT4-fs (sda1): re-mounted. Opts: errors=remount-ro,commit=0
    [ 117.531547] wlan0: authenticate with 08:76:ff:50:3b:bd (try 1)

    I’m new to Ubuntu and have been advised to fsck my system partitions in liveCD. Also to check If the bootable drive is SATA, then try putting it into ‘IDE compatibility mode’ in BIOS.
    Kindly let me have instructions on how to do this. I would be most grateful for your kind help.

    1. I don’t understand; What’s the problem? All of those seem fine to me. If you’re wondering about the “errors=remount-ro”, that just means that *if* there are errors, that filesystem will be remounted as read-only (instead of unmounted completely, I suppose?).

  8. Thanks for your kind response. As my bootable drive is SATA, is it possible to try putting it into ‘IDE compatibility mode’ in BIOS? If possible kindly advise further.
    Thanks again and kind regards

    1. I just noticed that the log messages you posted did in fact say “remounting”, so perhaps there *is* a problem. At any rate I’m not sure IDE compatibility mode will help you, but I suppose it’s worth a shot.
      Yes, you *probably* can change it in your BIOS, but there’s no guarantee. You’ll have to look around.. it might be under the drive configuration, under chipset configuration, or buried somewhere else… or your BIOS might not have the option at all.
      If you have a manual for your motherboard/BIOS, I would look it up there first as it will probably make it easier to find.

  9. Kindly advise if the following procedure to take down system to single user mode and unmout system works on Ubuntu 12.04:

    => Use init (process control initialization ) command to change runlevel 1 (singe user mode)
    => Use umount command to unmount /home file system
    => Run fsck using fsck command

    Kind regards

  10. Hi may have expressed it in a horribly inflammatory way but I think he’s right. Scandisk or chkdsk is so much easier than checking file systems on Linux, it is incomparable.

    I swear in the olden days Linux (gawd knows which flavour) had a similar sort of option to scandisk or chkdsk. It worked very well. Why they ever got rid of that is only something pure Linux zealots can relate to.

    1. Maybe only that flavour had it, and that program got lost in time. I don’t suppose you remember the name of the program by any chance..?

  11. There IS a linux app with a GUI for that, its called gParted. Its kind of like partition magic for windows except its free and does a whole lot more.

    1. Answers like this are why the problem doesn’t get fixed…

      First off, you’re ignoring the fact that part of the deal with this article is how to do it with your root FS, i.e., the one that is (almost) always mounted rw. You can’t just fsck it, with gparted or otherwise. In fact, gparted refuses to operated on any mounted partitions and the only option it gives you is to completely unmount it!
      Second, you still can’t schedule it easily — gparted will not do this for you (even though (at least I seem to recall) it is a flag stored in the FS metadata — assuming, of course, the system boot will pay attention to it, which is based on what’s in fstab).
      As for your other comment to use a live distro — you’re missing the point even further. Really, if you need to get, setup/burn/whatever, reboot into, and remain in that separate distro, that’s a lot of extra work. If you could simply right-click on a partition and select “Scan for errors on start” . . . that would be a step forward into .. what, 1984? While scandisk (and the need for it) was annoying, at least it existed and did correct (most) errors.

  12. Just use gParted on linux. There is even a live distribution with gparted and some other disk utilities designed to recover filesystems on just about any system.

  13. That comment was in reply to Keilaron’s post, not the main article so I excuse your poor post. And I accept your apology in advance.

  14. Boot server into: init=/bin/bash

    fsck -yC /dev/sd* (* is whichever is the partition you wish to run the fsck on)

    Reboot server and done.

    Still, have a question? Get help on our forum!