<div dir="ltr">That last error could just be lack of /dev mounts, but glad you were able to get it working, thanks for reporting back.<div><br></div><div>Cal</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Thu, Dec 19, 2013 at 2:29 AM, Antonin Bas <span dir="ltr"><<a href="mailto:antoninb@stanford.edu" target="_blank">antoninb@stanford.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Thanks Cal. I will look into this.<br>
However, for now, I have found a quick fix. I just added "lxc.pivotdir<br>
= /mnt" to my config file. The pivotdir is used when pivoting the<br>
original root file system. It seems that in older versions of lxc, the<br>
default value was /mnt but this was changed since (in my case it was<br>
/usr/lib/x86_64-linux-gnu/<br>
lxc/lxc_putold by default). Nothing is actually written in this<br>
directory, so it can work even in read-only mode. However, if this<br>
location does not exist lxc will try to create it, which will fail.<br>
mnt/ exists so no problem.<br>
I hope I did not break anything by changing it to /mnt. So far it<br>
seems to be working.<br>
Note that I still have the following error:<br>
<div class="im"><br>
lxc-execute: Read-only file system - error unlinking<br>
/usr/lib/x86_64-linux-gnu/lxc/<br>
dev/kmsg<br>
<br>
</div>but it does not provide the container from spawning.<br>
<div class="HOEnZb"><div class="h5"><br>
Antonin<br>
<br>
2013/12/18 Cal Leeming [Simplicity Media Ltd]<br>
<<a href="mailto:cal.leeming@simplicitymedialtd.co.uk">cal.leeming@simplicitymedialtd.co.uk</a>>:<br>
> It looks like something being executed is expecting your rootfs to be<br>
> writeable, this could be something in lxc-execute or it could be /bin/bash<br>
> itself (I wouldn't know without strace'ing both or looking at the source).<br>
><br>
> You could try adding the necessary /dev, /proc and /sys mounts, which may be<br>
> enough to get it to run without error (add the following into your lxc<br>
> config);<br>
> <a href="http://pastebin.com/ZAcXn926" target="_blank">http://pastebin.com/ZAcXn926</a><br>
><br>
> However any applications expecting a write-able FS are going to fail hard -<br>
> for example, anything relying on /tmp, or /var/log, and numerous other<br>
> places. You could in theory bind mount a ramfs to those locations, but it<br>
> would be easier, in my opinion, to use a stacked file system.<br>
><br>
> Here is an example of using overlayfs;<br>
> <a href="http://askubuntu.com/questions/109413/how-do-i-use-overlayfs" target="_blank">http://askubuntu.com/questions/109413/how-do-i-use-overlayfs</a><br>
><br>
> In short, you'd build your container rootfs and make whatever changes you<br>
> wanted to make, once you're happy with it you then do;<br>
><br>
> $ mount -t overlayfs -o<br>
> lowerdir=/your.rootfs.here,upperdir=/your.discarded.changes.here overlayfs<br>
> /your.new.mount.here<br>
> lxc.rootfs = /your.new.mount.here<br>
><br>
> There is also a previous discussion on this;<br>
> <a href="http://osdir.com/ml/lxc-chroot-linux-containers/2011-07/msg00019.html" target="_blank">http://osdir.com/ml/lxc-chroot-linux-containers/2011-07/msg00019.html</a><br>
> <a href="https://www.redhat.com/archives/libvirt-users/2011-December/msg00024.html" target="_blank">https://www.redhat.com/archives/libvirt-users/2011-December/msg00024.html</a><br>
> <a href="http://s3hh.wordpress.com/2011/09/22/sharing-mounts-with-a-container/" target="_blank">http://s3hh.wordpress.com/2011/09/22/sharing-mounts-with-a-container/</a><br>
> <a href="https://www.mail-archive.com/lxc-users@lists.sourceforge.net/msg02190.html" target="_blank">https://www.mail-archive.com/lxc-users@lists.sourceforge.net/msg02190.html</a><br>
><br>
> Hope this helps<br>
><br>
> Cal<br>
><br>
><br>
> On Thu, Dec 19, 2013 at 1:51 AM, Antonin Bas <<a href="mailto:antoninb@stanford.edu">antoninb@stanford.edu</a>> wrote:<br>
>><br>
>> Hi,<br>
>><br>
>> I guess that could do it. But I don't understand while it would not be<br>
>> possible to have a read-only rootfs (i.e. is what I am seeing the<br>
>> expected behaviour?).<br>
>> What would the configuration look like if I decided to use overlayfs?<br>
>> Is it easy to use with lxc-execute? Because I just want to run an<br>
>> application, and I don't want to pay the overhead of<br>
>> lxc-start-ephemeral.<br>
>><br>
>> Thanks,<br>
>><br>
>> Antonin<br>
>><br>
>> 2013/12/18 Cal Leeming [Simplicity Media Ltd]<br>
>> <<a href="mailto:cal.leeming@simplicitymedialtd.co.uk">cal.leeming@simplicitymedialtd.co.uk</a>>:<br>
>> > Would it not be better to use a stacked file system, such as overlayfs<br>
>> > or<br>
>> > aufs, then discard the changes?<br>
>> ><br>
>> > Cal<br>
>> ><br>
>> ><br>
>> > On Thu, Dec 19, 2013 at 12:49 AM, Antonin Bas <<a href="mailto:antoninb@stanford.edu">antoninb@stanford.edu</a>><br>
>> > wrote:<br>
>> >><br>
>> >> Hi,<br>
>> >><br>
>> >> I am trying to run an application container with lxc-execute. I am<br>
>> >> going to run "untrusted" student codes in this container and I want<br>
>> >> the root file system to be shared with the host but read-only. I<br>
>> >> thought this would be as easy as using the following configuration<br>
>> >> file:<br>
>> >><br>
>> >> # Container with new network withtout network devices<br>
>> >> lxc.utsname = omega<br>
>> >> lxc.network.type = empty<br>
>> >> lxc.network.flags = up<br>
>> >><br>
>> >> lxc.rootfs = /tmp/guest/rootfs<br>
>> >> lxc.mount.entry=/ /tmp/guest/rootfs/ none ro,bind 0 0<br>
>> >><br>
>> >> However, when I run `sudo lxc-execute -n test -f grader.conf<br>
>> >> --logpriority=DEBUG -- /bin/bash`, I get the following message:<br>
>> >><br>
>> >> lxc-execute: Read-only file system - error unlinking<br>
>> >> /usr/lib/x86_64-linux-gnu/lxc/dev/kmsg<br>
>> >><br>
>> >> lxc-execute: failed to setup kmsg for 'test'<br>
>> >> lxc-execute: Read-only file system - failed to create directory<br>
>> >> '/usr/lib/x86_64-linux-gnu/lxc/lxc_putold'<br>
>> >><br>
>> >> lxc-execute: Read-only file system - failed to create pivotdir<br>
>> >> '/usr/lib/x86_64-linux-gnu/lxc/lxc_putold'<br>
>> >> lxc-execute: failed to setup pivot root<br>
>> >> lxc-execute: failed to set rootfs for 'test'<br>
>> >> lxc-execute: failed to setup the container<br>
>> >> lxc-execute: invalid sequence number 1. expected 2<br>
>> >> lxc-execute: failed to spawn 'test'<br>
>> >><br>
>> >><br>
>> >> Is it possible to have some insight on what the problem is here?<br>
>> >> I am using Ubuntu 13.10, and my lxc is the one from the official repo<br>
>> >> (1.0.0.alpha1).<br>
>> >><br>
>> >> Thanks you in advance for your help,<br>
>> >><br>
>> >> Antonin<br>
>> >> _______________________________________________<br>
>> >> lxc-users mailing list<br>
>> >> <a href="mailto:lxc-users@lists.linuxcontainers.org">lxc-users@lists.linuxcontainers.org</a><br>
>> >> <a href="http://lists.linuxcontainers.org/listinfo/lxc-users" target="_blank">http://lists.linuxcontainers.org/listinfo/lxc-users</a><br>
>> ><br>
>> ><br>
>> ><br>
>> > _______________________________________________<br>
>> > lxc-users mailing list<br>
>> > <a href="mailto:lxc-users@lists.linuxcontainers.org">lxc-users@lists.linuxcontainers.org</a><br>
>> > <a href="http://lists.linuxcontainers.org/listinfo/lxc-users" target="_blank">http://lists.linuxcontainers.org/listinfo/lxc-users</a><br>
>> _______________________________________________<br>
>> lxc-users mailing list<br>
>> <a href="mailto:lxc-users@lists.linuxcontainers.org">lxc-users@lists.linuxcontainers.org</a><br>
>> <a href="http://lists.linuxcontainers.org/listinfo/lxc-users" target="_blank">http://lists.linuxcontainers.org/listinfo/lxc-users</a><br>
><br>
><br>
><br>
> _______________________________________________<br>
> lxc-users mailing list<br>
> <a href="mailto:lxc-users@lists.linuxcontainers.org">lxc-users@lists.linuxcontainers.org</a><br>
> <a href="http://lists.linuxcontainers.org/listinfo/lxc-users" target="_blank">http://lists.linuxcontainers.org/listinfo/lxc-users</a><br>
_______________________________________________<br>
lxc-users mailing list<br>
<a href="mailto:lxc-users@lists.linuxcontainers.org">lxc-users@lists.linuxcontainers.org</a><br>
<a href="http://lists.linuxcontainers.org/listinfo/lxc-users" target="_blank">http://lists.linuxcontainers.org/listinfo/lxc-users</a><br>
</div></div></blockquote></div><br></div>