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

init: Use pivot_root, not chroot #19

Closed
cgwalters opened this issue Nov 11, 2023 · 5 comments
Closed

init: Use pivot_root, not chroot #19

cgwalters opened this issue Nov 11, 2023 · 5 comments

Comments

@cgwalters
Copy link

See containers/bootc#203

TL;DR using chroot instead of pivot_root breaks things that want to enter the root mountns from a different mount namespace.

@rwmjones
Copy link
Member

pivot_root can't be used, see:

/* Note that pivot_root won't work. See the note in Linux
and https://www.kernel.org/doc/html/v5.10/filesystems/ramfs-rootfs-initramfs.html (search for pivot_root). I don't know if this has changed, but Linux docs suggest not.

@cgwalters
Copy link
Author

Thanks, sorry for not reading the comment above. I'm fine to close this as WONTFIX.

BTW, I think now that Linux supports root-on-virtiofs we could basically obsolete the supermin disk image building and this code I believe?

@cgwalters cgwalters closed this as not planned Won't fix, can't repro, duplicate, stale Nov 13, 2023
@rwmjones
Copy link
Member

rwmjones commented Nov 13, 2023

virtiofs is quite a bit more heavyweight than some files zipped up into a cpio. It involves running a daemon at least.

BTW what actually goes wrong because we don't use pivot_root? I don't think I've encountered any problem with it before. Edit: OK I read the other bug now. This seems strange though, you'd like the new mount namespace would start from the existing root.

@cgwalters
Copy link
Author

  • chroot changes just the process view of the filesystem
  • pivot_root changes the mount namespace itself

The difference becomes visible when a process in a different mount namespace wants to enter the original mountns.

@dustymabe
Copy link

Note also the use of chroot means that user namespaces can't be used:

bash-5.2# unshare -U
unshare: unshare failed: Operation not permitted

This is by design (thanks @giuseppe for the link): https://github.com/torvalds/linux/blob/41bccc98fb7931d63d03f326a746ac4d429c1dd3/kernel/user_namespace.c#L98-L107

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