Skip to content
Snippets Groups Projects
Commit 380ce9dd authored by Peter Senna Tschudin's avatar Peter Senna Tschudin
Browse files

Use PARTLABEL instead of LABEL


Using a label on the partition instead of on the file system has the
advantage of decoupling the label information from the file system which
will persist even to formatting the file system for example. Using
PARTLABEL is in general a more robust approach.

This patch also replaces `e2label` by `lsblk` as the former does not
require root permissions and also produces json output making it more
reliable to parse.

Signed-off-by: default avatarPeter Senna Tschudin <peter.senna@collabora.com>
parent bb6d374c
No related branches found
No related tags found
1 merge request!2V3
......@@ -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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment