From ae5e9b8f3424716e9057170a40334cd0887fd16f Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Mon, 28 Oct 2019 20:45:30 -0600 Subject: [PATCH] Added 4K alignment check --- scripts/wk/hw/obj.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/scripts/wk/hw/obj.py b/scripts/wk/hw/obj.py index ab30d258..3330f7f7 100644 --- a/scripts/wk/hw/obj.py +++ b/scripts/wk/hw/obj.py @@ -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.")