Rewrite format-sdcard.py to use f2fs
This commit is contained in:
parent
acdbd14d8e
commit
c10c3a2c21
|
@ -60,14 +60,21 @@ in {
|
||||||
};
|
};
|
||||||
|
|
||||||
config = lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
boot = {
|
boot.supportedFilesystems =
|
||||||
supportedFilesystems =
|
lib.mkForce [ "f2fs" "ntfs" "cifs" "ext4" "vfat" "nfs" "nfs4" ];
|
||||||
lib.mkForce [ "f2fs" "ntfs" "cifs" "ext4" "vfat" "nfs" "nfs4" ];
|
boot.kernelParams = [ "rootflags=atgc" "rw" ];
|
||||||
};
|
|
||||||
fileSystems."/" = {
|
fileSystems."/" = {
|
||||||
device = "/dev/disk/by-label/NixosSd";
|
device = "/dev/disk/by-label/NixosSd";
|
||||||
fsType = "ext4";
|
fsType = "f2fs";
|
||||||
options = [ "noatime" ];
|
options = [
|
||||||
|
"atgc,gc_merge"
|
||||||
|
"compress_algorithm=lz4"
|
||||||
|
"compress_extension=*"
|
||||||
|
"compress_chksum"
|
||||||
|
"discard"
|
||||||
|
"lazytime"
|
||||||
|
];
|
||||||
};
|
};
|
||||||
fileSystems."/boot" = {
|
fileSystems."/boot" = {
|
||||||
device = "/dev/disk/by-label/SdBoot";
|
device = "/dev/disk/by-label/SdBoot";
|
||||||
|
@ -85,7 +92,7 @@ in {
|
||||||
"reset-raspberrypi" # required for vl805 firmware to load
|
"reset-raspberrypi" # required for vl805 firmware to load
|
||||||
];
|
];
|
||||||
|
|
||||||
initrd.luks.devices."cryptlvmsd" = {
|
initrd.luks.devices."cryptsd" = {
|
||||||
device = "/dev/mmcblk1p2";
|
device = "/dev/mmcblk1p2";
|
||||||
allowDiscards = true; # required for TRIM
|
allowDiscards = true; # required for TRIM
|
||||||
};
|
};
|
||||||
|
@ -109,7 +116,5 @@ in {
|
||||||
sudo umount /mnt/firmware
|
sudo umount /mnt/firmware
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
# Enable TRIM for SD cards
|
|
||||||
services.fstrim.enable = true;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,12 @@ def _run_command(command, user_input=""):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def _partition_suffix(disk):
|
||||||
|
if ("nvmne" or "mmc") in disk:
|
||||||
|
return "p"
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
def read_disks():
|
def read_disks():
|
||||||
output = _run_command(["lsblk", "-dpno", "name"])
|
output = _run_command(["lsblk", "-dpno", "name"])
|
||||||
disks = []
|
disks = []
|
||||||
|
@ -39,12 +45,20 @@ def get_disk_to_format():
|
||||||
def create_main_partition(disk):
|
def create_main_partition(disk):
|
||||||
print("Create main partition.")
|
print("Create main partition.")
|
||||||
_run_command(["parted", "--script", disk, "mkpart", "primary", "1GiB", "100%"])
|
_run_command(["parted", "--script", disk, "mkpart", "primary", "1GiB", "100%"])
|
||||||
return f"{disk}p2"
|
return f"{disk}{_partition_suffix(disk)}2"
|
||||||
|
|
||||||
|
|
||||||
def _create_main_filesystem():
|
def _create_main_filesystem():
|
||||||
_run_command(["lvcreate", "-l", "100%FREE", "MainGroupSd", "-n", "sdroot"])
|
_run_command(
|
||||||
_run_command(["mkfs.ext4", "-L", "NixosSd", "/dev/MainGroupSd/sdroot"])
|
[
|
||||||
|
"mkfs.f2fs",
|
||||||
|
"-l",
|
||||||
|
"NixosSd",
|
||||||
|
"-O",
|
||||||
|
"extra_attr,inode_checksum,sb_checksum,compression",
|
||||||
|
"/dev/mapper/cryptsd",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _encrypt_disk(partition_path):
|
def _encrypt_disk(partition_path):
|
||||||
|
@ -54,28 +68,18 @@ def _encrypt_disk(partition_path):
|
||||||
["cryptsetup", "luksFormat", "-q", partition_path],
|
["cryptsetup", "luksFormat", "-q", partition_path],
|
||||||
user_input=password,
|
user_input=password,
|
||||||
)
|
)
|
||||||
_run_command(
|
_run_command(["cryptsetup", "open", partition_path, "cryptsd"], user_input=password)
|
||||||
["cryptsetup", "open", partition_path, "cryptlvmsd"], user_input=password
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def _setup_lvm(lvm_target):
|
|
||||||
print("Set up LVM on {}.".format(lvm_target))
|
|
||||||
_run_command(["pvcreate", lvm_target])
|
|
||||||
_run_command(["vgcreate", "MainGroupSd", lvm_target])
|
|
||||||
|
|
||||||
|
|
||||||
def create_file_systems(partition):
|
def create_file_systems(partition):
|
||||||
print("Creating filesystems.")
|
print("Creating filesystems.")
|
||||||
lvm_target = "/dev/mapper/cryptlvmsd"
|
|
||||||
_encrypt_disk(partition)
|
_encrypt_disk(partition)
|
||||||
_setup_lvm(lvm_target)
|
|
||||||
_create_main_filesystem()
|
_create_main_filesystem()
|
||||||
|
|
||||||
|
|
||||||
def mount_partitions():
|
def mount_partitions():
|
||||||
print("Mounting partitions.")
|
print("Mounting partitions.")
|
||||||
_run_command(["mount", "/dev/MainGroupSd/sdroot", "/mnt"])
|
_run_command(["mount", "/dev/disk/by-label/NixosSd", "/mnt"])
|
||||||
os.mkdir("/mnt/boot")
|
os.mkdir("/mnt/boot")
|
||||||
_run_command(["mount", "/dev/disk/by-label/SdBoot", "/mnt/boot"])
|
_run_command(["mount", "/dev/disk/by-label/SdBoot", "/mnt/boot"])
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue