从 fstab 挂载磁盘之前执行脚本(在系统启动时)

从 fstab 挂载磁盘之前执行脚本(在系统启动时)

我正在进行一个项目来实现块分层设备驱动程序,因此我的内核模块和控制实用程序(此实用程序需要网络启动并运行)必须在系统检查目标设备上的文件系统之前执行(在我的情况下是/dev/sdb)并尝试安装它。为了实现它,我写了一个脚本/etc/init.d/dudriver

#!/bin/sh
# kFreeBSD do not accept scripts as interpreters, using #!/bin/sh and sourcing.
if [ true != "$INIT_D_SCRIPT_SOURCED" ] ; then
    set "$0" "$@"; INIT_D_SCRIPT_SOURCED=true . /lib/init/init-d-script
fi

### BEGIN INIT INFO
# Provides:          dudriver
# Required-Start:    $network udev mountdevsubfs
# Required-Stop:     
# Should-Start:      udev
# Should-Stop:       udev
# X-Start-Before:    checkfs mountall
# X-Stop-After:      
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: 
# Description:
### END INIT INFO



SCRIPTNAME=/etc/init.d/dudriver
. /lib/lsb/init-functions


#
# Check  a presence of the main startup script
#

#if [ -x /opt/dudriver_startup.sh ]
#then
#   /opt/dudriver_startup.sh >>/var/log/dudriver_startup.log
#fi

set -e

[ -x /opt/dudriver_startup.sh ] || exit 0


do_start()
{
    /opt/dudriver_startup.sh
}


do_stop()
{
    exit 0
}

case "$1" in
    start)
            log_begin_msg "Starting UP DUDRIVER ..."
            do_start
        stv=$?
        exit 0
            ;;
    stop)
            log_begin_msg "Shutting down DUDRIVER ..."
            do_stop
        stv=$?
        exit 0
            ;;
    restart|force-reload)
        exit 0
            ;;
    *)
            echo "Usage: $SCRIPTNAME {start|stop}" >&2
            exit 3
        ;;
esac

因此,当系统启动时我看到:

-- The start-up result is done.
янв 26 13:07:50 sysman mount[658]: mount: wrong fs type, bad option, bad superblock on /dev/sdb2,
янв 26 13:07:50 sysman mount[658]:        missing codepage or helper program, or other error
янв 26 13:07:50 sysman mount[658]:        In some cases useful info is found in syslog - try
янв 26 13:07:50 sysman mount[658]:        dmesg | tail or so.
янв 26 13:07:50 sysman kernel: EXT4-fs (sdb2): VFS: Can't find ext4 filesystem
янв 26 13:07:50 sysman systemd[1]: mnt-luks.mount: Mount process exited, code=exited status=32
янв 26 13:07:50 sysman systemd[1]: Failed to mount /mnt/luks.
-- Subject: Unit mnt-luks.mount has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit mnt-luks.mount has failed.
-- 
-- The result is failed.
янв 26 13:07:50 sysman systemd[1]: mnt-luks.mount: Unit entered failed state.

/etc/fstab :

# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda1 during installation
UUID=c9e11c4a-36cb-4a53-bea5-cd430429ca1e /               ext4    errors=remount-ro 0       1

# swap was on /dev/sda5 during installation
#UUID=614198e5-236e-41fc-baa1-31b9f2230c02 none            swap    sw              0       0

/dev/sdb2 /mnt/luks ext4 defaults 0 0 

因此,问题是:

  1. 我在依赖关系上哪里错了?
  2. 我需要在 dudriver 脚本中做哪些更改?

相关内容