问题
最近遇到了几次OpenWRT产生的启动问题,即在多次掉电重启后,OpenWRT的磁盘出现了数据错误的情况,导致无法正常运行。经过排查,发现x86_64版的OpenWRT提供的内核是不带initrd的,同时提供的磁盘镜像也是一样的。那如何在没有initrd的情况下配置磁盘启动时自动fsck呢?
解决方案
经过搜索,发现了how-to-force-fsck-at-boot 这篇文章。里面提到的方法,是通过重新挂载到只读模式,再进行fsck,然后再挂载回读写模式。
于是我按照上面的方法,做了些调整,没有使用sda之类的设备路径名,而是使用了/boot/grub.conf里的PARTUUID。
修改/lib/preinit/80_mount_root,调整后的脚本如下
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25  | 
						#!/bin/sh # Copyright (C) 2006 OpenWrt.org # Copyright (C) 2010 Vertical Communications do_mount_root() {     # 从这里是新添加的部分     echo "fsck checking rootfs"     /bin/mount -o remount,ro /     /usr/sbin/fsck.ext4 -p -f PARTUUID=339542e9-01     /usr/sbin/fsck.ext4 -p -f PARTUUID=339542e9-02     /bin/mount -o remount,rw /     echo "fsck checking rootfs done"     # 新添加的部分到这里结束     mount_root     boot_run_hook preinit_mount_root     [ -f /sysupgrade.tgz ] && {         echo "- config restore -"         cd /         tar xzf /sysupgrade.tgz     } } [ "$INITRAMFS" = "1" ] || boot_hook_add preinit_main do_mount_root  | 
					
验证
重启后,通过串口控制台看到成功输出了fsck的输出。问题解决。