[SOLVED] Accessing a host partition from inside a container

Helio Mendonça

Active Member
Apr 10, 2019
73
6
28
I know, I know there are here a lot of posts about this issue but I still can not do this apparently easy task! :(
The majority of those posts say that I need to edit the container conf file with the a line similar with:
Code:
mp0: /dev/sdb1,mp=/mnt/ext,backup=0

The container starts without any problem but when I go to the mounted folder, it is empty!

Here is the all process (including the creation of the partition, and the mounting points):
Code:
@CT126:
# create folder to mount the external partition
mkdir -p /mnt/ext
# shutdown the container
poweroff

@PVE host:
# initialise HDD using GPT
parted /dev/sdb mklabel gpt
# create a partition using 10% of its space
parted -a opt /dev/sdb mkpart primary ext4 0% 10%
# create ext4 file system on it
mkfs.ext4 -L data /dev/sdb1
# create folder to mount that partition
mkdir -p /mnt/data
# update fstab with that mount
echo "LABEL=data /mnt/data ext4 defaults 0 2" >> /etc/fstab
# and do it
mount -a
# create a test file in that mount
touch /mnt/data/file.txt
# check if the file exists
ls /mnt/data
# YES it does!
# update the container conf file with that mount point
echo "mp0: /dev/sdb1,mp=/mnt/ext,backup=0" >> /etc/pve/lxc/126.conf
# start the container
lxc-start -n 126 --logfile /dev/stdout

@CT126:
# check if the test file exists
ls /mnt/ext
# NO it does not!!! :(

Any help please?
Thanks
 
Last edited:
Even unmounting it from the host I still can not access it inside the container!

I noticed that the /etc/fstab inside the container is still empty. Could not this be a problem?

Any other tip on how to solve this?
Thanks

PS - If I can not solve this I will try to do it through a NFS server/client approach, but c'mon using mount points should be possible, right?
 
Last edited:
hi.

I noticed that the /etc/fstab inside the container is still empty. Could not this be a problem?

no. that's normal.

i'll try to do the same thing you did and let you know in a bit.
 
i was able to get it working with an alpine linux container, following the exact same commands you wrote. (i touched a file from host and i could see it in the container.)

maybe you have an older proxmox version where this wasn't implemented yet? if that's the case, you can try to manually `mknod` in the container config, to get it recognized in the container. (search the forum, you'll find similar topics where this was mentioned)

if your pve isn't old, then please send your `pveversion -v` output and maybe a container debug log[0]

[0]: https://pve.proxmox.com/pve-docs/chapter-pct.html#_obtaining_debugging_logs
 
  • Like
Reactions: Helio Mendonça
Just to say that in fact with a Alpine template (default_20190224_amd64.tar.xz)... IT WORKS!!! :)
But why the template I was using (ubuntu-16.04-standard_16.04.5-1_amd64.tar.gz) did not?!?
By the way, I just also tried the ubuntu-18.04-standard_18.04.1-1_amd64.tar.gz template and ALSO WORKED!!!
Conclusion: The problem was in the Ubuntu 16.04 version!?!
Can I do anything in Ubuntu 16.04 to make it work also?

PS - I think I have the latest version of PVE: 5.4-5
 
Just to say that in fact with a Alpine template (default_20190224_amd64.tar.xz)... IT WORKS!!! :)
But why the template I was using (ubuntu-16.04-standard_16.04.5-1_amd64.tar.gz) did not?!?
By the way, I just also tried the ubuntu-18.04-standard_18.04.1-1_amd64.tar.gz template and ALSO WORKED!!!

i'm glad it worked. you can mark as [SOLVED] if you'd like (need to edit your first post)

Conclusion: The problem was in the Ubuntu 16.04 version!?!
Can I do anything in Ubuntu 16.04 to make it work also?

i might still be able to help you get it working on the ubuntu 16.04 version, but you will need to send me debug logs and `pveversion -v` as i mentioned in my previous post.
 
  • Like
Reactions: Helio Mendonça
Well... let me clarity one last thing.
The problem was not Ubuntu16.04 after all!
The problem was the way I was editing the conf file of the container!
Let me explain...
I was using a container that had several snapshots, and for each one is created a new section in the conf file.
I though that I just needed to add the "mp0: /dev..." line on the end of the conf file but in fact the line should appear in all sections, specially in the FIRST ONE!

Code:
arch: amd64
cores: 2
...
rootfs: local-lvm:vm-125-disk-0,size=16G
swap: 512
unprivileged: 1
mp0: /dev/sdb1,mp=/mnt/ext,backup=0           <---------- the one that is really needed

[snapshot1]
arch: amd64
cores: 2
...
swap: 512
unprivileged: 1
mp0: /dev/sdb1,mp=/mnt/ext,backup=0

[snapshot2]
arch: amd64
cores: 2
...
swap: 512
unprivileged: 1
mp0: /dev/sdb1,mp=/mnt/ext,backup=0           <---------- the one that I thought was enough

I hope my statement can avoid others to commit the same error!
Shame on me I know!!! :D
 
Last edited:
thank you for the clarification!
 
Resurrecting this old thread... I got the lxc container to see the host partition just fine. This is great! I am wondering though if it could cause issues if I also did this to multiple other lxc containers. Would there be any danger of file corruption?

I'm trying to avoid setting up a full NAS (virtualized one) just to share files across vms and lxcs. I essentially have a media partition that I'd like to have nextcloud, jellifyn, and other media oriented services use at the same time...
 
Would there be any danger of file corruption?
If you want to change the same file at the same time,. If that does not happen, you're fine.

I'm trying to avoid setting up a full NAS (virtualized one) just to share files across vms and lxcs.
You cannot share it with the same logic (bind mount) with VMs, only containers. If you want to share it with all types, you need a network storage like NFS or CIFS (so setting up a NAS).
 

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!