btrfs: Change default subvol upon creation

The default root subvol comes with its own limitations and it might be
better off changing the default subvol upon creation. This should also
let us create hidden subvols that may be used for storing snapshots,
without exposing them to the end-user.
This commit is contained in:
Mehran Kholdi 2021-06-26 02:15:59 +04:30
parent c11646e08c
commit 7c7e8eb4ce

View File

@ -1,5 +1,6 @@
import os
import subprocess
import tempfile
from pathlib import Path
from util import run
@ -70,6 +71,19 @@ def be_formatted(dev, fs):
run(f"mkfs.ext4 -m 0 {device}")
elif fs == "btrfs":
run(f"mkfs.btrfs {device}")
tmp_mnt = tempfile.mkdtemp(prefix="mnt-")
default_subvol = f"{tmp_mnt}/default"
run(
f"""
set -ex
mkdir -p {tmp_mnt}
mount {device} {tmp_mnt}
btrfs subvolume create {default_subvol}
btrfs subvolume set-default {default_subvol}
umount {tmp_mnt}
rmdir {tmp_mnt}
"""
)
else:
raise Exception(f"Unsupported fs type: {fs}")