SW 개발

Linux 에서 cmdline 과 fsck 를 통한 파일자동복구하기

. . . 2021. 11. 17. 16:37
반응형

대부분의 rotofs 시스템에서 fsck 를 통해서 파일시스템을 복구하는기능을 제공한다.

커널이 부팅될때 파일시스템을 자동으로 확인하고 복구시키는 방법에 대해서 설명한다.

fsck 를 통한 파일시스템복구

커널아규먼트를 통한 fsck 하기

https://manpages.debian.org/jessie/systemd/systemd-fsck-root.service.8.en.html

위의내용은 일반적인 systemd 에서의 fsck 를 이야기한다.

즉, 커널아규먼트에 fsck.modefsck.repair 가 있어야한다고 설명이 되어있다.

fsck.mode=
One of "auto", "force", "skip". Controls the mode of operation. The default is "auto", and ensures that file system checks are done when the file system checker deems them necessary. "force" unconditionally results in full file system checks. "skip" skips any file system checks.
fsck.repair=
One of "preen", "yes", "no". Controls the mode of operation. The default is " preen", and will automatically repair problems that can be safely fixed. "yes " will answer yes to all questions by fsck and "no" will answer no to all questions.
  • 특이사항
    • systemd 에서 systemd-fsck.service 내용을 수정하지 않아도된다.
      • 즉 위의 커널아규먼트를 통해서, systemd-fsck 가 알아서 실행이된다.
    • fsck.mode=force 하면 매번 모든파일시스템을 재부팅하기 때문에 엄청 느려진다.

fstab 관련한내용

위에서 정한 fsck argument 는 fstab 의 옵션과 연동되어 동작된다.

The sixth field (fs_passno).
              This field is used by fsck(8) to determine the order in
              which filesystem checks are done at boot time.  The root
              filesystem should be specified with a fs_passno of 1.
              Other filesystems should have a fs_passno of 2.
              Filesystems within a drive will be checked sequentially,
              but filesystems on different drives will be checked at the
              same time to utilize parallelism available in the
              hardware.  Defaults to zero (don't fsck) if not present.
  • 위의설명에서 보듯이 fstab 의 마지막필드를 1 or 2 로 해야 fsck 가 동작한다.
    • 해당 숫자는 우선먼저검새해야할 순서를 지정하는것이다.
반응형