Working suggested single disk layout, preparing for multiple selections.
This commit is contained in:
parent
24476ac1f6
commit
858171986c
|
|
@ -27,6 +27,60 @@ def valid_fs_type(fstype :str) -> bool:
|
||||||
"btrfs",
|
"btrfs",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def suggest_single_disk_layout(blockdevice):
|
||||||
|
MIN_SIZE_TO_ALLOW_HOME_PART = 40 # Gb
|
||||||
|
|
||||||
|
layout = {
|
||||||
|
blockdevice : {
|
||||||
|
"wipe" : True,
|
||||||
|
"partitions" : []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
layout[blockdevice]['partitions'].append({
|
||||||
|
# Boot
|
||||||
|
"type" : "primary",
|
||||||
|
"start" : "1MiB",
|
||||||
|
"size" : "513MiB",
|
||||||
|
"boot" : True,
|
||||||
|
"format" : True,
|
||||||
|
"mountpoint" : "/boot",
|
||||||
|
"filesystem" : {
|
||||||
|
"format" : "fat32"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
layout[blockdevice]['partitions'].append({
|
||||||
|
# Root
|
||||||
|
"type" : "primary",
|
||||||
|
"start" : "513MiB",
|
||||||
|
"encrypted" : True,
|
||||||
|
"format" : True,
|
||||||
|
"size" : "100%" if blockdevice.size < MIN_SIZE_TO_ALLOW_HOME_PART else f"{min(blockdevice.size, 20)*1024}MiB",
|
||||||
|
"mountpoint" : "/",
|
||||||
|
"filesystem" : {
|
||||||
|
"format" : "btrfs"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if blockdevice.size > MIN_SIZE_TO_ALLOW_HOME_PART:
|
||||||
|
layout[blockdevice]['partitions'].append({
|
||||||
|
# Home
|
||||||
|
"type" : "primary",
|
||||||
|
"encrypted" : True,
|
||||||
|
"format" : True,
|
||||||
|
"start" : f"{min(blockdevice.size*0.2, 20)*1024}MiB",
|
||||||
|
"size" : "100%",
|
||||||
|
"mountpoint" : "/home",
|
||||||
|
"filesystem" : {
|
||||||
|
"format" : "btrfs"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return layout
|
||||||
|
|
||||||
|
def suggest_multi_disk_layout(blockdevices):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class BlockDevice:
|
class BlockDevice:
|
||||||
def __init__(self, path, info=None):
|
def __init__(self, path, info=None):
|
||||||
|
|
@ -323,6 +377,7 @@ class Partition:
|
||||||
This is more reliable than relying on /dev/disk/by-partuuid as
|
This is more reliable than relying on /dev/disk/by-partuuid as
|
||||||
it doesn't seam to be able to detect md raid partitions.
|
it doesn't seam to be able to detect md raid partitions.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
lsblk = json.loads(SysCommand(f'lsblk -J -o+PARTUUID {self.path}').decode('UTF-8'))
|
lsblk = json.loads(SysCommand(f'lsblk -J -o+PARTUUID {self.path}').decode('UTF-8'))
|
||||||
for partition in lsblk['blockdevices']:
|
for partition in lsblk['blockdevices']:
|
||||||
return partition.get('partuuid', None)
|
return partition.get('partuuid', None)
|
||||||
|
|
|
||||||
|
|
@ -601,55 +601,9 @@ def partition_overlap(partitions :list, start :str, end :str) -> bool:
|
||||||
|
|
||||||
def get_default_partition_layout(block_devices):
|
def get_default_partition_layout(block_devices):
|
||||||
if len(block_devices) == 1:
|
if len(block_devices) == 1:
|
||||||
MIN_SIZE_TO_ALLOW_HOME_PART = 40 # Gb
|
return suggest_single_disk_layout(blockdevices[0])
|
||||||
|
else:
|
||||||
layout = {
|
return suggest_multi_disk_layout(blockdevices)
|
||||||
block_devices[0] : {
|
|
||||||
"wipe" : True,
|
|
||||||
"partitions" : []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
layout[block_devices[0]]['partitions'].append({
|
|
||||||
# Boot
|
|
||||||
"type" : "primary",
|
|
||||||
"start" : "1MiB",
|
|
||||||
"size" : "513MiB",
|
|
||||||
"boot" : True,
|
|
||||||
"format" : True,
|
|
||||||
"mountpoint" : "/boot",
|
|
||||||
"filesystem" : {
|
|
||||||
"format" : "fat32"
|
|
||||||
}
|
|
||||||
})
|
|
||||||
layout[block_devices[0]]['partitions'].append({
|
|
||||||
# Root
|
|
||||||
"type" : "primary",
|
|
||||||
"start" : "513MiB",
|
|
||||||
"encrypted" : True,
|
|
||||||
"format" : True,
|
|
||||||
"size" : "100%" if block_devices[0].size < MIN_SIZE_TO_ALLOW_HOME_PART else f"{min(block_devices[0].size, 20)*1024}MiB",
|
|
||||||
"mountpoint" : "/",
|
|
||||||
"filesystem" : {
|
|
||||||
"format" : "btrfs"
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if block_devices[0].size > MIN_SIZE_TO_ALLOW_HOME_PART:
|
|
||||||
layout[block_devices[0]]['partitions'].append({
|
|
||||||
# Home
|
|
||||||
"type" : "primary",
|
|
||||||
"encrypted" : True,
|
|
||||||
"format" : True,
|
|
||||||
"start" : f"{min(block_devices[0].size*0.2, 20)*1024}MiB",
|
|
||||||
"size" : "100%",
|
|
||||||
"mountpoint" : "/home",
|
|
||||||
"filesystem" : {
|
|
||||||
"format" : "btrfs"
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return layout
|
|
||||||
|
|
||||||
# TODO: Implement sane generic layout for 2+ drives
|
# TODO: Implement sane generic layout for 2+ drives
|
||||||
|
|
||||||
|
|
@ -660,38 +614,6 @@ def wipe_and_create_partitions(block_device :BlockDevice) -> dict:
|
||||||
partition_type = 'msdos'
|
partition_type = 'msdos'
|
||||||
|
|
||||||
partitions_result = [] # Test code: [part.__dump__() for part in block_device.partitions.values()]
|
partitions_result = [] # Test code: [part.__dump__() for part in block_device.partitions.values()]
|
||||||
suggested_layout = [
|
|
||||||
{ # Boot
|
|
||||||
"type" : "primary",
|
|
||||||
"start" : "1MiB",
|
|
||||||
"size" : "513MiB",
|
|
||||||
"boot" : True,
|
|
||||||
"mountpoint" : "/boot",
|
|
||||||
"filesystem" : {
|
|
||||||
"format" : "fat32"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ # Root
|
|
||||||
"type" : "primary",
|
|
||||||
"start" : "513MiB",
|
|
||||||
"encrypted" : True,
|
|
||||||
"size" : f"{max(block_device.size*0.2, 20)}GiB",
|
|
||||||
"mountpoint" : "",
|
|
||||||
"filesystem" : {
|
|
||||||
"format" : "btrfs"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ # Home
|
|
||||||
"type" : "primary",
|
|
||||||
"encrypted" : True,
|
|
||||||
"start" : f"{max(block_device.size*0.2, 20)}GiB",
|
|
||||||
"size" : "100%",
|
|
||||||
"mountpoint" : "/home",
|
|
||||||
"filesystem" : {
|
|
||||||
"format" : "btrfs"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
# TODO: Squeeze in BTRFS subvolumes here
|
# TODO: Squeeze in BTRFS subvolumes here
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
@ -745,7 +667,7 @@ def wipe_and_create_partitions(block_device :BlockDevice) -> dict:
|
||||||
if input(f"{block_device} contains queued partitions, this will remove those, are you sure? y/N: ").strip().lower() in ('', 'n'):
|
if input(f"{block_device} contains queued partitions, this will remove those, are you sure? y/N: ").strip().lower() in ('', 'n'):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
partitions_result = [*suggested_layout]
|
partitions_result = suggest_single_disk_layout(block_device)[block_device]
|
||||||
elif task is None:
|
elif task is None:
|
||||||
return {
|
return {
|
||||||
block_device : partitions_result
|
block_device : partitions_result
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue