Created
July 15, 2023 20:43
-
-
Save oko/740eb1eb683fb80622bd4942d1ffc5a9 to your computer and use it in GitHub Desktop.
Scripts for creating ZFS pool w/ mirror vdevs on QNAP TS-673A
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import argparse | |
import itertools | |
import os | |
import subprocess | |
import sys | |
parser = argparse.ArgumentParser(description="set up zfs pool") | |
parser.add_argument("--mirror-size", type=int, default="2") | |
parser.add_argument("--disk-name-filter", type=str, default="*-ata-*.0") | |
parser.add_argument("--pool-name", type=str, default="tank") | |
def run(mirror_size, disk_name_filter, pool_name): | |
paths = {path: os.path.realpath(path) for path in subprocess.check_output(["find", "/dev/disk/by-path/", "-name", disk_name_filter, "-print0"]).decode('utf-8').split('\0') if path.strip()} | |
assert len(set(paths.keys())) == len(set(paths.values())) | |
for path, rpath in paths.items(): | |
assert os.path.exists(path) and os.path.exists(rpath) | |
print(f"using path {path} which is a link to {rpath}") | |
assert len(paths) % mirror_size == 0 | |
num_mirrors = int(len(paths) / mirror_size) | |
print(f"using mirror size {mirror_size}") | |
print(f"creating {num_mirrors} mirrors") | |
chunk_paths = list(sorted(paths.keys())) | |
chunks = [chunk_paths[start:start + mirror_size] for start in range(0, len(chunk_paths), mirror_size)] | |
command = ["zpool", "create", "-f", "-o", "ashift=12", pool_name] | |
for chunk in chunks: | |
command += ["mirror"] + chunk | |
print(' '.join(command)) | |
print("confirm with ENTER, ctrl-c to quit") | |
input() | |
subprocess.check_call(command) | |
if __name__ == "__main__": | |
args = parser.parse_args() | |
run(args.mirror_size, args.disk_name_filter, args.pool_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euxo pipefail | |
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | |
pool="tank" | |
"$SCRIPT_DIR/mkpool.py" --pool-name "$pool" | |
zpool add "$pool" log /dev/nvme0n1p4 | |
zpool add "$pool" cache /dev/nvme0n1p5 | |
zfs create "$pool"/media | |
zfs create "$pool"/mirror | |
zfs set acltype=posix xattr=sa "$pool"/media | |
zfs set acltype=posix xattr=sa "$pool"/mirror |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment