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):
|
class MultipleInstallationsError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class NotInstalledError(Exception):
|
class NoProfilesError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class NoProfilesError(Exception):
|
class Not4KAlignedError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class NotInstalledError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class OSInstalledLegacyError(Exception):
|
class OSInstalledLegacyError(Exception):
|
||||||
|
|
|
||||||
|
|
@ -307,6 +307,11 @@ class DiskObj():
|
||||||
attr_type=self.attr_type, **COLORS))
|
attr_type=self.attr_type, **COLORS))
|
||||||
report.extend(sorted(self.nvme_smart_notes.keys()))
|
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
|
# Tests
|
||||||
for test in self.tests.values():
|
for test in self.tests.values():
|
||||||
report.extend(test.report)
|
report.extend(test.report)
|
||||||
|
|
@ -410,6 +415,26 @@ class DiskObj():
|
||||||
'self_test', {}).get(
|
'self_test', {}).get(
|
||||||
k, {})
|
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):
|
def safety_check(self, silent=False):
|
||||||
"""Run safety checks and disable tests if necessary."""
|
"""Run safety checks and disable tests if necessary."""
|
||||||
test_running = False
|
test_running = False
|
||||||
|
|
@ -454,7 +479,6 @@ class DiskObj():
|
||||||
disk_ok = OVERRIDES_FORCED or ask('Run tests on this device anyway?')
|
disk_ok = OVERRIDES_FORCED or ask('Run tests on this device anyway?')
|
||||||
print_standard(' ')
|
print_standard(' ')
|
||||||
|
|
||||||
|
|
||||||
# Disable tests if necessary (statuses won't be overwritten)
|
# Disable tests if necessary (statuses won't be overwritten)
|
||||||
if test_running:
|
if test_running:
|
||||||
if not silent:
|
if not silent:
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,35 @@ from functions.common import *
|
||||||
from settings.sw_diags 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():
|
def check_connection():
|
||||||
"""Check if the system is online and optionally abort the script."""
|
"""Check if the system is online and optionally abort the script."""
|
||||||
while True:
|
while True:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue