Issue923 (#927)
* Correct definition of btrfs standard layout * Solving issue 923. Standarize keyword "wipe" to signal the need of formatting a FS * flake8 complains
This commit is contained in:
parent
64bde666ac
commit
e3adab13e8
|
|
@ -169,6 +169,12 @@ def post_process_arguments(arguments):
|
||||||
if not json_stream_to_structure('--disk_layouts',arguments['disk_layouts'],layout_storage):
|
if not json_stream_to_structure('--disk_layouts',arguments['disk_layouts'],layout_storage):
|
||||||
exit(1)
|
exit(1)
|
||||||
else:
|
else:
|
||||||
|
# backward compatibility. Change partition.format for partition.wipe
|
||||||
|
for disk in layout_storage:
|
||||||
|
for i,partition in enumerate(layout_storage[disk].get('partitions',[])):
|
||||||
|
if 'format' in partition:
|
||||||
|
partition['wipe'] = partition['format']
|
||||||
|
del partition['format']
|
||||||
arguments['disk_layouts'] = layout_storage
|
arguments['disk_layouts'] = layout_storage
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ from typing import Optional, Dict, Any, TYPE_CHECKING
|
||||||
# https://stackoverflow.com/a/39757388/929999
|
# https://stackoverflow.com/a/39757388/929999
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .blockdevice import BlockDevice
|
from .blockdevice import BlockDevice
|
||||||
|
|
||||||
from .partition import Partition
|
from .partition import Partition
|
||||||
from .validators import valid_fs_type
|
from .validators import valid_fs_type
|
||||||
from ..exceptions import DiskError
|
from ..exceptions import DiskError
|
||||||
|
|
@ -76,7 +76,7 @@ class Filesystem:
|
||||||
# We then iterate the partitions in order
|
# We then iterate the partitions in order
|
||||||
for partition in layout.get('partitions', []):
|
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 partition.get('format', False) and not partition.get('PARTUUID', None):
|
if partition.get('wipe', False) and not partition.get('PARTUUID', None):
|
||||||
print("Adding partition....")
|
print("Adding partition....")
|
||||||
partition['device_instance'] = self.add_partition(partition.get('type', 'primary'),
|
partition['device_instance'] = self.add_partition(partition.get('type', 'primary'),
|
||||||
start=partition.get('start', '1MiB'), # TODO: Revisit sane block starts (4MB for memorycards for instance)
|
start=partition.get('start', '1MiB'), # TODO: Revisit sane block starts (4MB for memorycards for instance)
|
||||||
|
|
@ -113,11 +113,11 @@ class Filesystem:
|
||||||
loopdev = f"{storage.get('ENC_IDENTIFIER', 'ai')}{pathlib.Path(partition['mountpoint']).name}loop"
|
loopdev = f"{storage.get('ENC_IDENTIFIER', 'ai')}{pathlib.Path(partition['mountpoint']).name}loop"
|
||||||
else:
|
else:
|
||||||
loopdev = f"{storage.get('ENC_IDENTIFIER', 'ai')}{pathlib.Path(partition['device_instance'].path).name}"
|
loopdev = f"{storage.get('ENC_IDENTIFIER', 'ai')}{pathlib.Path(partition['device_instance'].path).name}"
|
||||||
|
|
||||||
partition['device_instance'].encrypt(password=partition['!password'])
|
partition['device_instance'].encrypt(password=partition['!password'])
|
||||||
# Immediately unlock the encrypted device to format the inner volume
|
# Immediately unlock the encrypted device to format the inner volume
|
||||||
with luks2(partition['device_instance'], loopdev, partition['!password'], auto_unmount=True) as unlocked_device:
|
with luks2(partition['device_instance'], loopdev, partition['!password'], auto_unmount=True) as unlocked_device:
|
||||||
if not partition.get('format'):
|
if not partition.get('wipe'):
|
||||||
if storage['arguments'] == 'silent':
|
if storage['arguments'] == 'silent':
|
||||||
raise ValueError(f"Missing fs-type to format on newly created encrypted partition {partition['device_instance']}")
|
raise ValueError(f"Missing fs-type to format on newly created encrypted partition {partition['device_instance']}")
|
||||||
else:
|
else:
|
||||||
|
|
@ -133,7 +133,7 @@ class Filesystem:
|
||||||
break
|
break
|
||||||
|
|
||||||
unlocked_device.format(partition['filesystem']['format'], options=format_options)
|
unlocked_device.format(partition['filesystem']['format'], options=format_options)
|
||||||
elif partition.get('format', False):
|
elif partition.get('wipe', False):
|
||||||
if not partition['device_instance']:
|
if not partition['device_instance']:
|
||||||
raise DiskError(f"Internal error caused us to loose the partition. Please report this issue upstream!")
|
raise DiskError(f"Internal error caused us to loose the partition. Please report this issue upstream!")
|
||||||
|
|
||||||
|
|
@ -150,7 +150,7 @@ class Filesystem:
|
||||||
|
|
||||||
def partprobe(self) -> bool:
|
def partprobe(self) -> bool:
|
||||||
result = SysCommand(f'partprobe {self.blockdevice.device}')
|
result = SysCommand(f'partprobe {self.blockdevice.device}')
|
||||||
|
|
||||||
if result.exit_code != 0:
|
if result.exit_code != 0:
|
||||||
log(f"Could not execute partprobe: {result!r}", level=logging.ERROR, fg="red")
|
log(f"Could not execute partprobe: {result!r}", level=logging.ERROR, fg="red")
|
||||||
raise DiskError(f"Could not run partprobe: {result!r}")
|
raise DiskError(f"Could not run partprobe: {result!r}")
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ def suggest_single_disk_layout(block_device :BlockDevice,
|
||||||
"size" : "203MiB",
|
"size" : "203MiB",
|
||||||
"boot" : True,
|
"boot" : True,
|
||||||
"encrypted" : False,
|
"encrypted" : False,
|
||||||
"format" : True,
|
"wipe" : True,
|
||||||
"mountpoint" : "/boot",
|
"mountpoint" : "/boot",
|
||||||
"filesystem" : {
|
"filesystem" : {
|
||||||
"format" : "fat32"
|
"format" : "fat32"
|
||||||
|
|
@ -65,7 +65,7 @@ def suggest_single_disk_layout(block_device :BlockDevice,
|
||||||
"type" : "primary",
|
"type" : "primary",
|
||||||
"start" : "206MiB",
|
"start" : "206MiB",
|
||||||
"encrypted" : False,
|
"encrypted" : False,
|
||||||
"format" : True,
|
"wipe" : True,
|
||||||
"mountpoint" : "/" if not using_subvolumes else None,
|
"mountpoint" : "/" if not using_subvolumes else None,
|
||||||
"filesystem" : {
|
"filesystem" : {
|
||||||
"format" : default_filesystem
|
"format" : default_filesystem
|
||||||
|
|
@ -114,7 +114,7 @@ def suggest_single_disk_layout(block_device :BlockDevice,
|
||||||
"start" : f"{min(block_device.size, 20)}GiB",
|
"start" : f"{min(block_device.size, 20)}GiB",
|
||||||
"size" : "100%",
|
"size" : "100%",
|
||||||
"encrypted" : False,
|
"encrypted" : False,
|
||||||
"format" : True,
|
"wipe" : True,
|
||||||
"mountpoint" : "/home",
|
"mountpoint" : "/home",
|
||||||
"filesystem" : {
|
"filesystem" : {
|
||||||
"format" : default_filesystem
|
"format" : default_filesystem
|
||||||
|
|
@ -166,7 +166,7 @@ def suggest_multi_disk_layout(block_devices :List[BlockDevice],
|
||||||
"size" : "203MiB",
|
"size" : "203MiB",
|
||||||
"boot" : True,
|
"boot" : True,
|
||||||
"encrypted" : False,
|
"encrypted" : False,
|
||||||
"format" : True,
|
"wipe" : True,
|
||||||
"mountpoint" : "/boot",
|
"mountpoint" : "/boot",
|
||||||
"filesystem" : {
|
"filesystem" : {
|
||||||
"format" : "fat32"
|
"format" : "fat32"
|
||||||
|
|
@ -183,7 +183,7 @@ def suggest_multi_disk_layout(block_devices :List[BlockDevice],
|
||||||
"start" : "206MiB",
|
"start" : "206MiB",
|
||||||
"size" : "100%",
|
"size" : "100%",
|
||||||
"encrypted" : False,
|
"encrypted" : False,
|
||||||
"format" : True,
|
"wipe" : True,
|
||||||
"mountpoint" : "/",
|
"mountpoint" : "/",
|
||||||
"filesystem" : {
|
"filesystem" : {
|
||||||
"format" : default_filesystem
|
"format" : default_filesystem
|
||||||
|
|
@ -198,7 +198,7 @@ def suggest_multi_disk_layout(block_devices :List[BlockDevice],
|
||||||
"start" : "1MiB",
|
"start" : "1MiB",
|
||||||
"size" : "100%",
|
"size" : "100%",
|
||||||
"encrypted" : False,
|
"encrypted" : False,
|
||||||
"format" : True,
|
"wipe" : True,
|
||||||
"mountpoint" : "/home",
|
"mountpoint" : "/home",
|
||||||
"filesystem" : {
|
"filesystem" : {
|
||||||
"format" : default_filesystem
|
"format" : default_filesystem
|
||||||
|
|
|
||||||
|
|
@ -661,7 +661,7 @@ def manage_new_and_existing_partitions(block_device :BlockDevice) -> Dict[str, A
|
||||||
block_device_struct["partitions"][partition]['mountpoint'] = mountpoint
|
block_device_struct["partitions"][partition]['mountpoint'] = mountpoint
|
||||||
if mountpoint == '/boot':
|
if mountpoint == '/boot':
|
||||||
log(f"Marked partition as bootable because mountpoint was set to /boot.", fg="yellow")
|
log(f"Marked partition as bootable because mountpoint was set to /boot.", fg="yellow")
|
||||||
block_device_struct["partitions"][block_device_struct["partitions"].index(partition)]['boot'] = True
|
block_device_struct["partitions"][partition]['boot'] = True
|
||||||
else:
|
else:
|
||||||
del(block_device_struct["partitions"][partition]['mountpoint'])
|
del(block_device_struct["partitions"][partition]['mountpoint'])
|
||||||
|
|
||||||
|
|
@ -682,7 +682,7 @@ def manage_new_and_existing_partitions(block_device :BlockDevice) -> Dict[str, A
|
||||||
block_device_struct["partitions"][partition]['filesystem']['format'] = fstype
|
block_device_struct["partitions"][partition]['filesystem']['format'] = fstype
|
||||||
|
|
||||||
# Negate the current wipe marking
|
# Negate the current wipe marking
|
||||||
block_device_struct["partitions"][partition]['format'] = not block_device_struct["partitions"][partition].get('format', False)
|
block_device_struct["partitions"][partition]['wipe'] = not block_device_struct["partitions"][partition].get('wipe', False)
|
||||||
|
|
||||||
elif task == "Mark/Unmark a partition as encrypted":
|
elif task == "Mark/Unmark a partition as encrypted":
|
||||||
title = f'{current_layout}\n\nSelect which partition to mark as encrypted'
|
title = f'{current_layout}\n\nSelect which partition to mark as encrypted'
|
||||||
|
|
|
||||||
|
|
@ -194,7 +194,7 @@ Options for ``--disk_layouts``
|
||||||
"filesystem": {
|
"filesystem": {
|
||||||
"format": "fat32"
|
"format": "fat32"
|
||||||
},
|
},
|
||||||
"format": true,
|
"wipe": true,
|
||||||
"mountpoint": "/boot",
|
"mountpoint": "/boot",
|
||||||
"size": "513MB",
|
"size": "513MB",
|
||||||
"start": "5MB",
|
"start": "5MB",
|
||||||
|
|
@ -213,7 +213,7 @@ Options for ``--disk_layouts``
|
||||||
"filesystem": {
|
"filesystem": {
|
||||||
"format": "btrfs"
|
"format": "btrfs"
|
||||||
},
|
},
|
||||||
"format": true,
|
"wipe": true,
|
||||||
"mountpoint": "/",
|
"mountpoint": "/",
|
||||||
"size": "100%",
|
"size": "100%",
|
||||||
"start": "518MB",
|
"start": "518MB",
|
||||||
|
|
@ -245,4 +245,4 @@ Options for ``--disk_layouts``
|
||||||
| type | primary | Only used if MBR and BIOS is used. Marks what kind of partition it is. | No |
|
| type | primary | Only used if MBR and BIOS is used. Marks what kind of partition it is. | No |
|
||||||
+----------------------+-----------------------------------------------------+--------------------------------------------------------------------------------------+-----------------------------------------------+
|
+----------------------+-----------------------------------------------------+--------------------------------------------------------------------------------------+-----------------------------------------------+
|
||||||
| btrfs | { "subvolumes": {"subvolume": "mountpoint"}} | Support for btrfs subvolumes for a given partition | No |
|
| btrfs | { "subvolumes": {"subvolume": "mountpoint"}} | Support for btrfs subvolumes for a given partition | No |
|
||||||
+----------------------+-----------------------------------------------------+--------------------------------------------------------------------------------------+-----------------------------------------------+
|
+----------------------+-----------------------------------------------------+--------------------------------------------------------------------------------------+-----------------------------------------------+
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
"filesystem": {
|
"filesystem": {
|
||||||
"format": "fat32"
|
"format": "fat32"
|
||||||
},
|
},
|
||||||
"format": true,
|
"wipe": true,
|
||||||
"mountpoint": "/boot",
|
"mountpoint": "/boot",
|
||||||
"size": "513MB",
|
"size": "513MB",
|
||||||
"start": "5MB",
|
"start": "5MB",
|
||||||
|
|
@ -26,7 +26,7 @@
|
||||||
"filesystem": {
|
"filesystem": {
|
||||||
"format": "btrfs"
|
"format": "btrfs"
|
||||||
},
|
},
|
||||||
"format": true,
|
"wipe": true,
|
||||||
"mountpoint": "/",
|
"mountpoint": "/",
|
||||||
"size": "100%",
|
"size": "100%",
|
||||||
"start": "518MB",
|
"start": "518MB",
|
||||||
|
|
@ -35,4 +35,4 @@
|
||||||
],
|
],
|
||||||
"wipe": true
|
"wipe": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,8 +42,8 @@ def ask_harddrives():
|
||||||
if input("Do you wish to continue ? [Y/n]").strip().lower() == 'n':
|
if input("Do you wish to continue ? [Y/n]").strip().lower() == 'n':
|
||||||
exit(1)
|
exit(1)
|
||||||
else:
|
else:
|
||||||
if archinstall.storage.get('disk_layouts', None) is None:
|
if archinstall.arguments.get('disk_layouts', None) is None:
|
||||||
archinstall.storage['disk_layouts'] = archinstall.select_disk_layout(archinstall.arguments['harddrives'], archinstall.arguments.get('advanced', False))
|
archinstall.arguments['disk_layouts'] = archinstall.select_disk_layout(archinstall.arguments['harddrives'], archinstall.arguments.get('advanced', False))
|
||||||
|
|
||||||
# Get disk encryption password (or skip if blank)
|
# Get disk encryption password (or skip if blank)
|
||||||
if archinstall.arguments.get('!encryption-password', None) is None:
|
if archinstall.arguments.get('!encryption-password', None) is None:
|
||||||
|
|
@ -53,8 +53,8 @@ def ask_harddrives():
|
||||||
if archinstall.arguments.get('!encryption-password', None):
|
if archinstall.arguments.get('!encryption-password', None):
|
||||||
# If no partitions was marked as encrypted, but a password was supplied and we have some disks to format..
|
# If no partitions was marked as encrypted, but a password was supplied and we have some disks to format..
|
||||||
# Then we need to identify which partitions to encrypt. This will default to / (root).
|
# Then we need to identify which partitions to encrypt. This will default to / (root).
|
||||||
if len(list(archinstall.encrypted_partitions(archinstall.storage['disk_layouts']))) == 0:
|
if len(list(archinstall.encrypted_partitions(archinstall.arguments['disk_layouts']))) == 0:
|
||||||
archinstall.storage['disk_layouts'] = archinstall.select_encrypted_partitions(archinstall.storage['disk_layouts'], archinstall.arguments['!encryption-password'])
|
archinstall.arguments['disk_layouts'] = archinstall.select_encrypted_partitions(archinstall.arguments['disk_layouts'], archinstall.arguments['!encryption-password'])
|
||||||
|
|
||||||
# Ask which boot-loader to use (will only ask if we're in BIOS (non-efi) mode)
|
# Ask which boot-loader to use (will only ask if we're in BIOS (non-efi) mode)
|
||||||
if not archinstall.arguments.get("bootloader", None):
|
if not archinstall.arguments.get("bootloader", None):
|
||||||
|
|
@ -121,8 +121,8 @@ def save_user_configurations():
|
||||||
with open("/var/log/archinstall/user_configuration.json", "w") as config_file:
|
with open("/var/log/archinstall/user_configuration.json", "w") as config_file:
|
||||||
config_file.write(user_configuration)
|
config_file.write(user_configuration)
|
||||||
|
|
||||||
if archinstall.storage.get('disk_layouts'):
|
if archinstall.arguments.get('disk_layouts'):
|
||||||
user_disk_layout = json.dumps(archinstall.storage['disk_layouts'], indent=4, sort_keys=True, cls=archinstall.JSON)
|
user_disk_layout = json.dumps(archinstall.arguments['disk_layouts'], indent=4, sort_keys=True, cls=archinstall.JSON)
|
||||||
with open("/var/log/archinstall/user_disk_layout.json", "w") as disk_layout_file:
|
with open("/var/log/archinstall/user_disk_layout.json", "w") as disk_layout_file:
|
||||||
disk_layout_file.write(user_disk_layout)
|
disk_layout_file.write(user_disk_layout)
|
||||||
|
|
||||||
|
|
@ -135,14 +135,14 @@ def write_config_files():
|
||||||
user_configuration = json.dumps({**archinstall.arguments, 'version' : archinstall.__version__} , indent=4, sort_keys=True, cls=archinstall.JSON)
|
user_configuration = json.dumps({**archinstall.arguments, 'version' : archinstall.__version__} , indent=4, sort_keys=True, cls=archinstall.JSON)
|
||||||
archinstall.log(user_configuration, level=logging.INFO)
|
archinstall.log(user_configuration, level=logging.INFO)
|
||||||
|
|
||||||
if archinstall.storage.get('disk_layouts'):
|
if archinstall.arguments.get('disk_layouts'):
|
||||||
user_disk_layout = json.dumps(archinstall.storage['disk_layouts'], indent=4, sort_keys=True, cls=archinstall.JSON)
|
user_disk_layout = json.dumps(archinstall.arguments['disk_layouts'], indent=4, sort_keys=True, cls=archinstall.JSON)
|
||||||
archinstall.log(user_disk_layout, level=logging.INFO)
|
archinstall.log(user_disk_layout, level=logging.INFO)
|
||||||
|
|
||||||
print()
|
print()
|
||||||
|
|
||||||
save_user_configurations()
|
save_user_configurations()
|
||||||
if archinstall.arguments.get('dry-run'):
|
if archinstall.arguments.get('dry_run'):
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -164,7 +164,7 @@ def perform_disk_operations():
|
||||||
mode = archinstall.MBR
|
mode = archinstall.MBR
|
||||||
|
|
||||||
for drive in archinstall.arguments.get('harddrives', []):
|
for drive in archinstall.arguments.get('harddrives', []):
|
||||||
if dl_disk := archinstall.storage.get('disk_layouts', {}).get(drive.path):
|
if dl_disk := archinstall.arguments.get('disk_layouts', {}).get(drive.path):
|
||||||
with archinstall.Filesystem(drive, mode) as fs:
|
with archinstall.Filesystem(drive, mode) as fs:
|
||||||
fs.load_layout(dl_disk)
|
fs.load_layout(dl_disk)
|
||||||
|
|
||||||
|
|
@ -177,8 +177,8 @@ def perform_installation(mountpoint):
|
||||||
with archinstall.Installer(mountpoint, kernels=None) as installation:
|
with archinstall.Installer(mountpoint, kernels=None) as installation:
|
||||||
# Mount all the drives to the desired mountpoint
|
# Mount all the drives to the desired mountpoint
|
||||||
# This *can* be done outside of the installation, but the installer can deal with it.
|
# This *can* be done outside of the installation, but the installer can deal with it.
|
||||||
if archinstall.storage.get('disk_layouts'):
|
if archinstall.arguments.get('disk_layouts'):
|
||||||
installation.mount_ordered_layout(archinstall.storage['disk_layouts'])
|
installation.mount_ordered_layout(archinstall.arguments['disk_layouts'])
|
||||||
|
|
||||||
# Placing /boot check during installation because this will catch both re-use and wipe scenarios.
|
# Placing /boot check during installation because this will catch both re-use and wipe scenarios.
|
||||||
for partition in installation.partitions:
|
for partition in installation.partitions:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue