[Solved] Run fsck on external mounted device

Having issues with your DietPi installation, or, found a bug? Post it here.
Post Reply
User avatar
WarHawk
Posts: 621
Joined: Thu Jul 20, 2017 8:55 am

[Solved] Run fsck on external mounted device

Post by WarHawk »

I automount a 1TB drive on a nextcloud server

How would I ensure it runs an fsck check each boot to ensure data is not corrupted

I used this entry, but not 100% sure it will run it
tune2fs -c 1 /dev/sda1

My external drive mounts as:
/dev/sda1 917G 76G 795G 9% /mnt/3189011b-6b04-433b-8de3-6bdb8a925672

I used the example from here for the non-root partitions
https://linuxconfig.org/how-to-force-fs ... t-on-linux
User avatar
johnvick
Legend
Posts: 693
Joined: Wed Jun 08, 2016 11:53 am
Location: New Zealand

Re: Run fsck on external mounted device

Post by johnvick »

Can you run command as a cron job?
User avatar
MichaIng
Site Admin
Posts: 2324
Joined: Sat Nov 18, 2017 6:21 pm

Re: Run fsck on external mounted device

Post by MichaIng »

@WarHawk
Which device?

On x86 devices at least, fsck is done by initramfs and produces the following flag file: /run/initramfs/fsck-root
On RPi at least, initramfs is not enabled by default (due to custom boot loader), in this case systemd-fsck-root.service kicks in: systemctl status systemd-fsck-root

Besides tune2fs -c 1 /dev/sda1, also take care that /etc/fstab drive entry contains the fsck flag: The last integer in the line needs to be 1 instead of 0. If I remember right, by default on DietPi this flag is only set for rootfs.

In all cases you should be able to see the fsck execution via: journalctl and/or dmesg
User avatar
WarHawk
Posts: 621
Joined: Thu Jul 20, 2017 8:55 am

Re: Run fsck on external mounted device

Post by WarHawk »

So by changing /etc/fstab with the entry of 0 1 that will have it do a drive scan on every boot..cool

I just want to make sure if power drops out or whatever it doesn't corrupt the 1TB drive, sometimes it will boot from SD but if the harddrive is borked...it won't start the services because it is messed up
User avatar
MichaIng
Site Admin
Posts: 2324
Joined: Sat Nov 18, 2017 6:21 pm

Re: Run fsck on external mounted device

Post by MichaIng »

The fstab entry alone does not lead to fsck. It just enables fsck on boot for those drives, by reading other flags, most importantly tune2fs, which were otherwise ineffective.
tune2fs -c 1 /dev/sda1 then allows fsck on every boot/mount, with -c 5 every fifth boot/mount of the drive etc.

AFAIK by default it is configured to fsck on every 60th mount ;).
User avatar
WarHawk
Posts: 621
Joined: Thu Jul 20, 2017 8:55 am

Re: Run fsck on external mounted device

Post by WarHawk »

Just used the built in dietpi-drivemanager utility..worked like a champ! Thanks!
Post Reply