Added wipe support to layout definitions. Also changed default start positions of partitions to 1MiB in.
This commit is contained in:
parent
857b5c0c3e
commit
4691bad46b
|
|
@ -571,7 +571,17 @@ class Filesystem:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def load_layout(self, layout :dict):
|
def load_layout(self, layout :dict):
|
||||||
for partition in layout:
|
# If the layout tells us to wipe the drive, we do so
|
||||||
|
if layout.get('wipe', False):
|
||||||
|
if self.mode == GPT:
|
||||||
|
if not self.parted_mklabel(self.blockdevice.device, "gpt"):
|
||||||
|
raise KeyError(f"Could not create a GPT label on {self}")
|
||||||
|
elif self.mode == MBR:
|
||||||
|
if not self.parted_mklabel(self.blockdevice.device, "msdos"):
|
||||||
|
raise KeyError(f"Could not create a MSDOS label on {self}")
|
||||||
|
|
||||||
|
# We then iterate the partitions in order
|
||||||
|
for partition in layout.get('partitions', []):
|
||||||
# We don't want to re-add an existing partition (those containing a UUID already)
|
# We don't want to re-add an existing partition (those containing a UUID already)
|
||||||
if 'UUID' not in partition:
|
if 'UUID' not in partition:
|
||||||
self.add_partition(partition.get('type', 'primary'),
|
self.add_partition(partition.get('type', 'primary'),
|
||||||
|
|
@ -579,8 +589,6 @@ class Filesystem:
|
||||||
end=partition.get('size', '100%'),
|
end=partition.get('size', '100%'),
|
||||||
partition_format=partition.get('filesystem', {}).get('format', 'btrfs'))
|
partition_format=partition.get('filesystem', {}).get('format', 'btrfs'))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
def find_partition(self, mountpoint):
|
def find_partition(self, mountpoint):
|
||||||
|
|
@ -589,7 +597,9 @@ class Filesystem:
|
||||||
return partition
|
return partition
|
||||||
|
|
||||||
def raw_parted(self, string: str):
|
def raw_parted(self, string: str):
|
||||||
return SysCommand(f'/usr/bin/parted -s {string}')
|
if (cmd_handle := SysCommand(f'/usr/bin/parted -s {string}')).exit_code != 0:
|
||||||
|
log(f"Could not generate partition: {cmd_handle}", level=logging.ERROR, fg="red")
|
||||||
|
return cmd_handle
|
||||||
|
|
||||||
def parted(self, string: str):
|
def parted(self, string: str):
|
||||||
"""
|
"""
|
||||||
|
|
@ -601,35 +611,11 @@ class Filesystem:
|
||||||
return self.raw_parted(string).exit_code
|
return self.raw_parted(string).exit_code
|
||||||
|
|
||||||
def use_entire_disk(self, root_filesystem_type='ext4'):
|
def use_entire_disk(self, root_filesystem_type='ext4'):
|
||||||
log(f"Using and formatting the entire {self.blockdevice}.", level=logging.DEBUG)
|
# TODO: Implement this with declarative profiles instead.
|
||||||
if has_uefi():
|
raise ValueError("Installation().use_entire_disk() has to be re-worked.")
|
||||||
self.add_partition('primary', start='1MiB', end='513MiB', partition_format='fat32')
|
|
||||||
self.set_name(0, 'EFI')
|
|
||||||
self.set(0, 'boot on')
|
|
||||||
# TODO: Probably redundant because in GPT mode 'esp on' is an alias for "boot on"?
|
|
||||||
# https://www.gnu.org/software/parted/manual/html_node/set.html
|
|
||||||
self.set(0, 'esp on')
|
|
||||||
self.add_partition('primary', start='513MiB', end='100%')
|
|
||||||
|
|
||||||
self.blockdevice.partition[0].filesystem = 'vfat'
|
|
||||||
self.blockdevice.partition[1].filesystem = root_filesystem_type
|
|
||||||
log(f"Set the root partition {self.blockdevice.partition[1]} to use filesystem {root_filesystem_type}.", level=logging.DEBUG)
|
|
||||||
|
|
||||||
self.blockdevice.partition[0].target_mountpoint = '/boot'
|
|
||||||
self.blockdevice.partition[1].target_mountpoint = '/'
|
|
||||||
|
|
||||||
self.blockdevice.partition[0].allow_formatting = True
|
|
||||||
self.blockdevice.partition[1].allow_formatting = True
|
|
||||||
else:
|
|
||||||
# we don't need a seprate boot partition it would be a waste of space
|
|
||||||
self.add_partition('primary', start='1MB', end='100%')
|
|
||||||
self.blockdevice.partition[0].filesystem = root_filesystem_type
|
|
||||||
log(f"Set the root partition {self.blockdevice.partition[0]} to use filesystem {root_filesystem_type}.", level=logging.DEBUG)
|
|
||||||
self.blockdevice.partition[0].target_mountpoint = '/'
|
|
||||||
self.blockdevice.partition[0].allow_formatting = True
|
|
||||||
|
|
||||||
def add_partition(self, partition_type, start, end, partition_format=None):
|
def add_partition(self, partition_type, start, end, partition_format=None):
|
||||||
log(f'Adding partition to {self.blockdevice}', level=logging.INFO)
|
log(f'Adding partition to {self.blockdevice}, {start}->{end}', level=logging.INFO)
|
||||||
|
|
||||||
previous_partitions = self.blockdevice.partitions
|
previous_partitions = self.blockdevice.partitions
|
||||||
if self.mode == MBR:
|
if self.mode == MBR:
|
||||||
|
|
|
||||||
|
|
@ -322,6 +322,15 @@ class SysCommand:
|
||||||
for line in self.session:
|
for line in self.session:
|
||||||
yield line
|
yield line
|
||||||
|
|
||||||
|
def __getitem__(self, key):
|
||||||
|
if type(key) is slice:
|
||||||
|
start = key.start if key.start else 0
|
||||||
|
end = key.stop if key.stop else len(self.session._trace_log)
|
||||||
|
|
||||||
|
return self.session._trace_log[start:end]
|
||||||
|
else:
|
||||||
|
raise ValueError("SysCommand() doesn't have key & value pairs, only slices, SysCommand('ls')[:10] as an example.")
|
||||||
|
|
||||||
def __repr__(self, *args, **kwargs):
|
def __repr__(self, *args, **kwargs):
|
||||||
return self.session._trace_log.decode('UTF-8')
|
return self.session._trace_log.decode('UTF-8')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -191,8 +191,6 @@ def generic_multi_select(options, text="Select one or more of the options above
|
||||||
return selected_options
|
return selected_options
|
||||||
|
|
||||||
def select_encrypted_partitions(blockdevices :dict) -> dict:
|
def select_encrypted_partitions(blockdevices :dict) -> dict:
|
||||||
print(blockdevices[0])
|
|
||||||
|
|
||||||
if len(blockdevices) == 1:
|
if len(blockdevices) == 1:
|
||||||
if len(blockdevices[0]['partitions']) == 2:
|
if len(blockdevices[0]['partitions']) == 2:
|
||||||
root = find_partition_by_mountpoint(blockdevices[0]['partitions'], '/')
|
root = find_partition_by_mountpoint(blockdevices[0]['partitions'], '/')
|
||||||
|
|
@ -617,40 +615,53 @@ 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:
|
||||||
return {
|
MIN_SIZE_TO_ALLOW_HOME_PART = 40 # Gb
|
||||||
block_devices[0] : [
|
|
||||||
{ # Boot
|
layout = {
|
||||||
"type" : "primary",
|
block_devices[0] : {
|
||||||
"start" : "0MiB",
|
"wipe" : True,
|
||||||
"size" : "513MiB",
|
"partitions" : []
|
||||||
"boot" : True,
|
}
|
||||||
"mountpoint" : "/boot",
|
|
||||||
"filesystem" : {
|
|
||||||
"format" : "fat32"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ # Root
|
|
||||||
"type" : "primary",
|
|
||||||
"start" : "513MiB",
|
|
||||||
"encrypted" : True,
|
|
||||||
"size" : f"{max(block_devices[0].size*0.2, 20)*1024}MiB", # Warning: Won't work on small where max size is 16GB for instance.
|
|
||||||
"mountpoint" : "/",
|
|
||||||
"filesystem" : {
|
|
||||||
"format" : "btrfs"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ # Home
|
|
||||||
"type" : "primary",
|
|
||||||
"encrypted" : True,
|
|
||||||
"start" : f"{513 + (max(block_devices[0].size*0.2, 20)*1024)}MiB",
|
|
||||||
"size" : "100%",
|
|
||||||
"mountpoint" : "/home",
|
|
||||||
"filesystem" : {
|
|
||||||
"format" : "btrfs"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
layout[block_devices[0]]['partitions'].append({
|
||||||
|
# Boot
|
||||||
|
"type" : "primary",
|
||||||
|
"start" : "1MiB",
|
||||||
|
"size" : "513MiB",
|
||||||
|
"boot" : True,
|
||||||
|
"mountpoint" : "/boot",
|
||||||
|
"filesystem" : {
|
||||||
|
"format" : "fat32"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
layout[block_devices[0]]['partitions'].append({
|
||||||
|
# Root
|
||||||
|
"type" : "primary",
|
||||||
|
"start" : "513MiB",
|
||||||
|
"encrypted" : 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,
|
||||||
|
"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
|
||||||
|
|
||||||
def wipe_and_create_partitions(block_device :BlockDevice) -> dict:
|
def wipe_and_create_partitions(block_device :BlockDevice) -> dict:
|
||||||
|
|
@ -663,7 +674,7 @@ def wipe_and_create_partitions(block_device :BlockDevice) -> dict:
|
||||||
suggested_layout = [
|
suggested_layout = [
|
||||||
{ # Boot
|
{ # Boot
|
||||||
"type" : "primary",
|
"type" : "primary",
|
||||||
"start" : "0MiB",
|
"start" : "1MiB",
|
||||||
"size" : "513MiB",
|
"size" : "513MiB",
|
||||||
"boot" : True,
|
"boot" : True,
|
||||||
"mountpoint" : "/boot",
|
"mountpoint" : "/boot",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue