Bind Mounts and File System Mount Order

     When you use the bind option of the mount command, you must be sure that the file systems are mounted in the correct order. In the following example, the /var/log directory must be mounted before executing the bind mount on the /tmp directory:

# mount --bind /var/log /tmp

The ordering of file system mounts is determined as follows:

  1. In general, file system mount order is determined by the order in which the file systems appear in the fstab file. The exceptions to this ordering are file systems mounted with the _netdev flag or file systems that have their own init scripts.
  2. A file system with its own init script is mounted later in the initialization process, after the file systems in the fstab file.

    大意是:在初始化进程结束之后,一个带有自身的init脚本的文件系统会被挂载,不过,这要在fstab这个文件中所列出的文件系统被挂载之后。也就是说,挂载次序慢于fstab

  3. File systems mounted with the _netdev flag are mounted when the network has been enabled on the system.

If your configuration requires that you create a bind mount on which to mount a GFS2 file system, you can order your fstab file as follows:

  1. Mount local file systems that are required for the bind mount.
  2. Bind mount the directory on which to mount the GFS2 file system.
  3. Mount the GFS2 file system.

If your configuration requires that you bind mount a local directory or file system onto a GFS2 file system, listing the file systems in the correct order in the fstab file will not mount the file systems correctly since the GFS2 file system will not be mounted until the GFS2 init script is run. In this case, you should write an init script to execute the bind mount so that the bind mount will not take place until after the GFS2 file system is mounted.

The following script is an example of a custom init script. This script performs a bind mount of two directories onto two directories of a GFS2 file system. In this example, there is an existing GFS2 mount point at /mnt/gfs2a, which is mounted when the GFS2 init script runs, after cluster startup.

In this example script, the values of the chkconfig statement indicate the following:

  • 345 indicates the run levels that the script will be started in
  • 29 is the start priority, which in this case indicates that the script will run at startup time after the GFS2 init script, which has a start priority of 26
  • 73 is the stop priority, which in this case indicates that the script will be stopped during shutdown before the GFS2 script, which has a stop priority of 74

The start and stop values indicate that you can manually perform the indicated action by executing a service start and a service stop command. For example, if the script is named fredwilma, then you can execute service fredwilma start.

This script should be put in the /etc/init.d directory with the same permissions as the other scripts in that directory. You can then execute a chkconfig on command to link the script to the indicated run levels. For example, if the script is named fredwilma, then you can execute chkconfig fredwilma on.

#!/bin/bash
#
# chkconfig: 345 29 73
# description: mount/unmount my custom bind mounts onto a gfs2 subdirectory
#
#
### BEGIN INIT INFO
# Provides:
### END INIT INFO

. /etc/init.d/functions
case "$1" in
  start)
    # In this example, fred and wilma want their home directories
    # bind-mounted over the gfs2 directory /mnt/gfs2a, which has
    # been mounted as /mnt/gfs2a
    mkdir -p /mnt/gfs2a/home/fred &> /dev/null
    mkdir -p /mnt/gfs2a/home/wilma &> /dev/null
    /bin/mount --bind /mnt/gfs2a/home/fred /home/fred
    /bin/mount --bind /mnt/gfs2a/home/wilma /home/wilma
        ;;

  stop)
    /bin/umount /mnt/gfs2a/home/fred
    /bin/umount /mnt/gfs2a/home/wilma
        ;;

  status)
        ;;

  restart)
        $0 stop
        $0 start
        ;;

  reload)
        $0 start
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart|reload|status}"
        exit 1
esac

exit 0
时间: 2024-10-03 20:56:03

Bind Mounts and File System Mount Order的相关文章

NFS(Network File System)服务配置和使用

Sun公司开发NFS (Network File System)之初就是为了在不同linux/Unix系统之间共享文件或者文件夹.可以在本地通过网络挂载远程主机的共享文件,和远程主机交互.NFS共享存储对初学者来说不太好理解,我看到过一个很好的例子,假如有三台机器A.B.C,它们需要访问同一个目录,目录中都是图片,传统的做法是把这些图片分别放到A.B.C.但是使用NFS只需要放到A上,然后A共享给B和C即可.访问的时候,B和C是通过网络的方式去访问A上的那个目录的. 一.NFS的优势 允许本地获

linux nfs Read-only file system

[email protected]/4 # touch 1 touch: cannot touch `1': Read-only file system mount没有权限? [email protected]/0 # mount /dev/sda2 on / type ext4 (rw) proc on /proc type proc (rw) sysfs on /sys type sysfs (rw) devpts on /dev/pts type devpts (rw,gid=5,mode

linux c语言 rename的用法-rename() does not work across different mount points, even if the same file system is mounted on both

最近在一个项目上执行文件的搬移功能时发现总是失败,临时录像文件存放于emmc的/tmp/目录下,当录像完成时候则调用rename企图将此文件搬到/mnt/sdcard/mmcblk1p1/(这是外置的sd卡)上面,但是每次执行rename的时候都返回失败了. man 2  rename解释如下: 1 RENAME(2) Linux Programmer's Manual RENAME(2) 2 3 NAME 4 rename - change the name or location of a

How to Setup NFS (Network File System) on RHEL/CentOS/Fedora and Debian/Ubuntu

NFS (Network File System) is basically developed for sharing of files and folders between Linux/Unix systems by Sun Microsystems in 1980. It allows you to mount your local file systems over a network and remote hosts to interact with them as they are

NFS中小企业常见的网络文件系统服务(network file system)

NFS中小企业常见的网络文件系统服务(network file system) RPC服务最主要的功能就是记录每个NFS功能所对应的端口号,并在NFS客服端请求时将该端口和功能对应的信息传递个给请求数据的NFS客服端 流程: 1,先开启RPC服务 2,再启动NFS服务 3,NFS服务向RPC注册启动的端口 4,客服请求NFS服务 5,RPC返回端口给客服端 环境搭建: 服务端为 nfsserver  客服端为 nfsclient NFS服务需要安装的软件包: yum install nfs-ut

[白开水]-故障-启动类故障排错记录- Read-only file system

问题问题来源 由于磁盘fsck检查异常,导致系统挂载以只读模式挂载根分区. 如果fsck检查后以只读模式挂载/分区,很可能fsck已经无法修复分区了 问题描述 #开机启动会出现fsck对/分区fsck检测 Checking all file systems. [/sbin/fsck.ext4 (1) -- /] fsck.ext4 -a /dev/xvda3 /dev/xvda3 contains a file system with errors, check forced. /dev/xvd

HDFS分布式文件系统(The Hadoop Distributed File System)

The Hadoop Distributed File System (HDFS) is designed to store very large data sets reliably, and to stream those data sets at high bandwidth to user applications. In a large cluster, thousands of servers both host directly attached storage and execu

Extension of write anywhere file system layout

A file system layout apportions an underlying physical volume into one or more virtual volumes (vvols) of a storage system. The underlying physical volume is an aggregate comprising one or more groups of disks, such as RAID groups, of the storage sys

docker从零开始 存储(三)bind mounts

使用bind mounts 自Docker早期以来bind mounts 一直存在.与volumes相比,绑定挂载具有有限的功能.使用bind mounts时,主机上的文件或目录将装入容器中.文件或目录由其在主机上的完整路径或相对路径引用.相反,当您使用卷时,会在主机上的Docker存储目录中创建一个新目录,Docker会管理该目录的内容. 该文件或目录不需要已存在于Docker主机上.如果它尚不存在,则按需创建.绑定挂载非常高效,但它们依赖于具有特定目录结构的主机文件系统.如果您正在开发新的D