2

I'm trying to run e2fsck on boot of a persistent live lubuntu to fix 'corrupt filesystem' error of a writable system partition (ext4) and I want to automate this somehow (so ideally I do not want to boot into another live usb to do it)

I want to automate because these errors have a tendency to accumulate with restarts/shutdowns of the system (I do follow instructions and remove the USB stick on which the system is and then press Enter on shutdown/restart). After several months of use (maybe 100 shutdowns) the errors did accumulate so much, that the system became unable to boot.

I did fix the errors by booting another live system and then running:

umount -l /dev/sdc5
e2fsck -y /dev/sdc5

the /dev/sdc5 being the writable partition of the system mounted at /media/lubuntu/writable

In order to automate this for the future I've tried fixing the error from the same storage medium by:

  1. booting into the Recovery mode, yet e2fsck returned 'Target is busy', so the lazy unmount wasn't succesful.
  2. hitting e in the GRUB menu and editing fsck.mode=none to fsck.mode=force and then booting (Ctrl+x/f10) but it did not fix the errors.
  3. forcing fsck on boot by changing the maximum number of mounts by sudo tune2fs -c -1 /dev/sdb5 but it did not fix the errors

I'm not sure if in the last two cases the fsck did run and I don't know how to find out, I've tried to read the contents of several logs in /var/log but did not find a mention about it

my live system was made using mkusb and lubuntu 22.04.3 iso any help welcome

andrej
  • 59
  • One cannot successfully change a disk's partitioning metadata while ANY of the disk's partitions is mounted. Boot from another system, and you can fsck . – waltinator Dec 11 '23 at 17:13
  • When you want to fix the file system in the 'writable' partition, it is best to boot the operation system not as persistent, not as a normal live drive, but as nopersistent, do add that boot option into the 'linux' line that you use. Then when booted, it should work to use sudo e2fsck -f /dev/sdx5, where x is the drive letter of the USB drive with your persistent live system. See this link for more details, – sudodus Dec 12 '23 at 12:57
  • I am not sure if the method with tune2fs works in live or persistent live systems. But anyway, it is very important to shut down the computer very carefully (before unplugging), and still, if the USB pendrive is slow or getting old, things are not very reliable, so there is a risk of corrupted files or corrupted file system. An SSD connected via USB is much more reliable (according to my own experience). – sudodus Dec 12 '23 at 13:03
  • @sudodus thank you for the tips! This is my travelling system and I prefer to travel with USB sticks due to size. I am considering an investment in an SLC or MLC USB stick for reliability though. Do I understand you correct that you suggest that I download a Lubuntu iso file, edit it using sed 's/quiet splash/nopersistent/' standard.iso > nopersistent.iso and then flash it to a new drive using mkusb? In an ideal scenario for me, I would like to create a 'nopersistent' GRUB entry on the same stick that contains my persistent and live systems. Would that work? It would be great for debugging! – andrej Dec 13 '23 at 20:09
  • by reliability do you mean, that on an SSD connected via USB port, the 'corrupt filesystem' errors do not accumulate with proper shutdowns/restarts? – andrej Dec 13 '23 at 20:16
  • You can do it like that and have a separate USB drive for that purpose. You can also edit temporarily, while at the grub menu in the persistent live drive (on the 'linux line' replace persistent with nopersistent toram) and boot into a pure 'live-only' system, that should let you run sudo e2fsck -f /dev/sdx5 to repair the ext4 file system in your 'writable' partition. – sudodus Dec 13 '23 at 20:18
  • There is much less risk of problems due to slow or 'unwilling' response, and also much less risk of hardware failure in an SSD because both the memory cells and the controlling electronic circuits and software have a higher quality. – sudodus Dec 13 '23 at 20:21
  • You might be lucky and find a USB pendrive with SSD quality, but you can expect it to be fairly expensive. If size matters more than price, yes, it would be a good option. – sudodus Dec 13 '23 at 20:26

1 Answers1

2

The question was answered by @sudodus in the comments. I will summarize it here:

  • Run a live lubuntu that does not mount the writable partition for logs: in the mkusb made GRUB menu, highlight the live option, press e, replace the inline text quiet splash with nopersistent toram, and boot using f10 or Ctrl+X.
  • When booted, unmount the writable partition (e.g. via the KDE Partition manager GUI), and then in the Terminal run sudo e2fsck -f /dev/sdXN (sdXN being the writable partition, e.g sdc5)

Another possible fix: use a higher quality storage medium for the system, to prevent the errors from accumulating over time (not tested)

andrej
  • 59
  • I'm glad we found a method that works for you. In order to make it easier for other users to find your solution, please return to this answer and 'accept' it by clicking the tick icon. (You may need to wait for a couple of days until it is possible-) – sudodus Dec 14 '23 at 11:11