Added 4K alignment check

This commit is contained in:
2Shirt 2019-10-28 20:45:30 -06:00
parent c7090e77c2
commit ae5e9b8f34
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C

View file

@ -261,8 +261,12 @@ class Disk():
def is_4k_aligned(self):
"""Check that all disk partitions are aligned, returns bool."""
#TODO: Make real
return True
aligned = True
if not platform.system() == 'Linux':
aligned = is_4k_aligned_linux(self.path, self.details['phy-sec'])
#TODO: Add checks for other OS
return aligned
def update_smart_details(self):
"""Update SMART details via smartctl."""
@ -444,5 +448,27 @@ def get_ram_list_macos():
return dimm_list
def is_4k_aligned_linux(dev_path, physical_sector_size):
"""Check partition alignment using lsblk, returns bool."""
aligned = True
cmd = [
'sudo',
'sfdisk',
'--json',
dev_path,
]
# Get partition details
json_data = get_json_from_command(cmd)
# Check partitions
for part in json_data.get('partitiontable', {}).get('partitions', []):
offset = physical_sector_size * part.get('start', -1)
aligned = aligned and offset >= 0 and offset % 2096 == 0
# Done
return aligned
if __name__ == '__main__':
print("This file is not meant to be called directly.")