2

I have problems with the main OS partition, but seems that i can't run fsck on mounted partitions?

Is there a way to diagnose mounted partition (i'm having problems lately) and if there isn't what is the best way to check it when not mounted?

user240891
  • 709
  • 4
  • 9
  • 25
  • 1
    It is best to run fsck from a live USB / CD – Panther May 16 '17 at 19:47
  • Perhaps reviewing [https://askubuntu.com/questions/59064/how-to-run-a-checkdisk/59077#59077](https://askubuntu.com/questions/59064/how-to-run-a-checkdisk/59077#59077) would help – Charles Green May 16 '17 at 19:50
  • Please see my answer at https://askubuntu.com/questions/885062/root-file-system-requires-manual-fsck/885085#885085 and please remember to vote if it was helpful. – heynnema May 16 '17 at 20:15
  • I can suggest checking your Linux file system from initramfs or before your partitions are mounted that way you don't have to load a live cd/usb but using your own installation. I don't know the commands and I don't know if fsck is on there when the OS isn't load, in any case always have a handy bootable removable media with all your tools. – Latino16bits May 16 '17 at 19:50

2 Answers2

3

You can perform a fsck on your root partition during the next reboot by creating a file named forcefsck in your root directory:

sudo touch /forcefsck
reboot
Byte Commander
  • 105,631
  • 46
  • 284
  • 425
  • Will this work when I have encrypted hdd, home and swap? – user240891 May 17 '17 at 07:09
  • It should work, I think, but I can't test it here. In the worst case, if that file prevented your installation from booting and failed to trigger a `fsck`, you could mount the partition from a live system and remove it from there. But as you'd have to do the `fsck` from a live system anyway if it doesn't work this way, I don't see a real problem with just trying this method. – Byte Commander May 17 '17 at 08:25
  • will the file go away after running fsck or do I have to remove it manually afterwards? – wotter Feb 20 '19 at 17:47
  • 1
    @wotter It will get removed automatically during the file system check. – Byte Commander Feb 20 '19 at 18:07
1

I suggest running it in "Initramfs".

dracut is a low-level tool for generating an "initramfs" images with a lot of capabilities.

Let's install it:

sudo apt install dracut

After installation is finished a new "initramfs" will be generated and GRUB will be updated automatically; It also removes initramfs-tools.

Now reboot the system, hold the Shift to make the GRUB appear (if it won't by itself), press e to edit the default menu. There is a line which starts with linux at the end of that line add rd.break=pre-mount then press Ctrl+x to continue boot process.

it means that drop me into initramfs before mounting the filesystem, Now we are in a sh shell and we can simply run fsck:

$ fsch /dev/sda1
/dev/sda1: clean,  xxx/xxx files,  yyy/yyy blocks

dracut
dracut.cmdline

Ravexina
  • 54,268
  • 25
  • 157
  • 179