[SOLVED] Accessing a host partition from inside a container

Apr 10, 2019
34
3
8
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:
Apr 10, 2019
34
3
8
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:

oguz

Proxmox Staff Member
Staff member
Nov 19, 2018
703
75
28
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.
 

oguz

Proxmox Staff Member
Staff member
Nov 19, 2018
703
75
28
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
Apr 10, 2019
34
3
8
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
 

oguz

Proxmox Staff Member
Staff member
Nov 19, 2018
703
75
28
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
Apr 10, 2019
34
3
8
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:

oguz

Proxmox Staff Member
Staff member
Nov 19, 2018
703
75
28
thank you for the clarification!
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE 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!