Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cgcreate fails. Cgroup not mounted. #87

Open
DrOptix opened this issue Jan 27, 2024 · 4 comments
Open

cgcreate fails. Cgroup not mounted. #87

DrOptix opened this issue Jan 27, 2024 · 4 comments

Comments

@DrOptix
Copy link

DrOptix commented Jan 27, 2024

I created this script to automate the cgroups creation:

#!/bin/bash

# Create a new cgroup
cgcreate -g cpu,memory,blkio,devices,freezer:/sandbox

# Add the jail to the cgroup
# TODO: Find a way to get the jail PID automatically
cgclassify -g cpu,memory,blkio,devices,freezer:sandbox $1

# List tasks associated to the sandbox cgroup, we should
# see the above PID
cat /sys/fs/cgroup/cpu/sandbox/tasks

# Limit usage at 5% for a multi core system
cgset -r cpu.cfs_period_us=100000 \
    -r cpu.cfs_quota_us=$[ 5000 * $(getconf _NPROCESSORS_ONLN) ] \
    sandbox

# Set a limit of 80M
cgset -r memory.limit_in_bytes=80M sandbox

It fails with:

root@30dc1f2265b2:/work/chroot# ./setup_cgroups.sh
cgcreate: libcgroup initialization failed: Cgroup is not mounted
cgclassify: libcgroup initialization failed: Cgroup is not mounted
cat: /sys/fs/cgroup/cpu/sandbox/tasks: No such file or directory
cgset: libcgroup initialization failed: Cgroup is not mounted
cgset: libcgroup initialization failed: Cgroup is not mounted

I don't get why it's going mad. I'm using also an Ubuntu Bionic base image for my chroot.

@codemaestro
Copy link

I was going to suggest that based on the cgroups lesson page, the course was last reviewed 5 years ago. But that shouldn't be a problem if we're all running within an ubuntu:bionic container. I'm skipping these manual lessons and moving ahead to the pre-configured stuff.

@DrOptix
Copy link
Author

DrOptix commented Mar 21, 2024

It's a bit of both. From my research it seems to be something related to cgroups vs cgroups v2. I did not have time to fully wrap my head around it so I dropped this research.

Also you have to keep in mind that containers are not VMs, they use the underling host kernel. Because of this if the host kernel does not provide something or has a regression introduced, your container won't work.

I have a case like this at work where I have to stay on Kernel 6.6.x because after that a regression was introduced and because of that I could not launch Docker images of Microsoft SQL Server, mcr.microsoft.com/mssql/server:2019-latest to be exact. Periodically I boot a newer kernel to see if they fixed, but no luck so far.

I'll keep this issue open. If @btholt decided to close it I'm fine with closing it.

@btholt
Copy link
Owner

btholt commented Apr 9, 2024

This is indeed broken. I tried to fix it for v1 of this course but it was so different that I'm actually heading back to re-record it in May.

@btholt
Copy link
Owner

btholt commented Apr 14, 2024

I just finished rewriting the section for v2 if you want to preview the next version of the course

https://containers-v2.holt.courses/lessons/crafting-containers-by-hand/cgroups

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants