1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Bind mounts and API

Discussion in 'Proxmox VE: Installation and configuration' started by baptistemm, Jun 13, 2016.

Tags:
  1. baptistemm

    baptistemm New Member

    Joined:
    Nov 11, 2015
    Messages:
    7
    Likes Received:
    0
    Hello,

    It this possible to create a mount between the host and a guest by editing the lxc configuration file.
    cat "mp0: /srv/directory,mp=/srv/directory" >> /etc/pve/lxc/<id>.conf
    it seems to be called a bind mount reading the page https://pve.proxmox.com/wiki/LXC_Bind_Mounts

    Since 4.2 it is possible to create a mount in the graphical assistant or with the API but actually it does something different by creating a separate disk. (By the way this is not clear to me what the expected JSON structure to pass.)

    So I like to know if it possible to create a bind mount through the API, that would be convenient.

    Regards
     
  2. dietmar

    dietmar Proxmox Staff Member
    Staff Member

    Joined:
    Apr 28, 2005
    Messages:
    15,224
    Likes Received:
    154
    This exposes security problems, so only root should be allowed to do that. That is why it is not on the GUI.

    yes, for example:

    # pvesh set /nodes/localhost/lxc/<CTID>/config -mp0 "/srv/directory,mp=/srv/directory"
     
  3. sirlance

    sirlance New Member

    Joined:
    Aug 3, 2016
    Messages:
    7
    Likes Received:
    0
    Would it be possible to specify a few 'allowed' root folders where this mounting is allowed via the API? I'm using ansible to create and manage lxc containers, and being able to manage my storage like that would be a huge help. My current options are some whacky/hacky crap like using ansible to modify the lxc container config file and then restart the container, or setting up a nfs server and mount the data from there (which is not optimal for several reasons) using nfs mounts specified in my ansible playbook.

    Being able to directly bind mount folders on the host directly would simplify things considerably. For example, backup would be much straightforward (at least in my setup).
     
  4. fabian

    fabian Proxmox Staff Member
    Staff Member

    Joined:
    Jan 7, 2016
    Messages:
    1,852
    Likes Received:
    188
    I'd like to do something like this for 5.x - allow the root@pam and Sys.Modify users to define a set of bind mount / shared folder sources as storage, and then allow regular users with access to this storage to use them as bind mounts in containers and shared folders in VMs.

    if you are using ansible to modify the container config you must already be root there? is it just that you want to avoid that or am I missing something?
     
  5. sirlance

    sirlance New Member

    Joined:
    Aug 3, 2016
    Messages:
    7
    Likes Received:
    0
    Ah, right. Sorry. Yes, I'm root, but I was using a different user for creating the container and that didn't work.
    I'll try again using root credentials, see whether that works. Ansible is using the REST api, that shouldn't make a difference though, right?
     
  6. fabian

    fabian Proxmox Staff Member
    Staff Member

    Joined:
    Jan 7, 2016
    Messages:
    1,852
    Likes Received:
    188
    in PVE, (almost completely) everything is using the REST API. whether you use "pct set", "pvesh" or the REST HTTP endpoint makes no real difference here, as long as the user is root@pam (which is implied for the CLI tools including pvesh)
     
  7. Medvenda

    Medvenda Member

    Joined:
    Oct 5, 2016
    Messages:
    40
    Likes Received:
    0
    Hello,
    I tried to add a mount point with NFS storage to lxc container using the web GUI and it's work fine and the additional disk is created on the NFS storage but using the REST API the disk (raw) in the NFS Storage is not created ( i can view the new mount point in lxc config or in the resources tab but of course when i tried to resize the mount point i have an error that volume does not exist)
    i use this command to test the creation of a mount point over API
    set -mp0 ProxNFS-MJA:124/vm-124-disk-1.raw,mp=/mnt/mja,size=1G
    where is the problem?
    Thanks
     
  8. fabian

    fabian Proxmox Staff Member
    Staff Member

    Joined:
    Jan 7, 2016
    Messages:
    1,852
    Likes Received:
    188
    you need to either allocate the image manually (via pvesm / the storage API) or use the "STORAGE:SIZE" syntax which auto-allocates an image (e.g., "pct set -mp0 ProxNFS-MJA:1,mp=/mnt/mja").

    what you did is "use the existing image ProxNFS-MJA:124/vm-124-disk-1.raw", not "createa new image ..."
     
    Medvenda likes this.
  9. Medvenda

    Medvenda Member

    Joined:
    Oct 5, 2016
    Messages:
    40
    Likes Received:
    0
    Thanks for your reply :)
     
  10. Medvenda

    Medvenda Member

    Joined:
    Oct 5, 2016
    Messages:
    40
    Likes Received:
    0
    How can i delete mount point and unused volume using API ?

    PS : i can delete the volume using this command
    delete /nodes/proxnode/storage/ProxNFS-MJA/content/ProxNFS-MJA:124/vm-124-disk-1.raw

    but not the config "unused" or the mount point for the container.
     
    #10 Medvenda, Apr 21, 2017
    Last edited: Apr 21, 2017
  11. fabian

    fabian Proxmox Staff Member
    Staff Member

    Joined:
    Jan 7, 2016
    Messages:
    1,852
    Likes Received:
    188
    if you delete a disk/mount point entry from a config, it will be moved to unusedX. if you delete the unusedX entry, it will be removed AND the associated storage volume will be deleted.
     
  12. Medvenda

    Medvenda Member

    Joined:
    Oct 5, 2016
    Messages:
    40
    Likes Received:
    0
    Thanks Fabian for your reply but i can not find how delete the mount point and the unesedX using API (http ou CLI)
     
  13. fabian

    fabian Proxmox Staff Member
    Staff Member

    Joined:
    Jan 7, 2016
    Messages:
    1,852
    Likes Received:
    188
    CLI: "pct set CTID -delete KEY" (e.g., "pct set 100 -delete unused0")
    API: via "/api2/json/nodes/{node}/lxc/{vmid}/config"
     
    Medvenda likes this.
  14. Medvenda

    Medvenda Member

    Joined:
    Oct 5, 2016
    Messages:
    40
    Likes Received:
    0
    Thanks,
    i find this
    nodes/{node}/lxc/{vmid}/config > set -delete mpX
    nodes/{node}/lxc/{vmid}/config > set -delete unusedX
     

Share This Page