【问题标题】:how to mount a folder from lxc如何从 lxc 挂载文件夹
【发布时间】:2014-04-30 18:19:26
【问题描述】:

我有 lxc,它有一个正在运行的应用程序。 要在自己的计算机(Ubuntu 13.10)上编辑此应用程序的代码,我想挂载一个目录 lxc。如何做到这一点?

例如

/var/lib/lxc/ubuntu_12_04/rootfs/home/

安装在 /mnt/lxc

【问题讨论】:

  • 这和lxc没有太大关系。主机操作系统上的rootfs 目录只是一个常规目录,您可以从容器外部安全地写入它,您可以根据需要导出它(Samba、NFS 等)

标签: ubuntu mount lxc


【解决方案1】:

如果您想在每次启动 lxc 时自动挂载 lxc 内的目录,您可以使用 /var/lib/lxc/ubuntu_12_04/config 文件内的 lxc.mount.entry 目录。像这样的东西:

lxc.mount.entry = /mnt/lxc home/ none bind 0 0

这会将/mnt/lxc 挂载在lxc 根文件系统(又名rootfs)中home/ 目录中。

【讨论】:

    【解决方案2】:

    使用“mount --bind”

    man 8 mount

    -B, --绑定

    Remount a subtree somewhere else (so that its contents are available in both places).
    

    示例

    # make a mount point
    sudo mkdir /mnt/lxc
    
    # mount existing directory on the mount point
    mount --bind /var/lib/lxc/ubuntu_12_04/rootfs/home/ /mnt/lxc
    

    注意事项

    1. 即使没有挂载,Root 也可以访问 /var/lib/lxc/ubuntu_12_04/rootfs/home/。

    2. lxc 实例中的用户 ID 应等于主机中的用户 ID。否则,您可能需要更改用户 (su someother_username) 或更改文件所有权 (chown myuser: somefile.txt。) Ubuntu 默认以相同的用户 ID 启动,因此如果您在两个地方都使用默认用户,则用户 ID 应该相等。

    3. 要检查文件上的用户 ID,请使用 ls --numeric-uid-gidls -n。下面您会看到用户 ID 和组 ID 为 1042。

      # show user and group ids
      ls -n
      -rw-r--r-- 1 1042 1042   0 May  15 15:31 example.txt
      

    【讨论】:

      猜你喜欢
      • 2019-04-10
      • 2017-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-21
      • 2012-09-28
      • 2020-06-04
      • 1970-01-01
      相关资源
      最近更新 更多