Skip to content

Commit 12b5e2e

Browse files
authored
Adding compression as an option (#1084)
* Adding compression as an option * Ignore 'misaligned' ending parenthathese * Moved the 'mark compressed' logic into the sub block within manual disk operations. * Fixed flake8 complaints * Muting a complextion warning on manage_new_and_existing_partitions(). It is too complex, but not something that we'll bother with for v2.4.0. As this whole function could be replaced with a new and improved menu system split into tasks rather than one huge if/else.
1 parent 1bce561 commit 12b5e2e

4 files changed

Lines changed: 50 additions & 11 deletions

File tree

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[flake8]
22
count = True
33
# Several of the following could be autofixed or improved by running the code through psf/black
4-
ignore = E126,E128,E203,E231,E261,E302,E402,E722,F541,W191,W292,W293
4+
ignore = E123,E126,E128,E203,E231,E261,E302,E402,E722,F541,W191,W292,W293
55
max-complexity = 40
66
max-line-length = 236
77
show-source = True

archinstall/lib/disk/user_guides.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,17 @@ def suggest_single_disk_layout(block_device :BlockDevice,
2323
MIN_SIZE_TO_ALLOW_HOME_PART = 40 # GiB
2424
using_subvolumes = False
2525
using_home_partition = False
26+
compression = False
2627

2728
if default_filesystem == 'btrfs':
2829
prompt = 'Would you like to use BTRFS subvolumes with a default structure?'
2930
choice = Menu(prompt, ['yes', 'no'], skip=False, default_option='yes').run()
3031
using_subvolumes = choice == 'yes'
3132

33+
prompt = 'Would you like to use BTRFS compression?'
34+
choice = Menu(prompt, ['yes', 'no'], skip=False, default_option='yes').run()
35+
compression = choice == 'yes'
36+
3237
layout = {
3338
block_device.path : {
3439
"wipe" : True,
@@ -73,7 +78,8 @@ def suggest_single_disk_layout(block_device :BlockDevice,
7378
"wipe" : True,
7479
"mountpoint" : "/" if not using_subvolumes else None,
7580
"filesystem" : {
76-
"format" : default_filesystem
81+
"format" : default_filesystem,
82+
"mount_options" : ["compress=zstd"] if compression else []
7783
}
7884
})
7985

@@ -124,7 +130,8 @@ def suggest_single_disk_layout(block_device :BlockDevice,
124130
"wipe" : True,
125131
"mountpoint" : "/home",
126132
"filesystem" : {
127-
"format" : default_filesystem
133+
"format" : default_filesystem,
134+
"mount_options" : ["compress=zstd"] if compression else []
128135
}
129136
})
130137

@@ -151,6 +158,17 @@ def suggest_multi_disk_layout(block_devices :List[BlockDevice],
151158
home_device = select_largest_device(block_devices, gigabytes=MIN_SIZE_TO_ALLOW_HOME_PART)
152159
root_device = select_disk_larger_than_or_close_to(block_devices, gigabytes=ARCH_LINUX_INSTALLED_SIZE, filter_out=[home_device])
153160

161+
compression = False
162+
163+
if default_filesystem == 'btrfs':
164+
# prompt = 'Would you like to use BTRFS subvolumes with a default structure?'
165+
# choice = Menu(prompt, ['yes', 'no'], skip=False, default_option='yes').run()
166+
# using_subvolumes = choice == 'yes'
167+
168+
prompt = 'Would you like to use BTRFS compression?'
169+
choice = Menu(prompt, ['yes', 'no'], skip=False, default_option='yes').run()
170+
compression = choice == 'yes'
171+
154172
log(f"Suggesting multi-disk-layout using {len(block_devices)} disks, where {root_device} will be /root and {home_device} will be /home", level=logging.DEBUG)
155173

156174
layout = {
@@ -193,7 +211,8 @@ def suggest_multi_disk_layout(block_devices :List[BlockDevice],
193211
"wipe" : True,
194212
"mountpoint" : "/",
195213
"filesystem" : {
196-
"format" : default_filesystem
214+
"format" : default_filesystem,
215+
"mount_options" : ["compress=zstd"] if compression else []
197216
}
198217
})
199218
if has_uefi():
@@ -208,7 +227,8 @@ def suggest_multi_disk_layout(block_devices :List[BlockDevice],
208227
"wipe" : True,
209228
"mountpoint" : "/home",
210229
"filesystem" : {
211-
"format" : default_filesystem
230+
"format" : default_filesystem,
231+
"mount_options" : ["compress=zstd"] if compression else []
212232
}
213233
})
214234

archinstall/lib/installer.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def mount_ordered_layout(self, layouts: Dict[str, Any]) -> None:
235235
list_part.extend(layouts[blockdevice]['partitions'])
236236

237237
# we manage the encrypted partititons
238-
for partition in [entry for entry in list_part if entry.get('encrypted',False)]:
238+
for partition in [entry for entry in list_part if entry.get('encrypted', False)]:
239239
# open the luks device and all associate stuff
240240
if not (password := partition.get('!password', None)):
241241
raise RequirementError(f"Missing partition {partition['device_instance'].path} encryption password in layout: {partition}")
@@ -252,7 +252,11 @@ def mount_ordered_layout(self, layouts: Dict[str, Any]) -> None:
252252

253253
# we manage the btrfs partitions
254254
for partition in [entry for entry in list_part if entry.get('btrfs', {}).get('subvolumes', {})]:
255-
self.mount(partition['device_instance'],"/")
255+
if partition.get('filesystem',{}).get('mount_options',[]):
256+
mount_options = ','.join(partition['filesystem']['mount_options'])
257+
self.mount(partition['device_instance'], "/", options=mount_options)
258+
else:
259+
self.mount(partition['device_instance'], "/")
256260
try:
257261
new_mountpoints = manage_btrfs_subvolumes(self,partition)
258262
except Exception as e:
@@ -270,7 +274,7 @@ def mount_ordered_layout(self, layouts: Dict[str, Any]) -> None:
270274

271275
if partition.get('filesystem',{}).get('mount_options',[]):
272276
mount_options = ','.join(partition['filesystem']['mount_options'])
273-
partition['device_instance'].mount(f"{self.target}{mountpoint}",options=mount_options)
277+
partition['device_instance'].mount(f"{self.target}{mountpoint}", options=mount_options)
274278
else:
275279
partition['device_instance'].mount(f"{self.target}{mountpoint}")
276280

@@ -287,11 +291,11 @@ def mount_ordered_layout(self, layouts: Dict[str, Any]) -> None:
287291
log(f"creating key-file for {ppath}",level=logging.INFO)
288292
self._create_keyfile(handle[0],handle[1],handle[2])
289293

290-
def mount(self, partition :Partition, mountpoint :str, create_mountpoint :bool = True) -> None:
294+
def mount(self, partition :Partition, mountpoint :str, create_mountpoint :bool = True, options='') -> None:
291295
if create_mountpoint and not os.path.isdir(f'{self.target}{mountpoint}'):
292296
os.makedirs(f'{self.target}{mountpoint}')
293297

294-
partition.mount(f'{self.target}{mountpoint}')
298+
partition.mount(f'{self.target}{mountpoint}', options=options)
295299

296300
def post_install_check(self, *args :str, **kwargs :str) -> List[str]:
297301
return [step for step, flag in self.helper_flags.items() if flag is False]

archinstall/lib/user_interaction/partitioning_conf.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def select_individual_blockdevice_usage(block_devices: list) -> Dict[str, Any]:
113113
return result
114114

115115

116-
def manage_new_and_existing_partitions(block_device: 'BlockDevice') -> Dict[str, Any]:
116+
def manage_new_and_existing_partitions(block_device: 'BlockDevice') -> Dict[str, Any]: # noqa: max-complexity: 50
117117
block_device_struct = {"partitions": [partition.__dump__() for partition in block_device.partitions.values()]}
118118
# Test code: [part.__dump__() for part in block_device.partitions.values()]
119119
# TODO: Squeeze in BTRFS subvolumes here
@@ -125,6 +125,7 @@ def manage_new_and_existing_partitions(block_device: 'BlockDevice') -> Dict[str,
125125
assign_mount_point = str(_('Assign mount-point for a partition'))
126126
mark_formatted = str(_('Mark/Unmark a partition to be formatted (wipes data)'))
127127
mark_encrypted = str(_('Mark/Unmark a partition as encrypted'))
128+
mark_compressed = str(_('Mark/Unmark a partition as compressed (btrfs only)'))
128129
mark_bootable = str(_('Mark/Unmark a partition as bootable (automatic for /boot)'))
129130
set_filesystem_partition = str(_('Set desired filesystem for a partition'))
130131
set_btrfs_subvolumes = str(_('Set desired subvolumes on a btrfs partition'))
@@ -140,6 +141,7 @@ def manage_new_and_existing_partitions(block_device: 'BlockDevice') -> Dict[str,
140141
mark_formatted,
141142
mark_encrypted,
142143
mark_bootable,
144+
mark_compressed,
143145
set_filesystem_partition,
144146
set_btrfs_subvolumes,
145147
]
@@ -213,6 +215,7 @@ def manage_new_and_existing_partitions(block_device: 'BlockDevice') -> Dict[str,
213215
continue
214216

215217
block_device_struct.update(suggest_single_disk_layout(block_device)[block_device.path])
218+
216219
elif task is None:
217220
return block_device_struct
218221
else:
@@ -226,6 +229,18 @@ def manage_new_and_existing_partitions(block_device: 'BlockDevice') -> Dict[str,
226229
block_device_struct['partitions'] = [
227230
p for idx, p in enumerate(block_device_struct['partitions']) if idx not in to_delete
228231
]
232+
elif task == mark_compressed:
233+
title = _('{}\n\nSelect which partition to mark as bootable').format(current_layout)
234+
partition = select_partition(title, block_device_struct["partitions"])
235+
236+
if partition is not None:
237+
if "filesystem" not in block_device_struct["partitions"][partition]:
238+
block_device_struct["partitions"][partition]["filesystem"] = {}
239+
if "mount_options" not in block_device_struct["partitions"][partition]["filesystem"]:
240+
block_device_struct["partitions"][partition]["filesystem"]["mount_options"] = []
241+
242+
if "compress=zstd" not in block_device_struct["partitions"][partition]["filesystem"]["mount_options"]:
243+
block_device_struct["partitions"][partition]["filesystem"]["mount_options"].append("compress=zstd")
229244
elif task == delete_all_partitions:
230245
block_device_struct["partitions"] = []
231246
elif task == assign_mount_point:

0 commit comments

Comments
 (0)