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

zram-init prevents option X-mount.mkdir from being used #35

Closed
fabianoengler opened this issue Mar 17, 2021 · 0 comments
Closed

zram-init prevents option X-mount.mkdir from being used #35

fabianoengler opened this issue Mar 17, 2021 · 0 comments

Comments

@fabianoengler
Copy link

X-mount.mkdir is an option for mount where mount creates the target directory if it doesn't already exists (see man mount).

If one passes this option to zram-init it won't even call mount to give it a change to create the target directory, it will fail first:

root@localhost:~ # zram-init -t ext2 -o x-mount.mkdir=775 -d 3 512 /var/tmp/portage
zram-init: 
${dir:-(empty)} is not a directory

If one calls zramctl and mount directly, it works as expected:

root@localhost:~ # zramctl -f -s 512M
/dev/zram3

root@localhost:~ # mkfs.ext2 /dev/zram3 -q

root@localhost:~ # mount /dev/zram3 /var/tmp/portage
mount: /var/tmp/portage: mount point does not exist.

root@localhost:~ # mount /dev/zram3 /var/tmp/portage -o x-mount.mkdir=775

root@localhost:~ # ls -ld /var/tmp/portage
drwxr-xr-x 3 root root 4096 Mar 17 19:41 /var/tmp/portage

Q: What's is the use case for this? Why not simply do an mkdir before running zram-init?

A: On my setup, both /var/tmp and /var/tmp/portage are mounted by zram-init, with different options each. Among the differences there is noexec for /var/tmp (for security reasons) but exec for /var/tmp/portage (required).

Since both mount points are mounted by zram-init triggered by the distribution init scripts (openrc), /var/tmp will necessarily be empty after it's mounted and /var/tmp/portage is then mounted immediately after, leaving no opportunity for me to insert a mkdir command between the two mount operations.

For reference, my actual setup from /etc/conf.d/zram-init:

type2=/var/tmp
flag2=ext4
size2=16384
mlim2=
back2=
opts2="noatime,nosuid,nodev,noexec"
mode2=1777
owgr2=
notr2=
maxs2=1
algo2=zstd
labl2=var_tmp_dir
uuid2=
args2=

type3=/var/tmp/portage
flag3=ext4
size3=16384
mlim3=
back3=
opts3="noatime,nosuid,nodev,x-mount.mkdir=775"
mode3=
owgr3=portage:portage
notr3=
maxs3=1
algo3=zstd
labl3=tmp_portage_dir
uuid3=
args3=

Solution

I did simple check for X-mount.mkdir where zram-init checks if the directory exists, if it's there it won't trigger the error. I'm not sure if it's the best or even appropriate solution but it was what I came up with and it worked for me:

root@localhost:~ # ls -ld /var/tmp/portage
ls: cannot access '/var/tmp/portage': No such file or directory

root@localhost:~ # sh zram-init.sh -t ext2 -o noatime,nosuid,nodev,x-mount.mkdir=775 -c portage:portage -d 3 -D 4 -s 1 -a zstd -L tmp_portage_dir -- 16384 /var/tmp/portage
mke2fs 1.45.5 (07-Jan-2020)

root@localhost:~ # # ls -ld /var/tmp/portage
drwxr-xr-x 3 portage portage 4096 Mar 17 19:47 /var/tmp/portage

I'll be opening a PR next with my patch for discussion.

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

Successfully merging a pull request may close this issue.

1 participant