Bind mounts and API

baptistemm

New Member
Nov 11, 2015
7
0
1
France
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
 

dietmar

Proxmox Staff Member
Staff member
Apr 28, 2005
17,127
526
133
Austria
www.proxmox.com
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.)

This exposes security problems, so only root should be allowed to do that. That is why it is not on the GUI.

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

yes, for example:

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

sirlance

New Member
Aug 3, 2016
8
0
1
41
This exposes security problems, so only root should be allowed to do that. That is why it is not on the GUI."

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).
 

fabian

Proxmox Staff Member
Staff member
Jan 7, 2016
7,932
1,528
164
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).

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?
 

sirlance

New Member
Aug 3, 2016
8
0
1
41
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?
 

fabian

Proxmox Staff Member
Staff member
Jan 7, 2016
7,932
1,528
164
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?

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)
 

Medvenda

Member
Oct 5, 2016
40
0
6
35
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
 

fabian

Proxmox Staff Member
Staff member
Jan 7, 2016
7,932
1,528
164
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 ..."
 
  • Like
Reactions: Medvenda

Medvenda

Member
Oct 5, 2016
40
0
6
35
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.
 
Last edited:

fabian

Proxmox Staff Member
Staff member
Jan 7, 2016
7,932
1,528
164
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.

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.
 

Medvenda

Member
Oct 5, 2016
40
0
6
35
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.
Thanks Fabian for your reply but i can not find how delete the mount point and the unesedX using API (http ou CLI)
 

fabian

Proxmox Staff Member
Staff member
Jan 7, 2016
7,932
1,528
164
Thanks Fabian for your reply but i can not find how delete the mount point and the unesedX using API (http ou CLI)

CLI: "pct set CTID -delete KEY" (e.g., "pct set 100 -delete unused0")
API: via "/api2/json/nodes/{node}/lxc/{vmid}/config"
 
  • Like
Reactions: Medvenda

Medvenda

Member
Oct 5, 2016
40
0
6
35
CLI: "pct set CTID -delete KEY" (e.g., "pct set 100 -delete unused0")
API: via "/api2/json/nodes/{node}/lxc/{vmid}/config"
Thanks,
i find this
nodes/{node}/lxc/{vmid}/config > set -delete mpX
nodes/{node}/lxc/{vmid}/config > set -delete unusedX
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get your own in 60 seconds.

Buy now!