Mount disk to Container

omglolyes

New Member
Oct 26, 2020
2
0
1
34
So I am trying to do pretty much the same as in this thread, but instead of mounting the disk to a VM, mount it to a container.

I followed the steps but was unable to find it in the containers terminal and also my disk wouldnt show up in the resources of proxmox's webgui.

Did I do something wrong? TIA
 
hi,

for containers mounting a disk is easier with bind mounts. for example if your disk is mounted to /mnt/mydisk on your PVE host, you can add something like this in your container config:
Code:
$ cat /etc/pve/lxc/100.conf
<SNIP>
mp0: /mnt/mydisk,mp=/mydisk

restart the container afterwards and it should be mounted to /mydisk in the CT
 
hi,

for containers mounting a disk is easier with bind mounts. for example if your disk is mounted to /mnt/mydisk on your PVE host, you can add something like this in your container config:
Code:
$ cat /etc/pve/lxc/100.conf
<SNIP>
mp0: /mnt/mydisk,mp=/mydisk

restart the container afterwards and it should be mounted to /mydisk in the CT
can the disk be shared between multiple containers? I am planning to run a cifs (samba) and plex in two separate containers both need access to same filesystem. If its bind mount in theory I can mount same `/dev/disk/by-id/<xxx>` to two different containers and they will not get into any file system corruption, right?
 
can the disk be shared between multiple containers? I am planning to run a cifs (samba) and plex in two separate containers both need access to same filesystem. If its bind mount in theory I can mount same `/dev/disk/by-id/<xxx>` to two different containers and they will not get into any file system corruption, right?
absolutely.
this above method essentially is passing limited access to a host directory through to the container at a mountpoint. user/group permissions you set on host for the passed through directory, can inherit in the container making it quite seamless.

in the long run you might find it simpler to just setup that samba container, let it handle file sharing.
then just connect to it from within any future VMs and containers you create.
 
Hello everyone!
I'm new to proxmox (I'm using version 8.0.3) and I have a problem with a disk I added as a directory in my node.
The disk was then added to a container by editing the .conf file as indicated by @oguz in this thread.
In the container the disk is mounted correctly and I also can see the 'reserved' folders (dumps, images, templates, ...), but I do not have the rights to create new files or folders.
What commands am I missing to be able to write to the disk from the container?
 
