2

I am running Ubuntu 20.04 Server on my Raspberry Pi 4B 8GB. I have migrated to usb hdd boot but I still need the SD card as it houses the firmware (if somebody found a workaround, let me know :)). The SD card is prone to corruption.

The reboot failes ocasionally and I am required to manually run fsck for the failed partition. I would like to automate this step so that the server does not need to wait for my intervention to continue booting.

I understand that fsck will not fix certain issues and that the only fix is to replace the SD card. I am looking for an automatic solution for those cases where it can work.

I am copying this question from the Ubunut stackexchange. It was not answered there and I am the author of the question.

EDIT: I want clarify one commenters statement that an SD card is not necessary for USB boot. There is a bug on the 20.04 Ubuntu OS ARM64 version that prevents booting without an SD card. You need to leave the boot partition on the SD card while moving only the system partition to the USB HDD. For more information, please check this guide I made here.

3
  • 1
    "The SD card is prone to corruption." No this is an urban myth. In 9 years with 10 Pi I have only had 2 SD Cards wear out and occasional corruption due to operator error.
    – Milliways
    Sep 28, 2022 at 21:49
  • You don't actually need a SD Card for USB boot.
    – Milliways
    Sep 28, 2022 at 21:53
  • I've had three die in the last two years. Miths get started for a reason. Please point me to the article that explains why you don't need an SD card.
    – isaric
    Sep 30, 2022 at 5:20

2 Answers 2

2

On RpiOS by default /boot/cmdline.txt includes fsck.repair=yes, meaning if the root fs was not unmounted clearly,fsck will check and attempt to repair it if necessary.

This is not a kernel option, but is passed by it to systemd, which runs the service. You should be able to do the same thing on Ubuntu. You can also add fsck.mode=force to force a run even if the fs was cleanly unmounted.

The details of these two parameters are explained in man systemd-fsck-root.service:

KERNEL COMMAND LINE

systemd-fsck understands these kernel command line parameters:

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.

Note it is actually run even with no parameter on the kernel command-line, but it is done less aggressively than if fsck.repair=yes.

The man page also explains the relationship to the passno field used in /etc/fstab.

1
  • I have a Raspberry Pi model B which definitely cannot boot without an SD card, and yes, SD cards wear out if the Pi runs 24x7. Thus, I also put my system on a USB drive, which takes over from the SD card after boot. QUESTION is: which /boot/cmdline.txt must have the fsck.repair statement? The one on the SD card only, or the /boot partition on the USB drive too?
    – user333869
    Mar 25 at 15:24
0

I assume you are trying to run it from the cron. If so, I suspect the answer to your problem is the same answer to this question : Running Script on Crontab but it doesn't access WiFi connection

ALSO make SURE you are using a high quality SD card.

1
  • Actually, I want it to run when the boot fails and I get the message that I should run fsck.
    – isaric
    Sep 30, 2022 at 5:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.