I have OpenWRT installed on a single drive WD My Book Live and at the start had a great many issues originated in a bad shutdown.
I solved them with two things:
- the hardware issue
I rigged a cable to the 12v barrel socket and to a SPST switch at the back of the unit along with a scrip to shut down the drive that executes
sync, stops the HDD with
hdparm -Yand then executes
The trick here is to flip the switch less than 20s after the front LED turns blue.
If not done in time, openwrt/watchdog will reboot the system and flipping the switch will result in a hard shutdown.
But gone was the pull the plug to switch off the NAS routine, my HDD was happy and I was happy.
- the software issue
Of course, what I did above will not work under certain circumstances ie: a hard shutdown due to a power cut, a rare but worrying/possible prospect which will cause some problem to the HDD.
I found the solution in a post by forum member
iwman from back in 11/2019, which consists in editing
/lib/preinit/80_mount_root and adding this bit of code between lines
if [ -x '/usr/sbin/fsck.ext4' ]; then if [ -e '/dev/sda1' ]; then echo "Checking disk /dev/sda1...." /usr/sbin/fsck.ext4 -y /dev/sda1 fi if [ -e '/dev/sda2' ]; then echo "Checking disk /dev/sds2..." /usr/sbin/fsck.ext4 -y /dev/sda2 fi fi
This way, every time the system boots, it will check and repair the disk, even after a hard shutdown.
Or so I thought.
A couple of days ago I had to resort to a hard shutdown ie: flipping the switch to reboot after the system locked up completely while attempting to troubleshoot the ethernet speed configuration with
dmesg to see if everything was allright, and there it was again:
root@OpenWrt:~# dmesg | grep e2fsck [ 0.885063] EXT4-fs (sda2): warning: mounting unchecked fs, running e2fsck is recommended root@OpenWrt:~#
I know the script works because after I installed it, the warnings about the number of boots limit were gone.
Searching for the
dmesg warning, I found it is referenced quite a bit on the web but most times not as a problem to be solved but as part of the post which includes the
Besides printing some strange output,
tune2fs says that both
/dev/sda2 are not clean:
root@OpenWrt:~# tune2fs -l /dev/sda1 | grep -i "filesystem\|mount" Filesystem volume name: <none> Last mounted on: /boot Filesystem UUID: e61124a4-e786-44d9-bb0a-73d676fe5a61 Filesystem magic number: 0xEF53 Filesystem revision #: 1 (dynamic) Filesystem features: filetype Default mount options: (none) Filesystem state: not clean Filesystem OS type: Linux Last mount time: Wed Dec 31 21:00:05 1969 # <----------- ? Mount count: 1 Maximum mount count: 20 root@OpenWrt:~#
root@OpenWrt:~# tune2fs -l /dev/sda2 | grep -i "filesystem\|mount" Filesystem volume name: rootfs Last mounted on: / Filesystem UUID: ff313567-e9f1-5a5d-9895-3ba130b4a864 Filesystem magic number: 0xEF53 Filesystem revision #: 1 (dynamic) Filesystem features: ext_attr resize_inode filetype extent sparse_super large_file uninit_bg Filesystem flags: unsigned_directory_hash Default mount options: (none) Filesystem state: not clean Errors behavior: Remount read-only Filesystem OS type: Linux Last mount time: n/a Mount count: 67 Maximum mount count: -1 root@OpenWrt:~#
Thanks in advance,