In the meantime, I did some more tests.
I changed the .conf file of the container and initially removed the mount made earlier, saving the file (but I do not remember if I restarted the container).
I then added the previous mount back into the .conf file, but not to the whole disk, but to a folder of it (called "Files").
After restarting the container, inside the /mnt folder of the container I now have both the folder I made with the last mount command (Files), but also the name of the disk (WD4), used in the previous mount command, which I do not know how to remove.
Furthermore, even if I log in as root user in the container (it's a Debian 12), it doesn't allow me to give permissions on the new mounted folder (chmod give me the error "Operation not permitted").
The folder belongs to nobody:nogroup.
How can I solve this permissions problem?
 
Hi,
In the meantime, I did some more tests.
I changed the .conf file of the container and initially removed the mount made earlier, saving the file (but I do not remember if I restarted the container).
I then added the previous mount back into the .conf file, but not to the whole disk, but to a folder of it (called "Files").
After restarting the container, inside the /mnt folder of the container I now have both the folder I made with the last mount command (Files), but also the name of the disk (WD4), used in the previous mount command, which I do not know how to remove.
Furthermore, even if I log in as root user in the container (it's a Debian 12), it doesn't allow me to give permissions on the new mounted folder (chmod give me the error "Operation not permitted").
The folder belongs to nobody:nogroup.
How can I solve this permissions problem?
please see https://pve.proxmox.com/wiki/Unprivileged_LXC_containers
 
Thank you for the reply.
I actually created an unprivileged container (I left the default value during creation).
I followed the guide in your link, but when I get to the last step (i.e. the command on the host "chown -R 1005:1005 /mnt/bindmounts/shared") it gives me an error (Operation not permitted) on all directories and files ond the HDD.
The only perplexity I have is when I edit the /etc/subuid and /etc/subgid files: there is already a line in them (root:100000:65536) and I don't know whether the new line should be added to this one or should replace it.
I thought it would be easier to manage data disks in a container...
 
Thank you for the reply.
I actually created an unprivileged container (I left the default value during creation).
I followed the guide in your link, but when I get to the last step (i.e. the command on the host "chown -R 1005:1005 /mnt/bindmounts/shared") it gives me an error (Operation not permitted) on all directories and files ond the HDD.
What do stat /mnt/bindmounts/shared and findmnt | grep bindmounts show? As what user did you run the command?
The only perplexity I have is when I edit the /etc/subuid and /etc/subgid files: there is already a line in them (root:100000:65536) and I don't know whether the new line should be added to this one or should replace it.
You need to add a new one. The existing one is for the default unprivileged map I think.
I thought it would be easier to manage data disks in a container...
Not if you want actual isolation ;)
 
What do stat /mnt/bindmounts/shared and findmnt | grep bindmounts show? As what user did you run the command?
The first command show this:

Code:
  File: /mnt/bindmounts/shared
  Size: 4096            Blocks: 8          IO Block: 4096   directory
Device: 8,33    Inode: 1           Links: 8
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 1970-01-01 01:00:00.000000000 +0100
Modify: 1970-01-01 01:00:00.000000000 +0100
Change: 1970-01-01 01:00:00.000000000 +0100
 Birth: 1970-01-01 01:00:00.000000000 +0100

The second command show nothing.
I run the command with root user in host (the only one user on both host and guest machine).
 
Last edited:
The first command show this:

Code:
  File: /mnt/bindmounts/shared
  Size: 4096            Blocks: 8          IO Block: 4096   directory
Device: 8,33    Inode: 1           Links: 8
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 1970-01-01 01:00:00.000000000 +0100
Modify: 1970-01-01 01:00:00.000000000 +0100
Change: 1970-01-01 01:00:00.000000000 +0100
 Birth: 1970-01-01 01:00:00.000000000 +0100

The second command show nothing.
Was the container running when you tried to change the permissions? The timestamps are all the earliest possible here so that is odd. Is this actually the directory you want to share with the container?

I run the command with root user in host (the only one user on both host and guest machine).
Then you need to map the outside ID (can be root, but I'd suggest not for better isolation) to root (= ID 0) inside the container. The example assumes that a user with ID 1005 exists both outside and inside the container.
 
Was the container running when you tried to change the permissions? The timestamps are all the earliest possible here so that is odd. Is this actually the directory you want to share with the container?

The first time yes, the container was running, but I've got the error also when the container is stopped.
I don't know what I can do now...

EDIT
I am trying to understand where the problem lies.
I am testing with a USB stick formatted in FAT32. From the command line in the host system I can mount the disk correctly (even entering the string in fstab) and give rights to the root user. If I check, the mount folder belongs to the root user.

After this I added the mount folder to Storage with the proxmox web interface as a directory.

After this I edited the container's conf file.

However, if I try to give the command chown to the mount folder (logging in as root user in Host) it does not allow me.

I really don't understand where the problem lies.
(Proxmox version 8.0.3)

Found also this link with another method (Method 1): in the first method mentioned I think there is an error in the command (perhaps is chown and not chmod).
The second method is the same that in the Proxmox wiki...
 
Last edited:
I am trying to understand where the problem lies.
I am testing with a USB stick formatted in FAT32. From the command line in the host system I can mount the disk correctly (even entering the string in fstab) and give rights to the root user. If I check, the mount folder belongs to the root user.
FAT32 does not support Unix-style file owner/permissions. Maybe you can specify the user (ID) it should belong to via mount options, but not sure.
 
FAT32 does not support Unix-style file owner/permissions. Maybe you can specify the user (ID) it should belong to via mount options, but not sure.
Yes!
After many tests, I was able to realise that the FAT32 filesystem was the problem.
By repeating the same procedure for an ext4 disk, everything worked (finally!).
I think the solution proposed in this thread (slightly different for group management) is preferable to the one on the wiki page,
 
  • Like
Reactions: fiona

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 yours easily in our online shop.

Buy now!