My blog has moved!

You should be automatically redirected. If not, visit
http://benohead.com
and update your bookmarks.

Sunday, October 16, 2011

Check the file system of the root partition

Because running fsck to repair a file system which is mounted for read/write operations can potentially cause severe data corruption/loss, the file system is normally checked while unmounted, mounted read-only, or with the system in a special maintenance mode that limits the risk of such damage.

When checking the file system of the root partition, it's not an option to unmount it. So basically we have two solutions: have it checked when booting or mount it read-only.

File system check during the next boot

Linux checks while booting whether the file /forcefsck exists. If it finds this file, a file system check is started.

In order to create this file, you can either shutdown using:
shutdown -F
or create the file manually e.g. using:
touch /forcefsck 

File system check on read-only root partition

First you should get in single user mode:
# init 1
Wait until you reach run-level 1. Then remount the partition as read-only:
# mount -n -o remount,ro /dev/sda1
(replace /dev/sda1 by the mount device of your root partition)

Now we can check the file system:
# fsck -fp /dev/sda1
-f: means that we want to force a check.
-p: means that all errors should be automatically repaired.

After the check we can switch back to read/write mode:
# mount -n -o remount,rw /dev/sda1
Now we can switch back to our "normal" run-level:
# init 3
(for command line)
# init 5
(for GUI)

That's it !

No comments:

Post a Comment