diff --git a/tools/psdk b/tools/psdk index 9bb791af8072cd06146f54110b7403ba414879ca..a8d6525c093a5a9ce116c32c78cb994d92f7cc45 100755 --- a/tools/psdk +++ b/tools/psdk @@ -24,6 +24,7 @@ import re import tempfile from string import Template import errno +import json BKP_EXTENSION = ".PSDK" DISK_LABEL = "sdk-persistent" @@ -111,7 +112,7 @@ class Disk: """Format the partition using ext4""" print("Will format the persistent storage partition...") - command = ["sudo", "mkfs.ext4", "-F", "-L", DISK_LABEL, self.partpath] + command = ["sudo", "mkfs.ext4", "-F", self.partpath] result = _run(command) print(result.stdout.decode()) @@ -121,7 +122,7 @@ class Disk: command = ["sudo", "mkdir", "-p", MOUNT_POINT] _run(command) - command = ["sudo", "mount", "-L", DISK_LABEL, MOUNT_POINT] + command = ["sudo", "mount", "PARTLABEL=" + DISK_LABEL, MOUNT_POINT] _run(command) def _part(self): @@ -136,6 +137,13 @@ class Disk: # Give the kernel a moment to update the partition table time.sleep(3) + # Changes the label of partition 1 to DISK_LABEL + command = ["sudo", "sfdisk", "--part-label", self.diskpath, "1", DISK_LABEL] + _run(command) + + # Give the kernel another moment to update the partition table + time.sleep(3) + def _umount(self): """Unmount the fs""" @@ -189,13 +197,13 @@ class Disk: if not os.path.exists(self.partpath): return False - command = ["sudo", "/sbin/e2label", self.partpath] + command = ["lsblk", "--json", "-o", "fstype,partlabel", self.partpath] result = _run(command) - part_uuid = result.stdout.decode().split("'")[1] - - if part_uuid == DISK_LABEL: - return True + jpart_label = json.loads(result.stdout.decode()) + if jpart_label["blockdevices"][0]["partlabel"] == DISK_LABEL: + if jpart_label["blockdevices"][0]["fstype"] == "ext4": + return True return False @@ -220,7 +228,7 @@ def update_fstab(): new_fstab = "" old_home_uuid = "" - new_home_line = "LABEL=" + DISK_LABEL + "\t/home\text4\tdefaults\t0\t0" + new_home_line = "PARTLABEL=" + DISK_LABEL + "\t/home\text4\tdefaults\t0\t0" with open("/etc/fstab", "rt") as fstab: for line in fstab: