Mount ZFS dataset with legacy mountpoint to LXC container

frank0366

New Member
Apr 4, 2023
4
0
1
Hi folks,
I need to mount a ZFS dataset with mountpoint property set to 'legacy' (which means that this dataset leave unmounted by default) to LXC container. One of the reasons is to keep files on this filesystem visible only inside container, not on the host - so as we know, ProxMox have only three possible "categories" of mount points: ProxMox storage provider supplied, block device and bind mount. I've prepared a little patch for pve-container package which adds a fourth "category" named "zfs" - so with this patch it's possible to add such ZFS dataset into container config in a form "mpN: <ZFS pool name>/<dataset path>,<mount path>". Can somebody from devs here advise me how can I supply or suggest this patch to include it in future versions of ProxMox?
 
@frank0366 can you describe how to add the zfs dataset as a mount point in the mean time? would be greatly appreciated!
Currently there is no builtin capability to add zfs dataset as mount point to LXC container in ProxMox, that's why I've asked about standard procedure to propose a patch. If you are need such functionality you can use a patch I've created for my own - after applying it you will be able to add ZFS as a mount point in tank/volume01 format. Don't forget to set mountpoint property for this dataset to 'legacy':

Code:
--- a/LXC.pm
+++ b/LXC.pm
@@ -1839,6 +1839,10 @@
        my ($devpath) = (Cwd::realpath($volid) =~ /^(.*)$/s); # realpath() taints
        PVE::Tools::run_command(['mount', @extra_opts, $volid, $mount_path]) if $mount_path;
        return wantarray ? ($volid, 0, $devpath) : $volid;
+    } elsif ($type eq 'zfs') {
+       push @extra_opts, '-o', 'ro' if $readonly;
+       PVE::Tools::run_command(['mount.zfs', @extra_opts, $volid, $mount_path]) if $mount_path;
+       return wantarray ? ($volid, 0, undef) : $volid
     } elsif ($type eq 'bind') {
        die "directory '$volid' does not exist\n" if ! -d $volid;
        bindmount($volid, $parentfd, $last_dir//$rootdir, $mount_path, $readonly, @extra_opts) if $mount_path;
--- a/LXC/Config.pm
+++ b/LXC/Config.pm
@@ -1557,7 +1557,8 @@
        return 'device' if $vol =~ m!^/dev/!;
        return 'bind';
     }
-    return 'volume';
+    return 'volume' if $vol =~ m!:.*(vm|subvol)-[0-9]*-disk-[0-9]*!;
+    return 'zfs';
 }

 my $__is_volume_in_use = sub {

To apply it place it to your Proxmox node and apply it using standard patch command in /usr/share/perl5/PVE dir (the commans below assume that patch is in /root dir1):

cd /usr/share/perl5/PVE && patch -p1 < /root/LXC.patch

As I've written above I've created it for my own so use it only on your risk.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!