Linux磁盘管理之关于挂载的理解

前面说到文件系统,文件系统系统是操作位方便操作系统管理而创建的一种数据存储数据结构。当系统创建完成文件系统后,系统怎么被用户使用,Linux内核对外提供统一的接口,用户通过这个来对文件系统操作,内核内部再针对不同文件系统处理。

 Linux使用mount的方式来使用储存设备,挂载时候会识别文件系统类型,参考下man帮助和wiki百科介绍:

        All  files accessible  in  a Unix system are arranged  in  one big tree, the
        file  hierarchy, rooted at /.  These files can be spread out over several
        devices. The  mount  command  serves to attach the filesystem found on some
        device to the big  file  tree.  Conversely,  the  umount (8)  command  will
        detach it again.
  
        The standard form of the  mount  command , is
  
              mount  -t  type  device  dir
        This tells the kernel to attach the filesystem found on device ( which  is
        of  type  type ) at the directory  dir .  The previous contents ( if  any)  and
        owner  and  mode of  dir  become invisible, and as long as this filesystem
        remains mounted, the pathname  dir  refers to the root of  the  filesystem
        on device.

 Linux所有可以访问的文件都被排列为一个/开始的树形层级结构,mount是把文件系统附加到树形结构上。这个操作将告诉内核把设备附加到一个目录上。

  Mounting takes place before a computer can use any kind of storage device (such as a hard 
drive, CD-ROM, or network share). The user or their operating system must  make  it accessible
through the computer’s  file  system. A user can only access files on mounted media.

 计算机想要使用任何类型的存储设备 (如硬盘, CD-ROM, 网络设备) 之前使用挂载, 操作系统将这个设备纳入自己的文件系统中去.

 关于挂载点

 通常的挂载点都是目录,但是也可以是一个文件:

[root@localhost tmp] # cat > m1<<eof
> this is first line of file1
> eof
[root@localhost tmp] # cat >m2<<eof
> this is file2
> eof
[root@localhost tmp] # mount --bind m1 m2
[root@localhost tmp] # cat m2
this is first line of file1

 mount --bind:

 用于绑定式挂载,挂载一般无法挂载的,比如ISO镜像文件,对文件mkfs的文件,普通文件或者目录。

对于ISO镜像和创建了文件系统的文件可以--bind /dev/loop设备,通过本地回环设备绑定再将回环设备挂载到系统一个目录下,mount -o loop内部使用的就是这种做法。

 对于--bind目录主要不支持软连接或者不想更改目录内容想使用其他目录来文件来替换当前文件来做测试的情况。

 --bind文件和文件,在不修改的目标文件的情况下,测试现在新文件的效果。

猜你喜欢

转载自www.linuxidc.com/Linux/2017-07/145377.htm