首页 > 系统相关 >Linux系统的目录绑定配置

Linux系统的目录绑定配置

时间:2023-03-05 12:00:50浏览次数:34  
标签:11 -- backup 绑定 Linux docker txt root 目录

(Linux系统的目录绑定配置)

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

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]# 

标签:11,--,backup,绑定,Linux,docker,txt,root,目录
From: https://blog.51cto.com/u_14664141/6101356

相关文章

  • phpcms文件目录结构
    根目录| – api  接口文件目录| – caches缓存文件目录    | –configs系统配置文件目录    | –caches_*系统缓存目录| – p......
  • 5.可以说出两种实现双向绑定的方案、可以手动实现
    可以说出两种实现双向绑定的方案、可以手动实现1.手动绑定Object.defineProperty<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metanam......
  • linux下tomcat删除文件命令集合
    cd/usr/local/tomcat/bin./shutdown.shcd../cdwebappsrm-rfROOTrm-rfROOT.war首先进入到tomcat的bin目录下,然后关闭tomcat,并且返回目录删除文件和war文件。cd/usr/l......
  • docker存储目录
    1目录结构docker存储目录是/var/lib/docker。2image目录image/overlay2/distribution:从远端拉到本地的镜像相关元数据image/overlay2/imagedb:镜像数据库image/o......
  • Linux Mint 21.1 安装笔记
    LinuxMint21.1安装笔记V1.0 目录1.说明2.安装Linux系统2.1.下载LinuxMint安装包(ISO)2.2.下载/制作启动U盘工具(balenaEtcher)2.3.设置BIOS相关内容2.3.1.U......
  • delphi 11.2 配置Linux 开发环境
    转自https://www.cnblogs.com/xalion/p/16858230.htmldelphi11.2配置Linux开发环境1.rockylinux9 命令行: mvlibpython3.solibpython3.so_  ln-s/......
  • C程序中插入LINUX命令
    格式:system("......");//引号中为要执行的命令;例如创建共享内存的时候需要先生成key,生成key需要创建一个文件(最好在/dev/shm下创建一个),此时可以在生成key之......
  • 12月将发布 Linux Mint 18.1″Serena” 公测版
    ​​Linux​​ Mint在月度简报上,LinuxMint负责人ClementLefebvre重申强调了关于即将到来LinuxMint18.1“Serena”操作系统的相关信息。该发行版本目前仍在开发进程中,......
  • linux安装及练习
    完成安装Ubuntu及账号密码填写练习了创建目录删除目录,查看目录内容,查看当前目录,查看日期,返回上一目录,进入指定目录操作 ......
  • 12月将发布 Linux Mint 18.1″Serena” 公测版
    Linux Mint在月度简报上,LinuxMint负责人ClementLefebvre重申强调了关于即将到来LinuxMint18.1“Serena”操作系统的相关信息。该发行版本目前仍在开发进程中,......