[SOLVED] Accessing a host partition from inside a container

Discussion in 'Proxmox VE: Installation and configuration' started by Helio Mendonça, May 22, 2019.

  1. Helio Mendonça

    Helio Mendonça New Member

    Joined:
    Apr 10, 2019
    Messages:
    26
    Likes Received:
    0
    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
     
    #1 Helio Mendonça, May 22, 2019
    Last edited: May 22, 2019
  2. msg7086

    msg7086 New Member

    Joined:
    May 1, 2018
    Messages:
    7
    Likes Received:
    0
    If that's all you did, then you forgot to umount it from host system.
     
  3. Helio Mendonça

    Helio Mendonça New Member

    Joined:
    Apr 10, 2019
    Messages:
    26
    Likes Received:
    0
    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?
     
    #3 Helio Mendonça, May 23, 2019
    Last edited: May 23, 2019
  4. oguz

    oguz Proxmox Staff Member
    Staff Member

    Joined:
    Nov 19, 2018
    Messages:
    505
    Likes Received:
    49
    hi.

    no. that's normal.

    i'll try to do the same thing you did and let you know in a bit.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. oguz

    oguz Proxmox Staff Member
    Staff Member

    Joined:
    Nov 19, 2018
    Messages:
    505
    Likes Received:
    49
    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
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
    Helio Mendonça likes this.
  6. Helio Mendonça

    Helio Mendonça New Member

    Joined:
    Apr 10, 2019
    Messages:
    26
    Likes Received:
    0
    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
     
  7. oguz

    oguz Proxmox Staff Member
    Staff Member

    Joined:
    Nov 19, 2018
    Messages:
    505
    Likes Received:
    49
    i'm glad it worked. you can mark as [SOLVED] if you'd like (need to edit your first post)

    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
    Helio Mendonça likes this.
  8. Helio Mendonça

    Helio Mendonça New Member

    Joined:
    Apr 10, 2019
    Messages:
    26
    Likes Received:
    0
    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
     
    #8 Helio Mendonça, May 23, 2019
    Last edited: May 23, 2019
  9. oguz

    oguz Proxmox Staff Member
    Staff Member

    Joined:
    Nov 19, 2018
    Messages:
    505
    Likes Received:
    49
    thank you for the clarification!
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice