LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   What the fsck? How to check a partition that is mounted as readonly? (https://www.linuxquestions.org/questions/linux-newbie-8/what-the-fsck-how-to-check-a-partition-that-is-mounted-as-readonly-773373/)

gr4nt 12-04-2009 12:06 AM

What the fsck? How to check a partition that is mounted as readonly?
 
Reading the manpage for fsck, it cautions against doing a filecheck on a partition that is already mounted. Or that you shouldn't attempt it unless you really know your stuff. Or that if you did attempt fsck on a read-only filesystem, it could be unpredictable.

Yet I'm sure the rootfs get checked sometimes during system initialization. So there obviously is a safe way to do it, I'm just not sure how.

My intention here is not to fsck the rootfs. But if for some reason, another partition besides the rootfs is mounted ro by the initrd, then it may possibly NEVER get checked. e2fsck isn't included in the initrd's busybox environment. And the main rootfs's initialization scripts won't fsck it, coz its already mounted.

So before I dabble, I need to know the safest way to do this.

Thanks.

svinoba 12-04-2009 01:56 AM

I'm not very knowledgeable in these matters but one can safely guess 'rootfs' must be getting 'fsck'ed before it gets mounted. To do 'fsck' on another partition during boot up, you need to edit /etc/fstab. Its the last column.

syg00 12-04-2009 03:44 AM

Mounting ro will have no effect - the fsck will still go ahead.
The fsck warnings are there for you and me - don't do it if there is the possibility of someone accessing the filesystem. Even if they are only reading it. If you have to manually fsck, do it from single user, or (better) from a liveCD.

JZL240I-U 12-04-2009 04:35 AM

Code:

shutdown -r -F now
will force a fsck on all partitions during reboot, i.e. when it is not dangerous.

gr4nt 12-28-2009 03:54 PM

Thank you all for your help.

JZL240I-U 01-04-2010 04:45 AM

You're welcome. But what did you actually do and how did it play out eventually?

gr4nt 01-14-2010 09:20 PM

My original question was regarding a scenario where the initrd mounts a partition as read-only. Where if for some reason, I haven't listed that partition in my fstab, then it isn't automatically fscked. I have been dabbling with a custom initrd for mounting the rootfs as type aufs, so I will spare you the dubious details as to the why...

I guess the helpful answer given was that it is safe enuf to fsck a read-only partition, provided that no other processes are accessing that partition at the same time. Such that fsck is best done by the init-scripts, well before any service daemons get started up.

That said, I settled onto a different solution:- I just changed my partition type to xfs. A helpful post on slax-forums mentioned that xfs partitions are automatically filechecked at mount-time, without needing to use a separate fsck util. Very convenient :-)

But in any case, my current initrd for aufs is now mounting the base partition as read-write. So for filechecking the base partition, I will resort to either using the fstype xfs, or I will need to find myself a busybox for initrd that provides the e2fsck util. So alas, the original question has now become less important, but I am still very grateful for all your helpful responses.

JZL240I-U 01-15-2010 02:31 AM

Hmm. With "tune2fs -c 1" you can change the intervals between checks for the ext file system family. Thus you can force a check during every boot in analogy to my "shutdown -F now" suggestion. The boot sequence (i.e. init) will do it at the right time, too (I think when the partition is not mounted at all, you'd have to verify that, though).

This is not meant to criticize your solution, just a comment...

gr4nt 01-15-2010 11:12 PM

I liked your suggestion on doing the fsck during shutdown...
I think my problem with that is I am doing aufs here. Trying to avoid writing pages of detail here, but the shutdown script for aufs is very different, and makes that plan un-doable.

During startup, I am using a ramdisk-based initrd. Such that even after the main rootfs inits, the initrd is still attached to the filesystem. Not deallocated the way that the cpio-based initramfs does. And this is done intentionally, because I need to use that initrd again during shutdown.

My rc.6 shutdown script is modified, such that instead of halting at the end, a pivot_root call is made back to the initrd. Once back in the initrd busybox system, another cleanup script then umounts the aufs, umounts all the squashfs modules, which were stored on my base partition, and only then, finally, can I actually umount the base partition.

So the shutdown for aufs+squashfs has an extra step that gets in the way of a shutdown-fsck. And my base partition that stores the squashfs modules is actually the very last partition to get umounted. I've basically borrowed the shutdown method used by Slax, and it is quite elegant. But there are other aufs methods out there that use a cpio-based initramfs instead, and must the shutdown differently, but I haven't looked into them yet.

JZL240I-U 01-18-2010 02:00 AM

I see (though I don't understand the details ;)).

Just to make sure there is no misunderstanding: "shutdown -h -F now" makes the system do the fsck during the next (re)-boot, not during shutdown. So if you want to implement (at an other time) fsck during shutdown please keep in mind that this is not the way to do it...

tredegar 01-18-2010 03:54 AM

Quote:

shutdown -r -F now
You need to be aware that the -F option to shutdown was removed from the 'buntus in about 2008, and now does not force a fsck at the next boot.

The same may be true for other distributions. If I need to run fsck, I now have do it from a live CD or USB stick.

JZL240I-U 01-18-2010 04:22 AM

Quote:

Originally Posted by tredegar (Post 3830606)
You need to be aware that the -F option to shutdown was removed from the 'buntus in about 2008, and now does not force a fsck at the next boot.The same may be true for other distributions. ...

Interesting. SuSE 11.0 still has it, I'll have to check in 11.2. Do you know the reason for that removal?

Quote:

Originally Posted by tredegar (Post 3830606)
...If I need to run fsck, I now have do it from a live CD or USB stick.

You could also change the count number or the interval using tune2fs and thus still force a fsck during the next boot.

tredegar 01-18-2010 04:57 AM

Quote:

Interesting. SuSE 11.0 still has it, I'll have to check in 11.2. Do you know the reason for that removal?
No, I don't, but it caught me by surprise! -F is no longer referred to by man shutdown, and is ignored if used. No warning about "-F is no longer supported" either :(
Quote:

You could also change the count number or the interval using tune2fs and thus still force a fsck during the next boot.
Yes, that would be another option.


All times are GMT -5. The time now is 12:01 AM.