Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 647248 - sys-fs/zfs-0.7.6: /etc/init.d/zfs-mount tries to mount /dev/zvol swap from /etc/fstab
Summary: sys-fs/zfs-0.7.6: /etc/init.d/zfs-mount tries to mount /dev/zvol swap from /e...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Richard Yao (RETIRED)
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-02-10 20:12 UTC by Morgan Wesström
Modified: 2019-05-23 21:52 UTC (History)
3 users (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 Morgan Wesström 2018-02-10 20:12:14 UTC
Having a zvol defined as swap in /etc/fstab results in the following console output at boot:

 * Mounting ZFS filesystem(s)  ...
 [ ok ]
fsck from util-linux 2.30.2
mount: none: mount point does not exist.

Contents of /etc/fstab:

/dev/zvol/zroot/swap	none	swap	sw	0 0

Looking at /etc/init.d/zfs-mount it seems it explicitly tries to mount anything from /etc/fstab beginning with /dev/zvol and will of course fail if there's no proper mountpoint defined. I don't know if this is intended behaviour or if I have configured something wrong. The swap gets activated though, presumably through /etc/init.d/swap? Removing the line from /etc/fstab makes the message go away but then I get no swap.
Comment 1 Jonathan Vasquez (RETIRED) gentoo-dev 2018-03-25 23:40:34 UTC
That's interesting. I don't use OpenRC (I'm using systemd w/ zfs) so I can't really help much on this, but I believe ryao uses OpenRC. It seems that basically zfs-mount and the swap are both trying to mount it?

I would say that maybe the intended design for this (when using swap on zfs) is to not use /etc/init.d/swap in your startup process and let the zfs-mount zfs script handle swap.
Comment 2 Georgy Yakovlev archtester gentoo-dev 2018-03-26 02:59:05 UTC
(In reply to Jonathan Vasquez from comment #1)
> That's interesting. I don't use OpenRC (I'm using systemd w/ zfs) so I can't
> really help much on this, but I believe ryao uses OpenRC. It seems that
> basically zfs-mount and the swap are both trying to mount it?
> 
> I would say that maybe the intended design for this (when using swap on zfs)
> is to not use /etc/init.d/swap in your startup process and let the zfs-mount
> zfs script handle swap.

I have an openrc zfs system. Using dedicated swap partitions, so I'll create a swap zvol and try to test it and see what's going on.


meanwhile, quickly looking at the zfs-mount initscript is seems it's looking for exactly 2 patterns:

read_fstab "^/dev/(zd|zvol)"

so anything that matches /dev/zd* or /dev/zvol/* in fstab will be attempted to be mounted by zfs-mount.


workaround is to define swap in fstab using different string:
by label e.g LABEL=zswap
by uuid e.g. UUID=1795d4c3-9fa1-439c-a956-af92088b45d6
by /dev/zroot/swap (it does not match zd|zvol and is only created for zvols, not datasets)

ls -la /dev/zvol/zroot/swap /dev/zd0 /dev/zroot/swap 
brw-rw---- 1 root disk 230, 0 Mar 25 19:39 /dev/zd0
lrwxrwxrwx 1 root root      6 Mar 25 19:38 /dev/zroot/swap -> ../zd0
lrwxrwxrwx 1 root root      9 Mar 25 19:38 /dev/zvol/zroot/swap -> ../../zd0


those links created by 

60-zvol.rules 
# Persistent links for zvol
#
# persistent disk links: /dev/zvol/dataset_name
# also creates compatibility symlink of /dev/dataset_name

KERNEL=="zd*" SUBSYSTEM=="block" ACTION=="add|change" PROGRAM="/lib/udev/zvol_id $tempnode" SYMLINK+="zvol/%c %c"


openrc activates swap simply running swapon -a, which in case swap is already activated will just silently ignore active ones and return 0.

I'll get back here after I test it.
Seems zfs-mount script should filter out swap and never try to mount one, but I need to confirm this.
There is not a single mention of swap in zfs initscripts, so I believe it leaves it to the system and does not handle this at all.
Comment 3 Georgy Yakovlev archtester gentoo-dev 2018-03-26 04:14:05 UTC
I can't edit bugs, here is upstream bugreport

https://github.com/zfsonlinux/zfs/issues/7346
Comment 4 Georgy Yakovlev archtester gentoo-dev 2018-03-26 04:40:33 UTC
and a PR
https://github.com/zfsonlinux/zfs/pull/7347
Comment 5 Morgan Wesström 2018-03-26 14:00:40 UTC
Thank you Georgy. When I first filed this bug I noticed that the init script itself has a link to the original script acting as a template for it.
https://github.com/zfsonlinux/pkg-zfs/commit/80a3ae582b59c0250d7912ba794dca9e669e605a

This original script looks very different from what ended up in Gentoo and it actually has logic to deal with swap on zvol so long as the zvol has the property org.freebsd:swap=on. The Gentoo ZFS wiki lacks info on how to handle swap on a ZFS system which is why I asked for clarification. I have no problems to adapt to any solution or even live with the message during boot but it seems to me as the original script intended you to set that property on the zvol and don't have any swap defined in /etc/fstab.
Comment 6 Georgy Yakovlev archtester gentoo-dev 2018-03-27 02:53:54 UTC
(In reply to Morgan Wesström from comment #5)
> Thank you Georgy. When I first filed this bug I noticed that the init script
> itself has a link to the original script acting as a template for it.
> https://github.com/zfsonlinux/pkg-zfs/commit/
> 80a3ae582b59c0250d7912ba794dca9e669e605a
> 
> This original script looks very different from what ended up in Gentoo and
> it actually has logic to deal with swap on zvol so long as the zvol has the
> property org.freebsd:swap=on. The Gentoo ZFS wiki lacks info on how to
> handle swap on a ZFS system which is why I asked for clarification. I have
> no problems to adapt to any solution or even live with the message during
> boot but it seems to me as the original script intended you to set that
> property on the zvol and don't have any swap defined in /etc/fstab.

that is from freeBSD/debian hybrid and dated 2011.. it's obsolete. you have the wrong repo.
this is the correct one 

https://github.com/zfsonlinux/zfs/blob/master/etc/init.d/zfs-mount.in

all the scripts have been updated recently, they used to be a bit different.

zfs is managed a bit differently in other systems, there are many zfs forks.

on linux it's activated using /etc/fstab.
on freeBSD it's activated using zvol/dataset properties.
on solaris it's /etc/vfstab

so just keep it in /etc/fstab and you'll be fine.
sometime this PR will get merged and the message will go away. or use /dev/zroot/swap as a path to it, it will be mounted without error messages.
Comment 7 Jonathan Vasquez (RETIRED) gentoo-dev 2018-03-27 03:07:34 UTC
Just to add, I also have /dev/zvol/rpool/swap in my /etc/fstab, but I think it's probably the systemd swap service that is activating it rather than the 'zfs-mount' systemd service. From a design perspective, I would say it's better to let the native systemd service or openrc scripts (/etc/init.d/swap) mount swap directly based on /etc/fstab than adding another responsibility to the openrc zfs-mount script.
Comment 8 Morgan Wesström 2018-03-27 10:19:03 UTC
(In reply to Georgy Yakovlev from comment #6)
> that is from freeBSD/debian hybrid and dated 2011.. it's obsolete. you have
> the wrong repo.
> this is the correct one 

Just to clarify, the URL I linked is the one currently present among the comments in /etc/init.d/zfs-mount itself from sys-fs/zfs-0.7.6. I haven't tested any more recent version so that URL might have been updated already. If not, it should probably be replaced by the URL you gave me. I can file another bug for that if needed.
Comment 9 Morgan Wesström 2018-03-27 10:24:03 UTC
(In reply to Jonathan Vasquez from comment #7)
> Just to add, I also have /dev/zvol/rpool/swap in my /etc/fstab, but I think
> it's probably the systemd swap service that is activating it rather than the
> 'zfs-mount' systemd service. From a design perspective, I would say it's
> better to let the native systemd service or openrc scripts
> (/etc/init.d/swap) mount swap directly based on /etc/fstab than adding
> another responsibility to the openrc zfs-mount script.

As far as I understand it, this is how it currently works. /etc/init.d/swap correctly finds the entry in /etc/fstab and enables it. The problem is that the zfs-mount script also finds that entry and tries to mount it as a regular zfs filesystem and fails because the mountpoint is "none". Georgy's proposed change is to have zfs-mount simply ignore such fstab entries.
Comment 10 Morgan Wesström 2018-03-27 10:44:50 UTC
Adding to this: As a user I have no real preference whether it's swap or zfs-mount that actually enables the swap but from a zfs design perspective, configurations are supposed to be stored within the filesystem itself, aren't they? This means that the property value should be preferred over an entry in fstab, which in turn may have repercussions on whether it's swap or zfs-mount that has to deal with it. If Gentoo chose to move configurations out of the filesystem it would deviate from the zfs design philosophy IMHO.
Comment 11 Jonathan Vasquez (RETIRED) gentoo-dev 2018-03-27 11:44:16 UTC
That is correct, but ZFS wasn't designed for Linux and it's philosophy is different than Linux's. Linux philosophy has things managed by /etc/fstab. For me, I let ZFS only manage mounting, but other things such as swap, etc I delegate it to Linux. I don't even use the boot property either, I just pass the root dataset directly into bliss-initramfs as well ;).
Comment 12 Morgan Wesström 2018-03-27 12:06:18 UTC
I feel like I'm potentially stepping into a hornet's nest here ;) From the perspective of Linux/GNU, *nix (including Solaris), everything has historically been configured in files. The zfs philosophy otoh is quite interesting from a Gentoo point of view with its philosophy of choices. Would it be a bad thing to give the user a choice of either listing the swap in fstab, and thus handled by /etc/init.d/swap, or adding the property to the zfs filesystem which then would be handled by zfs-mount?
Comment 13 Jonathan Vasquez (RETIRED) gentoo-dev 2018-03-27 13:54:11 UTC
It's definitely interesting :). Personally I feel that too much choice is a bad thing. This may be contrary to Gentoo's philosophy (or at least to some). I know some other Gentoo developers also agree that choice in general is good, but when there is "too much choice", it actually causes a negative user experience. I believe having multiple choices for how a swap should be activated creates a negative user experiences considering this is stuff that runs during start up. We should select one method and move forward with that. Ideally one that is consistent between both openrc and systemd. I'll let ryao decide how he wants to move forward with this.
Comment 14 Georgy Yakovlev archtester gentoo-dev 2018-03-30 05:13:27 UTC
I was thinking the same actually while working on the pull request.

It's fine for zfs-mount service to handle zfs datasets that have mountpoint=legacy set.
I'm not sure, but it seems gentoo's localmount will not handle such entries. I'll double-check.


but zvols are regular block devices and I'm not sure why zfs-mount tries to parse fstab using grep/regexp and handle it.
I'd leave it to battle-tested init-scripts that have been around for years.
Comment 15 Georgy Yakovlev archtester gentoo-dev 2018-03-30 05:20:15 UTC
as for systemd, now it uses rather simplistic approach (just runs zfs mount -a)
but there is some work in progress of using systemd's generators.

https://github.com/zfsonlinux/zfs/pull/7329


zvols alredy handeled the normal way on systemd, using generators.
Comment 16 Georgy Yakovlev archtester gentoo-dev 2018-03-31 00:24:48 UTC
FYI, upstream merged my PR, so swap will be taken care of.

I opened another issue however, related to above distussion:

https://github.com/zfsonlinux/zfs/issues/7374

0. zvols mounted regardless of `noauto` fstab option
1. `mountpoint=legacy` datasets are mounted regardless of `canmount=noauto` property
2. `mountpoint=legacy` datasets are mounted regardless of fstab `noauto`
3. `fsck` being run for zvols regardless of fstab settings.


So yeah, you guys were right. Duplicating other's tools work, especially in a distro-agnostic way is hard and will lead to bugs.
Comment 17 Morgan Wesström 2018-03-31 15:44:46 UTC
Thank you for your great efforts guys. Highly appreciated. :)
Comment 18 Georgy Yakovlev archtester gentoo-dev 2019-05-23 21:52:08 UTC
this is fixed in just released 0.8.0
closing.
thanks again for reporting it.