how to mount a folder from lxc

2020-03-24 06:23发布

I have the lxc, it has a running application. To edit the code of this application on own computer(Ubuntu 13.10), I want to mount a directory lxc. How can this be done?

for example

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

mounted in /mnt/lxc

标签: ubuntu mount lxc
2条回答
我命由我不由天
2楼-- · 2020-03-24 07:09

Use "mount --bind"

man 8 mount

-B, --bind

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

Example

# 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

Notes

  1. Root has access to /var/lib/lxc/ubuntu_12_04/rootfs/home/ even without mounting.

  2. The user id in the lxc instance should equal the user id in the host. Otherwise you may need to change users (su someother_username) or change file ownership (chown myuser: somefile.txt.) Ubuntu starts at the same user id by default so if you're using the default user in both places, the user ids should equal.

  3. To check the user ids on files use ls --numeric-uid-gid or ls -n. Below you see a user id and group id of 1042.

    # show user and group ids
    ls -n
    -rw-r--r-- 1 1042 1042   0 May  15 15:31 example.txt
    
查看更多
手持菜刀,她持情操
3楼-- · 2020-03-24 07:22

If you want to mount automatically a directory inside the lxc each time you start the lxc you can use the lxc.mount.entry directory inside /var/lib/lxc/ubuntu_12_04/config file. With Something like:

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

This will mount /mnt/lxc inside the lxc root filesystem aka rootfs at home/ directory.

查看更多
登录 后发表回答