Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 576574 - app-portage/grs with sys-apps/systemd: "cannot run because /sys/fs/group is read only"
Summary: app-portage/grs with sys-apps/systemd: "cannot run because /sys/fs/group is r...
Status: CONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Unspecified (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Anthony Basile
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-03-06 09:48 UTC by Michael Jones
Modified: 2016-03-07 01:18 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Jones 2016-03-06 09:48:40 UTC
This bug should probably be assigned to Blueness.

GRS tries to create a new cgroup tree in /sys/fs/cgroup .  Systemd mounts /sys/fs/cgroup as read only.

It's relatively simple to work around this.

remount -o remount,rw /sys/fs/cgroup




GRS would benefit from code that detects this situation and gives the users instructions they can follow.
Comment 1 Anthony Basile gentoo-dev 2016-03-06 17:35:44 UTC
(In reply to Michael Jones from comment #0)
> This bug should probably be assigned to Blueness.
> 
> GRS tries to create a new cgroup tree in /sys/fs/cgroup .  Systemd mounts
> /sys/fs/cgroup as read only.
> 
> It's relatively simple to work around this.
> 
> remount -o remount,rw /sys/fs/cgroup
> 
> 
> 
> 
> GRS would benefit from code that detects this situation and gives the users
> instructions they can follow.

yeah i've never run GRS on a systemd system.  What can go wrong with that remount.
Comment 2 Anthony Basile gentoo-dev 2016-03-06 18:41:34 UTC
(In reply to Michael Jones from comment #0)
>
> remount -o remount,rw /sys/fs/cgroup
> 

@systemd folks, does anyone know if remounting cgroup rw is bad?  GRS [1] is a suite for building releases (anything from stage1/2/3 to full blown desktops) and it makes use of cgroups to collect together processes associated with some chroot, much the way systemd-nspawn does.  To do so, it needs /sys/fs/cgroup to be read/write.  Is there any reason not to do so?


[1] https://wiki.gentoo.org/wiki/Project:RelEng_GRS
Comment 3 Mike Gilbert gentoo-dev 2016-03-06 20:53:16 UTC
(In reply to Anthony Basile from comment #2)

I don't fully understand why systemd mounts it readonly, but I think it should be fine to remount rw for this use case.
Comment 4 Michael Jones 2016-03-07 00:33:44 UTC
A possibility to consider is to optionally use systemd-nspawn, instead of chroot + cgroups on systems that use systemd.

https://www.freedesktop.org/software/systemd/man/systemd-nspawn.html
Comment 5 Anthony Basile gentoo-dev 2016-03-07 00:50:48 UTC
(In reply to Michael Jones from comment #4)
> A possibility to consider is to optionally use systemd-nspawn, instead of
> chroot + cgroups on systems that use systemd.
> 
> https://www.freedesktop.org/software/systemd/man/systemd-nspawn.html

can you suggest a patch for GRS?(In reply to Michael Jones from comment #4)
> A possibility to consider is to optionally use systemd-nspawn, instead of
> chroot + cgroups on systems that use systemd.
> 
> https://www.freedesktop.org/software/systemd/man/systemd-nspawn.html

i guess i can make it a configure option, either run the scripts in the build system via chroot+cgroups or via systemd-nspawn.  right now the chroot+cgroups system provides grsrun with the set of tasks running in the chroot so that its easy to clean up, something that catalyst can't do and which drives me crazy!  if its possible to use systemd-nspawn to do the same cleanup then i'll just have a switch in the code to use one or the other.  i'll probably have to add that over the summer when i have time.  in the mean time, i think i can just add a check if /sys/fs/cgroup  is mounted ro and remount it rw if it is.

lets leave this bug open to remind me to consider using systemd-nspawn.
Comment 6 Michael Jones 2016-03-07 00:54:20 UTC
I'll see if I can come up with a patch for grs that does what I suggested.

systemd-nspawn automatically runs all processes happening in the "chroot" of the nspawn environment in a cgroup. When the process that systemd-nspawn started in the chroot exits, all remaining processes are cleaned up.

Do you have multiple independent groups of processes that you track with cgroups? or just one group per build environment? If you track more than one group per build environment, maybe systemd-nspawn isn't a good fit.
Comment 7 Richard Freeman gentoo-dev 2016-03-07 00:55:43 UTC
nspawn will create its own cgroups, and I believe it will clean up everything in the container when the process it spawns dies (including mounts, etc).  I'm pretty sure that you can just sigterm nspawn and get it to do its own cleanup as well.
Comment 8 Anthony Basile gentoo-dev 2016-03-07 01:00:30 UTC
(In reply to Michael Jones from comment #6)
> I'll see if I can come up with a patch for grs that does what I suggested.
> 
> systemd-nspawn automatically runs all processes happening in the "chroot" of
> the nspawn environment in a cgroup. When the process that systemd-nspawn
> started in the chroot exits, all remaining processes are cleaned up.
> 
> Do you have multiple independent groups of processes that you track with
> cgroups? or just one group per build environment? If you track more than one
> group per build environment, maybe systemd-nspawn isn't a good fit.

GRS runs multiple concurrent build environments, but each one has only one group of tasks.  if you send grsrun SIGINT or SIGTERM, it will first send SIGTERM and then SIGKILL to all processes in the build env task group so that i can cleanup the chroot.  i think systemd-nspawn might be able to do that.
Comment 9 Anthony Basile gentoo-dev 2016-03-07 01:01:22 UTC
(In reply to Richard Freeman from comment #7)
> nspawn will create its own cgroups, and I believe it will clean up
> everything in the container when the process it spawns dies (including
> mounts, etc).  I'm pretty sure that you can just sigterm nspawn and get it
> to do its own cleanup as well.

sounds like i wrote my own "poor mans" version of nspawn on top of libcgroup.
Comment 10 Richard Freeman gentoo-dev 2016-03-07 01:18:23 UTC
(In reply to Anthony Basile from comment #8)
> (In reply to Michael Jones from comment #6)
> > I'll see if I can come up with a patch for grs that does what I suggested.
> > 
> > systemd-nspawn automatically runs all processes happening in the "chroot" of
> > the nspawn environment in a cgroup. When the process that systemd-nspawn
> > started in the chroot exits, all remaining processes are cleaned up.
> > 
> > Do you have multiple independent groups of processes that you track with
> > cgroups? or just one group per build environment? If you track more than one
> > group per build environment, maybe systemd-nspawn isn't a good fit.
> 
> GRS runs multiple concurrent build environments, but each one has only one
> group of tasks.  if you send grsrun SIGINT or SIGTERM, it will first send
> SIGTERM and then SIGKILL to all processes in the build env task group so
> that i can cleanup the chroot.  i think systemd-nspawn might be able to do
> that.

I agree.  Just launch one nspawn instance per environment.

In addition to being a chroot and using cgroups, nspawn launches processes by default in a process/mount namespace.  You can also choose to put it in a network namespace (if it doesn't need network access you could isolate it from the network trivially).  With the mount namespace you don't have to worry about any kind of cleanup if anything crashes, and of course with a process namespace there is more isolation (catalyst could still see the processes inside the container, but not the reverse).  

The magic invocation is typically something like this:

systemd-nspawn -D path/to/chroot --bind /usr/portage --bind /foo/distfiles:/var/cache/distfiles/ /bin/bash

That will spawn /bin/bash in a container that behaves like a chroot in path/to/chroot, and will set up two bind mounts from the host into the chroot.  I don't know if you really need bind mounts, and you can just omit that or add as many as you need.

The man page is actually pretty good, and if you google for an nspawn guide you'll probably find my blog pretty high in the pagerank.  :)