Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Other Things Gentoo
  • Search

fsck - only check, not repair?

Still need help with Gentoo, and your question doesn't fit in the above forums? Here is your last bastion of hope.
Post Reply
Advanced search
5 posts • Page 1 of 1
Author
Message
Zucca
Administrator
Administrator
User avatar
Posts: 4703
Joined: Thu Jun 14, 2007 10:31 pm
Location: Rasi, Finland
Contact:
Contact Zucca
Website

fsck - only check, not repair?

  • Quote

Post by Zucca » Wed Oct 20, 2021 11:38 am

I'm currently improving my initramfs.
I wanted to create a function which checks all the available filesystems if possible.
I want it to be fs agnostic.
Looks like the fsck -command does not have an option to only check filesystems (what? why?!?).

Any clever ways to do check on all available filesystems (no fstab requirement) for errors (but not repair) in busybox shell inside initramfs?
This of course needs external fs utilities, but that's not my concern, I can add more utils. I can even load another cpio which contains them If needed.
..: Zucca :..

Code: Select all

0100100100100000011000010110110100100000
0100111001100001010011100010000100100000
0100100100100000011000010110110100100000
0110000100100000011011010110000101101110
00100001
Top
freke
Veteran
Veteran
Posts: 1136
Joined: Thu Jan 23, 2003 3:17 pm
Location: Somewhere in Denmark
Contact:
Contact freke
Website

  • Quote

Post by freke » Wed Oct 20, 2021 12:33 pm

Code: Select all

Filesystem-specific options
Options that are not understood by fsck are passed to the filesystem-specific checker. These arguments must not take arguments, as there is no way for fsck to be able to properly guess which options take arguments and which don't.

Options and arguments which follow the -- are treated as filesystem-specific options to be passed to the filesystem-specific checker.

Please note that fsck is not designed to pass arbitrarily complicated options to filesystem-specific checkers. If you're doing something complicated, execute the filesystem-specific checker directly. If you pass fsck some horribly complicated options and arguments, and it doesn't do what you expect, you're almost certainly doing something you shouldn't be doing with fsck. Options to different filesystem-specific fsck's are not standardized. If in doubt, please consult the man pages of the filesystem-specific checker. Although not guaranteed, the following options are supported by most filesystem checkers:

-a	Automatically repair the filesystem without any questions (use this option with caution). Note that e2fsck supports -a for backward compatibility only. This option is mapped to e2fsck's -p option that is safe to use, unlike the -a option that some filesystem checkers support.
-n	For some filesystem-specific checkers, the -n option causes the fs-specific fsck to avoid attempting to repair any problems, but report such problems to stdout. However, this is not true for all filesystem-specific checkers. In particular, fsck.reiserfs does not report any corruption if given this option. fsck.minix does not support the -n option at all.
-r	Interactively repair the filesystem (ask for confirmations). Note: It is generally a bad idea to use this option if multiple fsck's are being run in parallel. Also, note that this is e2fsck's default behavior; it supports this option for backward compatibility reasons only.
-y	For some filesystem-specific checkers, the -y option causes the fs-specific fsck to always attempt to fix any detected filesystem corruption automatically. Sometimes an expert can do better driving the fsck manually. Note that not all filesystem-specific checkers implement this option. In particular, fsck.minix and fsck.cramfs do not support the -y option.
ie. if it's an ext-filesystem it effectively uses e2fsck which support the -n option.
Top
Zucca
Administrator
Administrator
User avatar
Posts: 4703
Joined: Thu Jun 14, 2007 10:31 pm
Location: Rasi, Finland
Contact:
Contact Zucca
Website

  • Quote

Post by Zucca » Wed Oct 20, 2021 4:16 pm

*sigh*

So there's no handy utility to just check every filesystem. :|
fsck.xfs does nothing according to its man page. :P

Well. I'll write a function which covers most of the cases then.
..: Zucca :..

Code: Select all

0100100100100000011000010110110100100000
0100111001100001010011100010000100100000
0100100100100000011000010110110100100000
0110000100100000011011010110000101101110
00100001
Top
Goverp
Advocate
Advocate
User avatar
Posts: 2404
Joined: Wed Mar 07, 2007 6:41 pm

  • Quote

Post by Goverp » Wed Oct 20, 2021 4:35 pm

If you call raw fsck (i.e. not qualified like fsck.ext5), the busybox implementation just passes the command line to whichever fsck is needed; I'm not sure if the choice is driven by probing the fs or by reading /etc/fstab. If it's the latter, you can find the necessary info from blkid instead.

As you mentioned, you need to include whichever fsck.foo's you need in your initramfs; busybox's one doesn't actually do anything, it just passes the commands along.

fsck's normally respond to "-p" - i.e. "preen" as forced check-and-repair.
fsck "-n" is non-interactive check. opening the FS read-only, which I think is what you want. ext4 and fat both support it; f2fs doesn't mention it; I'll give it a try in a moment (needs a reboot).

I think it's up the the individual fsck.foo what they implement, but equally, I think they try to be consistent for the easy ones.

<edit>
Busybox's fsck needs a valid /etc/fstab. Even if you tell it the fs type with -t ! so you need to either know, or read blkid output, extract fstypes, and build the appropriate command.

f2fs is a pain in the but. Rejects "-n", and uses "--dry-run" instead.
</edit>
Greybeard
Top
Zucca
Administrator
Administrator
User avatar
Posts: 4703
Joined: Thu Jun 14, 2007 10:31 pm
Location: Rasi, Finland
Contact:
Contact Zucca
Website

code

  • Quote

Post by Zucca » Wed Oct 20, 2021 7:02 pm

Well. busybox blkid gives what I need.

Code: Select all

        blkid | awk '
                {
                        dev=substr($1,0,length($1)-1)

                        match($0,/ UUID=\"[-0-9a-fA-F]+\"/)
                        if (RLENGTH > 0) {
                                uuid=substr($0,RSTART+7,RLENGTH-8)
                                if (!seen[uuid]++) {
                                        match($0,/ TYPE=\"[-_a-zA-Z0-9]+\"/)
                                        if (RLENGTH > 0) print dev,uuid,substr($0,RSTART+7,RLENGTH-8)
                                }
                        }
                }
        '
This outputs path, uuid and type and drops duplicate UUIDs and entries which don't have UUID and/or TYPE. I can then loop trough the output line by line in sh and run appropriate fsck commands.
If only busybox blkid gave us the option to format its output...
..: Zucca :..

Code: Select all

0100100100100000011000010110110100100000
0100111001100001010011100010000100100000
0100100100100000011000010110110100100000
0110000100100000011011010110000101101110
00100001
Top
Post Reply

5 posts • Page 1 of 1

Return to “Other Things Gentoo”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic