How do you mount ZFS drives when dual booting? (Solved. ish.)

Questions about other topics - please check if your question fits better in another category before posting here
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
User avatar
Tater
Level 3
Level 3
Posts: 109
Joined: Sun Sep 16, 2018 9:28 am
Location: PEBCAK

How do you mount ZFS drives when dual booting? (Solved. ish.)

Post by Tater »

Hello,

I have set up a mirrored pair of 4tb drives with ZFS to store data. I run LM 20 Cinnamon and dual boot POP_OS which my daughter uses. ZFS works fine for one or the other but requires commands to import the pool and mount to data sets if you boot into the other OS.

I'm trying to figure out how to make the process of unmounting/exporting and importing/mounting automatic. I have scripts to do these things but they required sudo. I assume that means they would would need to be run in the root part of the boot/shutdown processes to be automatic.

My questions:

1) Am I missing something? I would have thought this use case would be addressed in ZFS but I can't find it explained anywhere. Is it so blindingly obvious that nobody ever had to ask the question? (This possibility seems likely to me.)

2) If my assumptions are correct about having to add the commands (or my scripts) to the startup/shutdown routines, where do I insert the zpool import and zfs mount / zfs unmount and zpool export commands so they are run with proper privileges?

Thank you for any thoughts or advice.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Current victims:
Mint 21 Cinnamon on an MSI B450-a Pro Max AMD Ryzen 5 / 3.6 Ghz 6 Core (12 Thread) w/ 16 GB Ram

Mint 21 XFCE on a Dell Latitude D830 Intel Core 2 Duo T7250 / 2 GHz w/ 4 GB Ram

OS Reinstall Counter is set at 8
User avatar
AndyMH
Level 21
Level 21
Posts: 13759
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: How do you mount ZFS drives when dual booting?

Post by AndyMH »

Can't comment on most of your question, but
I have scripts to do these things but they required sudo
You can define a policy kit for your scripts. An example here:
viewtopic.php?f=47&t=317804&p=1800030&h ... d#p1800030
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
User avatar
Tater
Level 3
Level 3
Posts: 109
Joined: Sun Sep 16, 2018 9:28 am
Location: PEBCAK

Re: How do you mount ZFS drives when dual booting?

Post by Tater »

Thank you for that information, Andy. I have not had a reason, so far, to dive into policy kit.

My scripts are simply zpool and zfs commands that require sudo. I should think I would be able to drop them into a startup file under root somewhere without need for a script or changing permissions.

All my searches find are tutorials for installation on zfs, which is a whole different kettle of fish.

I'm trying not to roll my counter down below to the next number.
Current victims:
Mint 21 Cinnamon on an MSI B450-a Pro Max AMD Ryzen 5 / 3.6 Ghz 6 Core (12 Thread) w/ 16 GB Ram

Mint 21 XFCE on a Dell Latitude D830 Intel Core 2 Duo T7250 / 2 GHz w/ 4 GB Ram

OS Reinstall Counter is set at 8
User avatar
AndyMH
Level 21
Level 21
Posts: 13759
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: How do you mount ZFS drives when dual booting?

Post by AndyMH »

Define a polkit for your script that gives it admin privileges and run it with pkexec myscript. Polkits are the systemd replacement for sudo. It is not that difficult.

If you want to stick with sudo then you will have to modify your sudoers file.
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
User avatar
Tater
Level 3
Level 3
Posts: 109
Joined: Sun Sep 16, 2018 9:28 am
Location: PEBCAK

Re: How do you mount ZFS drives when dual booting?

Post by Tater »

Thanks again, Andy. I will start down the polkit rabbit hole and see what's for tea.
Current victims:
Mint 21 Cinnamon on an MSI B450-a Pro Max AMD Ryzen 5 / 3.6 Ghz 6 Core (12 Thread) w/ 16 GB Ram

Mint 21 XFCE on a Dell Latitude D830 Intel Core 2 Duo T7250 / 2 GHz w/ 4 GB Ram

OS Reinstall Counter is set at 8
User avatar
AndyMH
Level 21
Level 21
Posts: 13759
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: How do you mount ZFS drives when dual booting?

Post by AndyMH »

It's not that difficult, once you grasp the basic principles.

Create a text file in /usr/share/polkit-1/actions/, e.g. org.you.myscript.policy. You will need to be root to do this and I use xed (default cinnamon text editor).
Copy/paste the following into it:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
 "http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">
<policyconfig>

    <vendor>My zfs Project</vendor>
    <vendor_url>http://myzfsproject.org</vendor_url>
    <icon_name>zfsproject</icon_name>
    <action id="org.you.myscript">
 
        <description gettext-domain="myscript">Run myscript as root</description>
        <message gettext-domain="myscript">Authentication is required to run myscript as root</message>
        <defaults>
            <allow_any>yes</allow_any>                                                             
            <allow_inactive>yes</allow_inactive>                                                   
            <allow_active>yes</allow_active>                                                       
        </defaults>
        <annotate key="org.freedesktop.policykit.exec.path">/usr/bin/myscript</annotate>
        <annotate key="org.freedesktop.policykit.exec.allow_gui">false</annotate>
    </action>
</policyconfig>
Most of the entries are descriptive, you can change them to what makes sense to you, the important ones are:

Code: Select all

    <action id="org.you.myscript">
still descriptive, suggest you use your username, e.g. fred, and the script name

And

Code: Select all

            <allow_any>yes</allow_any>                                                            
            <allow_inactive>yes</allow_inactive>                                                  
            <allow_active>yes</allow_active>                                                       
Normally instead of yes it would say auth_admin which would mean ask for a password, yes means run without asking.

Code: Select all

        <annotate key="org.freedesktop.policykit.exec.path">/usr/bin/myscript</annotate>
        <annotate key="org.freedesktop.policykit.exec.allow_gui">false</annotate>
You must specify the full pathname to your script and the script must be executable. Don't think it makes much difference if you say true or false to allow gui, but I'm assuming a script so no gui.

Once done, test with pkexec myscript - runs without a pwd = success, prompt for a pwd = you did something wrong. I did find when developing foxclone* (which is why I had to learn about polkits) that in spite of running foxclone as root, some commands it ran, specifically mount, did not behave. I ended up defining a polkit for every terminal command that foxclone uses (all in one file).

I found this was a useful article:
https://wiki.archlinux.org/title/Polkit ... %20policy.
and there is lots of other stuff on the web. There are also some terminal commands like pkaction that can give you more info, man pkaction for details.

I did try modifying sudoers initially, but found polkits better.

Any questions, ask, but I'm only a couple of steps ahead of you in understanding :)

* linux image backup utility.
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
User avatar
Tater
Level 3
Level 3
Posts: 109
Joined: Sun Sep 16, 2018 9:28 am
Location: PEBCAK

Re: How do you mount ZFS drives when dual booting?

Post by Tater »

Andy,

That is very helpful. I will start messing around with it.

I am very much a fan of foxclone, I have used it a few times and it sits on my Ventoy usb drive in case of need. Thank you for making it.
Current victims:
Mint 21 Cinnamon on an MSI B450-a Pro Max AMD Ryzen 5 / 3.6 Ghz 6 Core (12 Thread) w/ 16 GB Ram

Mint 21 XFCE on a Dell Latitude D830 Intel Core 2 Duo T7250 / 2 GHz w/ 4 GB Ram

OS Reinstall Counter is set at 8
User avatar
AndyMH
Level 21
Level 21
Posts: 13759
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: How do you mount ZFS drives when dual booting?

Post by AndyMH »

Good luck, if it helps, as a further example, I can send you the foxclone polkit - it has multiple entries in it and is a 38kb file.
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
User avatar
Tater
Level 3
Level 3
Posts: 109
Joined: Sun Sep 16, 2018 9:28 am
Location: PEBCAK

Re: How do you mount ZFS drives when dual booting?

Post by Tater »

To follow up on this thread, I did "solve" the mounting issue.

The issue was that the system showed the mount point for the pool as being occupied upon boot. The error was "mount point not empty". I am sure there is a proper and elegant way to address this, but what I found was that there is an overlay setting which will ignore the the "mount point not empty" result and mount the ZFS pool anyway.

My ZFS pool is named pool1 in this example.

Check whether overlay is enabled:

Code: Select all

zfs get overlay pool1
NAME     PROPERTY  VALUE	SOURCE
pool1  overlay	off		default
turn on the overlay:

Code: Select all

zfs set overlay=on pool1
Check:

Code: Select all

zfs get overlay pool1
NAME      PROPERTY  VALUE    SOURCE
pool1  overlay   on       local
Reboot and the pool should mount and show your datasets. I assume there might be some horrible possible side effect of doing this in this way, but I haven't had any issues so far.

Hopefully this will help someone in the future.
Last edited by Tater on Sat Sep 04, 2021 6:15 pm, edited 1 time in total.
Current victims:
Mint 21 Cinnamon on an MSI B450-a Pro Max AMD Ryzen 5 / 3.6 Ghz 6 Core (12 Thread) w/ 16 GB Ram

Mint 21 XFCE on a Dell Latitude D830 Intel Core 2 Duo T7250 / 2 GHz w/ 4 GB Ram

OS Reinstall Counter is set at 8
User avatar
Larry78723
Level 14
Level 14
Posts: 5476
Joined: Wed Jan 09, 2019 7:01 pm
Location: Jasper County, SC, USA

Re: How do you mount ZFS drives when dual booting?

Post by Larry78723 »

Please open your original post, click on the pencil, and add (Solved) to the Subject. It may help someone in the future.
Image
If you have found the solution to your initial post, please open your original post, click on the pencil, and add (Solved) to the Subject, it helps other users looking for help, and keeps the forum clean.
User avatar
Tater
Level 3
Level 3
Posts: 109
Joined: Sun Sep 16, 2018 9:28 am
Location: PEBCAK

Re: How do you mount ZFS drives when dual booting?

Post by Tater »

Larry78723 wrote: Sat Sep 04, 2021 11:25 am Please open your original post, click on the pencil, and add (Solved) to the Subject. It may help someone in the future.
I'm not absolutely sure it's the best answer, but you are right.
Current victims:
Mint 21 Cinnamon on an MSI B450-a Pro Max AMD Ryzen 5 / 3.6 Ghz 6 Core (12 Thread) w/ 16 GB Ram

Mint 21 XFCE on a Dell Latitude D830 Intel Core 2 Duo T7250 / 2 GHz w/ 4 GB Ram

OS Reinstall Counter is set at 8
Locked

Return to “Other topics”