Linux系统的目录绑定配置

简介: Linux系统的目录绑定配置

@TOC

一.源目录与目标目录情况

1、源目录文件及inode

[root@docker data]# pwd
/data
[root@docker data]# ll
total 140648
-rw-r--r-- 1 root root       205 Dec 11 13:59 backdata.tar.gz
-rw-r--r-- 1 root root         0 Dec 11 13:54 file1
-rw-r--r-- 1 root root         0 Dec 11 13:54 file10
-rw-r--r-- 1 root root         0 Dec 11 13:54 file2
-rw-r--r-- 1 root root         0 Dec 11 13:54 file3
-rw-r--r-- 1 root root         0 Dec 11 13:54 file4
-rw-r--r-- 1 root root         0 Dec 11 13:54 file5
-rw-r--r-- 1 root root         0 Dec 11 13:54 file6
-rw-r--r-- 1 root root         0 Dec 11 13:54 file7
-rw-r--r-- 1 root root         0 Dec 11 13:54 file8
-rw-r--r-- 1 root root         0 Dec 11 13:54 file9
-rw------- 1 root root 144015872 Dec 11 14:11 web01.tar
[root@docker data]# ls -lid /data
2401630 drwxr-xr-x. 2 root root 177 Dec 11 14:11 /data

2、目标目录的文件及inode

[root@docker backup]# pwd
/backup
[root@docker backup]# ll
total 0
-rw-r--r-- 1 root root 0 Dec 17 17:00 test1
-rw-r--r-- 1 root root 0 Dec 17 17:00 test2
[root@docker backup]# ls -lid /backup/
38821596 drwxr-xr-x 2 root root 32 Dec 17 17:00 /backup/
[root@docker backup]#

二、将两个目录进行绑定

1.moun --bind进行绑定

将test1挂载到test2上,inode号都变为test1的inode
root@docker backup]# mount --bind /data/ /backup/

2.检查绑定后的两个目录情况

[
[root@docker backup]# ls /data/
backdata.tar.gz  file1  file10  file2  file3  file4  file5  file6  file7  file8  file9  web01.tar
[root@docker backup]# ls /backup/
backdata.tar.gz  file1  file10  file2  file3  file4  file5  file6  file7  file8  file9  web01.tar
[root@docker backup]# lls -lid /data/ /backup/
bash: lls: command not found...
Similar command is: 'ls'
[root@docker backup]# ls -lid /data/ /backup/
2401630 drwxr-xr-x. 2 root root 177 Dec 11 14:11 /backup/
2401630 drwxr-xr-x. 2 root root 177 Dec 11 14:11 /data/

3.moun --bind绑定注意事项

#注意,mount --bind重启后会丢失挂载,包括/dev/shm目录重启后也会清空,要解决该问题,可以添加开机自启脚本
#添加到/etc/rc.local文件中

三、解挂载

1.对两个目录进行解挂载

[root@docker /]# umount /backup

2.查看解挂载后的情况

[root@docker ~]# ls /data
backdata.tar.gz  file1  file10  file2  file3  file4  file5  file6  file7  file8  file9  web01.tar
[root@docker ~]# ls /backup/
test1  test2
[root@docker ~]# ls -lid /data /backup/
38821596 drwxr-xr-x  2 root root  32 Dec 17 17:00 /backup/
 2401630 drwxr-xr-x. 2 root root 177 Dec 11 14:11 /data

四、应用场景

1.场景描述

在固件开发过程中常常遇到这样的情况:为测试某个新功能,必需修改某个系统文件。而这个文件在只读文件系统上(总不能为一个小小的测试就重刷固件吧),或者是虽然文件可写,但是自己对这个改动没有把握,不愿意直接修改。这时候mount --bind就是你的好帮手。

2.测试系统文件

[root@docker ~]# mount -o ro /dev/sdb1 /soft
[root@docker ~]# cd /soft/
[root@docker soft]# touch file1
touch: cannot touch 'file1': Read-only file system
[root@docker soft]#
[root@docker soft]# mount --bind /test/ /soft/
[root@docker soft]# cd /test
[root@docker test]# touch test{1..10}.txt
[root@docker test]# ls
test10.txt  test1.txt  test2.txt  test3.txt  test4.txt  test5.txt  test6.txt  test7.txt  test8.txt  test9.txt
[root@docker test]# ls /soft/
test10.txt  test1.txt  test2.txt  test3.txt  test4.txt  test5.txt  test6.txt  test7.txt  test8.txt  test9.txt
[root@docker test]#
相关文章
|
5天前
|
消息中间件 安全 Linux
服务器(Linux)在线下载activeMQ以及配置打开
服务器(Linux)在线下载activeMQ以及配置打开
14 3
|
5天前
|
IDE Linux 开发工具
Linux 系统上安装
在Linux和Mac上安装Lua 5.3.0只需下载源码,解压,编译和安装。Windows用户可选择SciTE IDE或通过LuaForWindows在Github或Google Code下载安装。创建 HelloWorld.lua,使用`lua HelloWorld.lua`运行显示"Hello World!"。另可参考LuaDist官方推荐方式安装。
|
5天前
|
Ubuntu Linux 编译器
【Linux】详解动静态库的制作和使用&&动静态库在系统中的配置步骤
【Linux】详解动静态库的制作和使用&&动静态库在系统中的配置步骤
|
5天前
|
Linux Windows
虚拟机添加新硬盘之linux系统篇
虚拟机添加新硬盘之linux系统篇
16 1
|
3天前
|
运维 Linux
CentOS系统openssh-9,你会的还只有初级Linux运维工程师的技术吗
CentOS系统openssh-9,你会的还只有初级Linux运维工程师的技术吗
|
4天前
|
监控 JavaScript Linux
Linux系统之部署Homepage个人导航页
【5月更文挑战第13天】Linux系统之部署Homepage个人导航页
22 1
|
5天前
|
监控 JavaScript 网络协议
Linux系统之安装uptime-kuma服务器监控面板
【5月更文挑战第12天】Linux系统之安装uptime-kuma服务器监控面板
18 0
|
5天前
|
Ubuntu Linux Shell
mc实现目录同步并封装成Linux服务形式
mc实现目录同步并封装成Linux服务形式
186 1
|
5天前
|
Linux Perl
Linux系统的文本处理
Linux系统的文本处理
|
5天前
|
Linux API
Linux系统编程之文件编程常用API回顾和文件编程一般步骤
Linux系统编程之文件编程常用API回顾和文件编程一般步骤
Linux系统编程之文件编程常用API回顾和文件编程一般步骤

热门文章

最新文章