🧹 move ZFS datasets creation into gucc

use predefined ZFS dataset scheme
This commit is contained in:
Vladislav Nepogodin 2024-09-25 02:32:27 +04:00
parent e98c7fb7b7
commit c76930d0d9
No known key found for this signature in database
GPG Key ID: B62C3D10C54D5DA9
3 changed files with 35 additions and 9 deletions

View File

@ -3,14 +3,23 @@
#include <string> // for string #include <string> // for string
#include <string_view> // for string_view #include <string_view> // for string_view
#include <vector> // for vector
namespace gucc::fs { namespace gucc::fs {
struct ZfsDataset final {
std::string zpath;
std::string mountpoint;
};
// Creates a zfs volume // Creates a zfs volume
void zfs_create_zvol(std::string_view zsize, std::string_view zpath) noexcept; void zfs_create_zvol(std::string_view zsize, std::string_view zpath) noexcept;
// Creates a zfs filesystem, the first parameter is the ZFS path and the second is the mount path // Creates a zfs filesystem, the first parameter is the ZFS path and the second is the mount path
void zfs_create_dataset(std::string_view zpath, std::string_view zmount) noexcept; auto zfs_create_dataset(std::string_view zpath, std::string_view zmount) noexcept -> bool;
// Creates a zfs datasets from predefined scheme
auto zfs_create_datasets(const std::vector<ZfsDataset>& zdatasets) noexcept -> bool;
void zfs_destroy_dataset(std::string_view zdataset) noexcept; void zfs_destroy_dataset(std::string_view zdataset) noexcept;

View File

@ -21,14 +21,26 @@ void zfs_create_zvol(std::string_view zsize, std::string_view zpath) noexcept {
} }
// Creates a zfs filesystem, the first parameter is the ZFS path and the second is the mount path // Creates a zfs filesystem, the first parameter is the ZFS path and the second is the mount path
void zfs_create_dataset(std::string_view zpath, std::string_view zmount) noexcept { auto zfs_create_dataset(std::string_view zpath, std::string_view zmount) noexcept -> bool {
#ifdef NDEVENV #ifdef NDEVENV
utils::exec(fmt::format(FMT_COMPILE("zfs create -o mountpoint={} {} 2>>/tmp/cachyos-install.log"), zmount, zpath), true); return utils::exec_checked(fmt::format(FMT_COMPILE("zfs create -o mountpoint={} {} 2>>/tmp/cachyos-install.log"), zmount, zpath));
#else #else
spdlog::debug("zfs create -o mountpoint={} {}", zmount, zpath); spdlog::debug("zfs create -o mountpoint={} {}", zmount, zpath);
return true;
#endif #endif
} }
auto zfs_create_datasets(const std::vector<ZfsDataset>& zdatasets) noexcept -> bool {
// Create datasets
for (const auto& zdataset : zdatasets) {
if (!fs::zfs_create_dataset(zdataset.zpath, zdataset.mountpoint)) {
spdlog::error("Failed to create zfs dataset {} at mountpoint {}", zdataset.zpath, zdataset.mountpoint);
return false;
}
}
return true;
}
void zfs_destroy_dataset(std::string_view zdataset) noexcept { void zfs_destroy_dataset(std::string_view zdataset) noexcept {
#ifdef NDEVENV #ifdef NDEVENV
utils::exec(fmt::format(FMT_COMPILE("zfs destroy -r {} 2>>/tmp/cachyos-install.log"), zdataset), true); utils::exec(fmt::format(FMT_COMPILE("zfs destroy -r {} 2>>/tmp/cachyos-install.log"), zdataset), true);

View File

@ -212,12 +212,17 @@ bool zfs_auto_pres(const std::string_view& partition, const std::string_view& zf
} }
// next create the datasets including their parents // next create the datasets including their parents
gucc::fs::zfs_create_dataset(fmt::format(FMT_COMPILE("{}/ROOT"), zfs_zpool_name), "none"sv); const std::vector<gucc::fs::ZfsDataset> default_zfs_datasets{
gucc::fs::zfs_create_dataset(fmt::format(FMT_COMPILE("{}/ROOT/cos"), zfs_zpool_name), "none"sv); gucc::fs::ZfsDataset{.zpath = fmt::format(FMT_COMPILE("{}/ROOT"), zfs_zpool_name), .mountpoint = "none"s},
gucc::fs::zfs_create_dataset(fmt::format(FMT_COMPILE("{}/ROOT/cos/root"), zfs_zpool_name), "/"sv); gucc::fs::ZfsDataset{.zpath = fmt::format(FMT_COMPILE("{}/ROOT/cos"), zfs_zpool_name), .mountpoint = "none"s},
gucc::fs::zfs_create_dataset(fmt::format(FMT_COMPILE("{}/ROOT/cos/home"), zfs_zpool_name), "/home"sv); gucc::fs::ZfsDataset{.zpath = fmt::format(FMT_COMPILE("{}/ROOT/cos/root"), zfs_zpool_name), .mountpoint = "/"s},
gucc::fs::zfs_create_dataset(fmt::format(FMT_COMPILE("{}/ROOT/cos/varcache"), zfs_zpool_name), "/var/cache"sv); gucc::fs::ZfsDataset{.zpath = fmt::format(FMT_COMPILE("{}/ROOT/cos/home"), zfs_zpool_name), .mountpoint = "/home"s},
gucc::fs::zfs_create_dataset(fmt::format(FMT_COMPILE("{}/ROOT/cos/varlog"), zfs_zpool_name), "/var/log"sv); gucc::fs::ZfsDataset{.zpath = fmt::format(FMT_COMPILE("{}/ROOT/cos/varcache"), zfs_zpool_name), .mountpoint = "/var/cache"s},
gucc::fs::ZfsDataset{.zpath = fmt::format(FMT_COMPILE("{}/ROOT/cos/varlog"), zfs_zpool_name), .mountpoint = "/var/log"s},
};
if (!gucc::fs::zfs_create_datasets(default_zfs_datasets)) {
spdlog::error("Failed to create zfs datasets automatically");
}
#ifdef NDEVENV #ifdef NDEVENV
// set the rootfs // set the rootfs