在固件开发过程中常常遇到这样的情况:为测试某个新功能,必需修改某个系统文件。而这个文件在只读文件系统上(总不能为一个小小的测试就重刷固件吧),或者是虽然文件可写,但是自己对这个改动没有把握,不愿意直接修改。这时候mount --bind就是你的好帮手。
假设我们要改的文件是/etc/hosts,可按下面的步骤操作:
1. 把新的hosts文件放在/tmp下。当然也可放在硬盘或U盘上。
2. mount --bind /tmp/hosts /etc/hosts
测试完成了执行 umount /etc/hosts 断开绑定。
如果我需要在/etc下面增加一个exports文件怎么办?原来没有这个文件,不能直接bind。我们有两个方法:
方法1:绑定整个/etc目录,绑定前先复制/etc

# cp -a /etc /tmp
# mount --bind /tmp/etc /etc

此时的/etc目录是可写的,所做修改不会应用到原来的/etc目录,可以放心测试。
方法2:挂载ramfs到/etc,同样要先复制/etc

挂载ramfs
# mkdir /tmp/etc
# mount -t ramfs none /tmp/etc
复制/etc,这里我们不能用cp -a,改用tar
# cd /etc
# tar cf - . |(cd /tmp/etc; tar xf -)
# cd /
覆盖/etc
# mount --move /tmp/etc /etc

测试完了记着 umount /etc

mount --bind 的妙用的更多相关文章

  1. mount --bind 重启后失效的解决办法

    vsftp不支持软链接,可以用mount来支持不同的目录结构 mount --bind /home/www/web/ROOT/img/upload /ftp/private/upload 重启后失效. ...

  2. mount --bind使用方法

    我们可以通过mount --bind命令来将两个目录连接起来,mount --bind命令是将前一个目录挂载到后一个目录上,所有对后一个目录的访问其实都是对前一个目录的访问,如下所示: ## test ...

  3. mount --bind

    [root@iZwz9i55e7v33yn8ksnh8nZ ~]# mkdir /tmp/dir1 [root@iZwz9i55e7v33yn8ksnh8nZ ~]# mkdir /tmp/dir2 ...

  4. ln -s vs mount --bind

    First ,Symlinks and bind mounts are a whole different ballgame. ln -s you create a symbolic link,whi ...

  5. mount --bind绑定命令

    将目录或文件DirFile-1绑定到目录或文件DirFile-2上,所有对DirFile-2的访问就是对DirFile-1的访问 mount --bind [DirFile-1] [DirFile-2 ...

  6. 查看一个目录是否已经mount --bind

    执行 mountpoint -q /test/mount echo $? 如果是0表示已经mount mountpoint -q /test/mount || mount -o bind /some/ ...

  7. Data Volume 之 bind mount - 每天5分钟玩转 Docker 容器技术(39)

    storage driver 和 data volume 是容器存放数据的两种方式,上一节我们学习了 storage driver,本节开始讨论 Data Volume. Data Volume 本质 ...

  8. 37-Data Volume 之 bind mount

    storage driver 和 data volume 是容器存放数据的两种方式,上一节我们学习了 storage driver,本节开始讨论 Data Volume. Data Volume 本质 ...

  9. 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 m ...

随机推荐

  1. 8 -- 深入使用Spring -- 1...2 Bean后处理器的用处

    8.1.2 Bean后处理器的用处 Spring提供的两个常用的后处理器: ⊙ BeanNameAutoProxyCreator : 根据Bean实例的name属性,创建Bean实例的代理. ⊙ De ...

  2. AddParent

    using UnityEngine; using UnityEditor; using System.Collections; public class AddParent : ScriptableO ...

  3. <转>Python: __init__.py 用法

    转自 http://www.cnblogs.com/BeginMan/p/3183629.html python的每个模块的包中,都有一个__init__.py文件,有了这个文件,我们才能导入这个目录 ...

  4. UVALive - 3507 Keep the Customer Satisfied

    题意:收到n个订单,每个订单有q,d分别代表做这个的时间,和最晚的完成时间,问你最多能接受几个订单 思路:贪心,我们显然要按最早的完成时间排序,那么接下来,我们用(6,8)和(4,9)做为例子,按照我 ...

  5. ios-toolchain-based-on-clang-for-linux

    https://github.com/tpoechtrager/cctools-port.git https://www.embtoolkit.org

  6. sendfile Linux函数

    现在流行的 web 服务器里面都提供sendfile 选项用来提高服务器性能,那到底 sendfile 是什么,怎么影响性能的呢? sendfile 实际上是 Linux 2.0+ 以后的推出的一个系 ...

  7. Elasticsearch学习之深入聚合分析一---基本概念

    首先明白两个核心概念:bucket和metric 1. bucket:一个数据分组 city name 北京 小李 北京 小王 上海 小张 上海 小丽 上海 小陈 基于city划分buckets,划分 ...

  8. [Vue warn]: Error in render: "SyntaxError: Unexpected token ' in JSON at position 1"

    一,场景: 字符串转对象: var str = "{'bankRate':5,'YINGUO':0}" 二,操作: JSON.parse(str)时候,报错 [Vue warn]: ...

  9. MySQL里面的子查询

    一.子查询定义 定义: 子查询允许把一个查询嵌套在另一个查询当中. 子查询,又叫内部查询,相对于内部查询,包含内部查询的就称为外部查询. 子查询可以包含普通select可以包括的任何子句,比如:dis ...

  10. HDU 2102 A计划(BFS/DFS走迷宫)

    A计划 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...