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

Unshare fails on nested mounts #19

Closed
ezrizhu opened this issue Jun 20, 2023 · 13 comments · Fixed by #67
Closed

Unshare fails on nested mounts #19

ezrizhu opened this issue Jun 20, 2023 · 13 comments · Fixed by #67
Assignees
Labels
bug Something isn't working
Milestone

Comments

@ezrizhu
Copy link
Collaborator

ezrizhu commented Jun 20, 2023

On a docker container, --privileged is required for unshare to work.
When running try, mount fails in the overlayfs.

❯ ./try echo hi
mount: /tmp/tmp.nFUDbAZ10u/temproot/bin: wrong fs type, bad option, bad superblock on overlay, missing codepage or helper program, or other error.
mount: /tmp/tmp.nFUDbAZ10u/temproot/boot: wrong fs type, bad option, bad superblock on overlay, missing codepage or helper program, or other error.
mount: /tmp/tmp.nFUDbAZ10u/temproot/etc: wrong fs type, bad option, bad superblock on overlay, missing codepage or helper program, or other error.
<snip>
unshare: failed to execute /bin/bash: No such file or directory
@ezrizhu ezrizhu changed the title try does not work in docker or debian mount fails in docker Jun 21, 2023
@ezrizhu
Copy link
Collaborator Author

ezrizhu commented Jun 21, 2023

The solution in https://stackoverflow.com/questions/67198603/overlayfs-inside-docker-container Fixes the issue.

> mkdir /tmp/overlay
> mkdir /tmp/{low,merged}
> mount -t tmpfs tmpfs /tmp/overlay
> mkdir /tmp/overlay/{up,work}
> mount -t overlay overlay -o lowerdir=/tmp/low/,upperdir=/tmp/overlay/up/,workdir=/tmp/overlay/work/ /tmp/merged/ 

I am not too sure why we need to place it in tmpfs for it to work in docker. cc @mgree

@mgree
Copy link
Contributor

mgree commented Jun 21, 2023

@ezrizhu
Copy link
Collaborator Author

ezrizhu commented Jun 21, 2023

That makes sense, should we work on support for running try in docker/overlayfs?

@mgree
Copy link
Contributor

mgree commented Jun 21, 2023

I don't think it's a huge priority---if you're running in those environments, you need try much less.

@mgree mgree added bug Something isn't working wontfix This will not be worked on labels Jun 24, 2023
@mgree mgree changed the title mount fails in docker Fails in docker: overlayfs cannot be nested Jun 24, 2023
@ezrizhu ezrizhu mentioned this issue Jun 24, 2023
@ezrizhu
Copy link
Collaborator Author

ezrizhu commented Jun 24, 2023

In a setup where we have a --bind(and possibly others) mount setup in a like /home, we get the following error when trying to mount it in overlayfs.

mount: /tmp/tmp.nFUDbAZ10u/temproot/home: wrong fs type, bad option, bad superblock on overlay, missing codepage or helper program, or other error.

And in dmesg, we see the following

[308798.929868] overlayfs: failed to set xattr on upper
[308798.929873] overlayfs: try mounting with 'userxattr' option
[308798.929883] overlayfs: failed to clone lowerpath

https://elixir.bootlin.com/linux/latest/source/fs/overlayfs/super.c#L1665

@ezrizhu ezrizhu changed the title Fails in docker: overlayfs cannot be nested Unshare fails on nested mounts Jun 24, 2023
@ezrizhu ezrizhu removed the wontfix This will not be worked on label Jun 24, 2023
@ezrizhu ezrizhu self-assigned this Jun 24, 2023
@ezrizhu ezrizhu added the help wanted Extra attention is needed label Jun 24, 2023
@ezrizhu
Copy link
Collaborator Author

ezrizhu commented Jun 25, 2023

Reproducible on the following.

eric@try-test-lvm:~/try$ lsblk
NAME                MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda                   8:0    0   50G  0 disk
└─sda1                8:1    0   50G  0 part
  ├─vg0-vg0--root   254:0    0 27.9G  0 lvm  /
  ├─vg0-lv--home    254:1    0  9.3G  0 lvm  /home
  └─vg0-lv--homemnt 254:2    0 12.7G  0 lvm  /home/eric/mnt
sr0                  11:0    1  957M  0 rom

@ezrizhu
Copy link
Collaborator Author

ezrizhu commented Jun 25, 2023

Mounting the directories via mergerfs to a tempdir, then mounting overlayfs with the tempdir as it's lowerdir seems to be able to fix this.
This method also fixes #56.

A fix has been pushed to branch nested-mount.

Should we work to support nested mounts via mergerfs @mgree

@mgree
Copy link
Contributor

mgree commented Jun 25, 2023

Is there a reason a simpler, comes-with-default-Linux approach like unionfs wouldn't work? I'm wary of adding too many dependencies.

@mgree
Copy link
Contributor

mgree commented Jun 25, 2023

Also: we will very much need tests for this.

@ezrizhu
Copy link
Collaborator Author

ezrizhu commented Jun 25, 2023

Is there a reason a simpler, comes-with-default-Linux approach like unionfs wouldn't work? I'm wary of adding too many dependencies.

Unionfs works, however on my debian setup it requires the installation of unionfs-fuse package.

cat /proc/filesystems | grep union Yields nothing on my Ubuntu and Debian machines

I agree we shouldn't add too many dependencies, perhaps we can make it a flag to enable/disable or use it only if merger/unionfs is installed.

@mgree
Copy link
Contributor

mgree commented Jun 25, 2023

Okay, fair enough. Let's see if we can use the same approach for both, and then we can detect (or have the user select) a union fs to use.

@ezrizhu
Copy link
Collaborator Author

ezrizhu commented Jun 25, 2023

Great, I'll see to implement this with #45

@ezrizhu ezrizhu linked a pull request Jun 26, 2023 that will close this issue
8 tasks
@ezrizhu ezrizhu removed the help wanted Extra attention is needed label Jun 26, 2023
@angelhof
Copy link
Member

Also should be closed using #67

@angelhof angelhof added this to the try 0.2 milestone Jun 28, 2023
ezrizhu added a commit that referenced this issue Jun 29, 2023
* Allow for nested mount by using mergerfs

* Remove debug bash and echo

* mount /run with merger aswell

* refactor and use overlayfs via mergerfs if regular overlayfs fails

* Only mount /dev/{tty null zero full random urandom}

* improve docs, refactor from top_dir to mountpoint

* Fix mergerfs failing not showing mount log path

* Add support for unionfs, allow user to specify unionfs helper path

* Write mountpoint on unionhelper not found message

* exit if findmnt not installed

* nested mount docs

* add newlines to readme

* grammar fix

* Add -U option description to manpages

* Add shell completion for -U option

* Change -U flag autocompletion to only suggest executables

* Install mergerfs in ci

* Try reading from /run directory before testing

* Refactor and unmount devices for tests to pass

* Add a device test

* Some comments and redirect a test to /dev/null

Fixed #56 #45 #38 #20 #19 

---------

Co-authored-by: Eric Zhu <eric@debian-BULLSEYE-live-builder-AMD64>
Co-authored-by: gliargovas <gliargovas@aueb.gr>
Co-authored-by: Konstantinos Kallas <konstantinos.kallas@hotmail.com>
Co-authored-by: Michael Greenberg <michael@greenberg.science>
@ezrizhu ezrizhu mentioned this issue Nov 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants