mirror of
https://github.com/CachyOS/New-Cli-Installer.git
synced 2025-01-23 05:52:23 +08:00
🧹 move ZFS datasets creation into gucc
use predefined ZFS dataset scheme
This commit is contained in:
parent
e98c7fb7b7
commit
c76930d0d9
@ -3,14 +3,23 @@
|
||||
|
||||
#include <string> // for string
|
||||
#include <string_view> // for string_view
|
||||
#include <vector> // for vector
|
||||
|
||||
namespace gucc::fs {
|
||||
|
||||
struct ZfsDataset final {
|
||||
std::string zpath;
|
||||
std::string mountpoint;
|
||||
};
|
||||
|
||||
// Creates a zfs volume
|
||||
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
|
||||
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;
|
||||
|
||||
|
@ -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
|
||||
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
|
||||
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
|
||||
spdlog::debug("zfs create -o mountpoint={} {}", zmount, zpath);
|
||||
return true;
|
||||
#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 {
|
||||
#ifdef NDEVENV
|
||||
utils::exec(fmt::format(FMT_COMPILE("zfs destroy -r {} 2>>/tmp/cachyos-install.log"), zdataset), true);
|
||||
|
17
src/disk.cpp
17
src/disk.cpp
@ -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
|
||||
gucc::fs::zfs_create_dataset(fmt::format(FMT_COMPILE("{}/ROOT"), zfs_zpool_name), "none"sv);
|
||||
gucc::fs::zfs_create_dataset(fmt::format(FMT_COMPILE("{}/ROOT/cos"), zfs_zpool_name), "none"sv);
|
||||
gucc::fs::zfs_create_dataset(fmt::format(FMT_COMPILE("{}/ROOT/cos/root"), zfs_zpool_name), "/"sv);
|
||||
gucc::fs::zfs_create_dataset(fmt::format(FMT_COMPILE("{}/ROOT/cos/home"), zfs_zpool_name), "/home"sv);
|
||||
gucc::fs::zfs_create_dataset(fmt::format(FMT_COMPILE("{}/ROOT/cos/varcache"), zfs_zpool_name), "/var/cache"sv);
|
||||
gucc::fs::zfs_create_dataset(fmt::format(FMT_COMPILE("{}/ROOT/cos/varlog"), zfs_zpool_name), "/var/log"sv);
|
||||
const std::vector<gucc::fs::ZfsDataset> default_zfs_datasets{
|
||||
gucc::fs::ZfsDataset{.zpath = fmt::format(FMT_COMPILE("{}/ROOT"), zfs_zpool_name), .mountpoint = "none"s},
|
||||
gucc::fs::ZfsDataset{.zpath = fmt::format(FMT_COMPILE("{}/ROOT/cos"), zfs_zpool_name), .mountpoint = "none"s},
|
||||
gucc::fs::ZfsDataset{.zpath = fmt::format(FMT_COMPILE("{}/ROOT/cos/root"), zfs_zpool_name), .mountpoint = "/"s},
|
||||
gucc::fs::ZfsDataset{.zpath = fmt::format(FMT_COMPILE("{}/ROOT/cos/home"), zfs_zpool_name), .mountpoint = "/home"s},
|
||||
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
|
||||
// set the rootfs
|
||||
|
Loading…
Reference in New Issue
Block a user