4K Alignment checks
This commit is contained in:
parent
214df52723
commit
7816602685
3 changed files with 59 additions and 3 deletions
|
|
@ -64,10 +64,13 @@ class GenericRepair(Exception):
|
|||
class MultipleInstallationsError(Exception):
|
||||
pass
|
||||
|
||||
class NotInstalledError(Exception):
|
||||
class NoProfilesError(Exception):
|
||||
pass
|
||||
|
||||
class NoProfilesError(Exception):
|
||||
class Not4KAlignedError(Exception):
|
||||
pass
|
||||
|
||||
class NotInstalledError(Exception):
|
||||
pass
|
||||
|
||||
class OSInstalledLegacyError(Exception):
|
||||
|
|
|
|||
|
|
@ -307,6 +307,11 @@ class DiskObj():
|
|||
attr_type=self.attr_type, **COLORS))
|
||||
report.extend(sorted(self.nvme_smart_notes.keys()))
|
||||
|
||||
# 4K alignment check
|
||||
if not self.is_4k_aligned():
|
||||
report.append('{YELLOW}Warning{CLEAR}'.format(**COLORS))
|
||||
report.append(' One or more partitions are not 4K aligned')
|
||||
|
||||
# Tests
|
||||
for test in self.tests.values():
|
||||
report.extend(test.report)
|
||||
|
|
@ -410,6 +415,26 @@ class DiskObj():
|
|||
'self_test', {}).get(
|
||||
k, {})
|
||||
|
||||
def is_4k_aligned(self):
|
||||
"""Check if partitions are 4K aligned, returns bool."""
|
||||
cmd = [
|
||||
'sudo',
|
||||
'sfdisk',
|
||||
'--json',
|
||||
self.path,
|
||||
]
|
||||
aligned = True
|
||||
|
||||
# Get partition details
|
||||
json_data = get_json_from_command(cmd)
|
||||
|
||||
# Check partitions
|
||||
for part in json_data.get('partitiontable', {}).get('partitions', []):
|
||||
aligned = aligned and part.get('start', -1) % 4096 == 0
|
||||
|
||||
# Done
|
||||
return aligned
|
||||
|
||||
def safety_check(self, silent=False):
|
||||
"""Run safety checks and disable tests if necessary."""
|
||||
test_running = False
|
||||
|
|
@ -454,7 +479,6 @@ class DiskObj():
|
|||
disk_ok = OVERRIDES_FORCED or ask('Run tests on this device anyway?')
|
||||
print_standard(' ')
|
||||
|
||||
|
||||
# Disable tests if necessary (statuses won't be overwritten)
|
||||
if test_running:
|
||||
if not silent:
|
||||
|
|
|
|||
|
|
@ -6,6 +6,35 @@ from functions.common import *
|
|||
from settings.sw_diags import *
|
||||
|
||||
|
||||
def check_4k_alignment(show_alert=False):
|
||||
"""Check that all partitions are 4K aligned."""
|
||||
aligned = True
|
||||
cmd = ['WMIC', 'partition', 'get', 'StartingOffset']
|
||||
offsets = []
|
||||
|
||||
# Get offsets
|
||||
result = run_program(cmd, encoding='utf-8', errors='ignore', check=False)
|
||||
offsets = result.stdout.splitlines()
|
||||
|
||||
# Check offsets
|
||||
for off in offsets:
|
||||
off = off.strip()
|
||||
if not off.isnumeric():
|
||||
# Skip
|
||||
continue
|
||||
|
||||
try:
|
||||
aligned = aligned and int(off) % 4096 == 0
|
||||
except ValueError:
|
||||
# Ignore, this check is low priority
|
||||
pass
|
||||
|
||||
# Show alert
|
||||
if show_alert:
|
||||
show_alert_box('One or more partitions are not 4K aligned')
|
||||
raise Not4KAlignedError
|
||||
|
||||
|
||||
def check_connection():
|
||||
"""Check if the system is online and optionally abort the script."""
|
||||
while True:
|
||||
|
|
|
|||
Loading…
Reference in a new issue