8

I have a problem with automounting separate pools, that have nested mountpoints. I am using ZfsOnLinux 0.6.2.

The siuation currently is as follows:

zpool1      ---> /var
zpool1/log  ---> /var/log
zpool1/mail ---> /var/mail

Now I need to add a separate zpool for db. To keep directory hierarchy consistent, I thought about this:

zpool2      ---> /var/db

Now, the problem is that when zpool2 is mounted first, zpool1 fails to mount (this is logical).

Is there a way I can force the mount order of pools to allow mounting of zpool2 inside zpool1, besides using the legacy mount option? Something like zpools dependency? Or should I avoid such nested mounts at all costs?

4
  • Good question. I'm not sure...
    – ewwhite
    Mar 31, 2014 at 23:38
  • 1
    Maybe set the mount point to 'legacy' and add it to /etc/fstab, which mounts in the order given? Is this Ubuntu? Apr 1, 2014 at 0:32
  • @MarkWagner, it's Gentoo. But I'd prefer not to use legacy mount options and benefit from zfs automounting... Apr 1, 2014 at 6:28
  • I fail at reading. Sorry. Apr 1, 2014 at 17:04

5 Answers 5

6

Instead of mounting zpool2 as /var/db, mount it as /zpool2 or /db or whatever makes sense for you.

Then make /var/db a symlink to /db.

5
  • Alternatively, do a bindmount instead of symlink; some software want some directories to be honest-to-goodness actual directories instead of symlinks.
    – pepoluan
    Apr 1, 2014 at 3:29
  • 3
    A bind mount nets you the same problem - namely that /var has to be mounted before the bind mount can be created.
    – MikeyB
    Apr 1, 2014 at 3:53
  • 1
    I was afraid this would be the only solution... I just thought about another workaround: creating datasets for all directories in /var, setting mountpoints for zpool1 and zpool2 to none and mounting only the datasets. Should this work? Of course the drawback is that I would need separate datasets for all directories in /var/... Apr 1, 2014 at 12:05
  • Why do you think symlinks are SO BAD? They're not. Stop obsessing over trying to get things perfect.
    – MikeyB
    Apr 1, 2014 at 12:21
  • Yeah, I always tried to make things perfectly polished, and symlinks seemed to increase entropy ;) I guess you are right, though... Apr 1, 2014 at 13:22
6

You can set the file system mountpoint properties to legacy and use /etc/fstab to define them.

That way, you'll be able to define the order in which they will be mounted.

Edit: I just noticed you already considered the legacy approach. It might be the only one though.

2

Within the same pool, the composition of mount paths determines the mount order. Within one pool, Zfs sorts the file systems to be mounted by their respective mount point paths, which guarantees the correct mount order.

When there are 2 or more pools involved, there is no similar facility to automatically impose the mount order between the pools.

In other words, Zfs has a built-in mechanism that makes sure that any mount-point composition will cause the fs-s to get mounted in the correct order, but it has no similar facility to make this guarantee when multiple pools are involved.

If pool2 has a file system that is set up to mount on a mount point that is made available by mounting an fs in pool1 first, it is on the admin to make sure that pool1 is indeed mounted first. E.g.: It has to be scripted. So the answer is "do not expect this to sort itself out".

1
  • hmm how can you tell that zfs does it right if all is the same pool? It's failing to mount /tmp correctly for me and I can't tell where to find logs about how exactly, because it just ends up creating a normal tmp directory instead
    – lucidbrot
    Feb 8, 2023 at 22:14
1

Maybe using Root on ZFS could help.

I use ZFS on FreeBSD with two pools and nested mountpoints. The first pool (ssd) is the pool where root filesystem is located as are most of the other file systems. The second pool (hdd) is used for file systems with large data mounted to specific locations.

I believe because of the root filesystem all the file sytems from the ssd pool are mounted first and the filesystems from the hdd pool are mounted second.

I have never had problems with this setup. However this is a production server and I am not restarting it too often.

-1

in ubuntu and debian you can edit the file /etc/default/zfs ....

List of pools that SHOULD be imported at boot by the initramfs

instead of trying to import all available pools. If this is set

then ZFS_POOL_EXCEPTIONS is ignored.

This is a semi-colon separated list.

#ZFS_POOL_IMPORT="rpool;bpool;cpool"

maybe you set ZFS_POOL_IMPORT="zpool1;zpool2" and try if it imports them in the order as they are listet.. if not, the just put zpool1 in there, and create a systemd file called zpool2-import.service

[Unit] Description=Zpool2 mount After=zfs-import.target Requires=zfs-mount.service

[Service] Type=oneshot ExecStart=/sbin/zpool import zpool2 -N Exec=/sbin/zfs mount -a (or zpool2/var/db)

[Install] WantedBy=zfs-import.target.wants

################# or edit zpool1 the mount points zfs set canmount=off zpool1/var zfs set mountpoint=none zpool1/var mkdir -p /var/db

so your other datasets in /var can all mount , eg. zpool1/var/cache will mount

on /var/cache , and if zpool2 gets imported first, doesn't matter if pool1 is mount or not, because the target ( /var/db )is still on the root filesystem.

edit also same way zpool2 zfs set canmount=off zpool2/var zfs set mountpoint=none zpool2/var

zfs set mountpoint=/var zpool2 zfs set mountpoint=/var/db zpool2/var/db zfs set overlay=on zpool2

then it should mount

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .