[lxc-users] How do you mount this file as an lxc rootfs?

Serge E. Hallyn serge at hallyn.com
Mon Jun 20 15:51:41 UTC 2016


Quoting John Lewis (oflameo2 at gmail.com):
> On 06/20/2016 10:34 AM, Mike Wright wrote:
> > On 06/20/2016 07:22 AM, John Lewis wrote:
> >> On 06/20/2016 10:04 AM, Mike Wright wrote:
> >>> On 06/20/2016 06:47 AM, John Lewis wrote:
> >>>> I have a ext4 formatted file called pmd.simg with a directory
> >>>> structure
> >>>> like this.
> >>>>
> >>>> lost+found  rootfs
> >>>
> >>> You should be able to mount that via the loop device:
> >>>
> >>> <code>
> >>> mount pmd.simg <mount_point> -o loop
> >>> </code>
> >>>
> >>> Then rootfs will be available at <mount_point>/rootfs
> >>>
> >> Sorry I think I spoke too soon. Is there any way to do this inside the
> >> lxc container configuration file?
> >>
> > I may be out of my league here but you could try using a pre-start hook.
> >
> > Put your mount command into a shell script and then invoke it from
> > your config file:
> >
> > lxc.hook.pre-start = <path to mount script>
> >
> > Hope that works.
> > _______________________________________________
> > lxc-users mailing list
> > lxc-users at lists.linuxcontainers.org
> > http://lists.linuxcontainers.org/listinfo/lxc-users
> I don't understand how it worked, but it did. The pmd directory is

The pre-mount hook runs in the container's mount namespace but before
mounting the rootfs.  So the fs you mount only shows up in the container's
namespace, not on the host.  Auto-cleanup is just a nice bonus.  I would
have been not entirely surprised if the loopdev remained attached, happy
to see it apparently gets cleaned up.

> empty, but the lxc is running. The loop device removes itself after I
> stop the lxc. The /usr/lib/x86_64-linux-gnu/lxc/rootfs/ has a readme file.
> 
>     lxc-start 1466435077.780 INFO     lxc_conf - Executing script
> '/var/lib/lxc/pmd/pre-mount.sh' for container 'pmd', config section 'lxc'
> 
>       lxc-start 1466435077.788 DEBUG    lxc_conf - mounted
> '/home/diskimg/lxc/pmd/rootfs' on '/usr/lib/x86_64-linux-gnu/lxc/rootfs'
> 


> _______________________________________________
> lxc-users mailing list
> lxc-users at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-users



More information about the lxc-users mailing list